rename-Api

master
stevenzack 4 years ago committed by Kevin Wan
parent 693a8b627a
commit d4e38cb7f0

@ -67,11 +67,11 @@ suspend fun apiRequest(
eventually?.invoke() eventually?.invoke()
} }
` `
apiTemplate = `package {{with .Info}}{{.Title}}{{end}} apiTemplate = `package {{with .Info}}{{.Desc}}{{end}}
import com.google.gson.Gson import com.google.gson.Gson
object Api{ object {{with .Info}}{{.Title}}{{end}}{
{{range .Types}} {{range .Types}}
data class {{.Name}}({{$length := (len .Members)}}{{range $i,$item := .Members}} data class {{.Name}}({{$length := (len .Members)}}{{range $i,$item := .Members}}
val {{with $item}}{{lowCamelCase .Name}}: {{parseType .Type}}{{end}}{{if ne $i (add $length -1)}},{{end}}{{end}} val {{with $item}}{{lowCamelCase .Name}}: {{parseType .Type}}{{end}}{{if ne $i (add $length -1)}},{{end}}{{end}}
@ -120,8 +120,10 @@ func genBase(dir, pkg string, api *spec.ApiSpec) error {
} }
func genApi(dir, pkg string, api *spec.ApiSpec) error { func genApi(dir, pkg string, api *spec.ApiSpec) error {
path := filepath.Join(dir, strcase.ToCamel(api.Info.Title+"Api")+".kt") name := strcase.ToCamel(api.Info.Title + "Api")
api.Info.Title = pkg path := filepath.Join(dir, name+".kt")
api.Info.Title = name
api.Info.Desc = pkg
e := os.MkdirAll(dir, 0755) e := os.MkdirAll(dir, 0755)
if e != nil { if e != nil {
@ -135,7 +137,7 @@ func genApi(dir, pkg string, api *spec.ApiSpec) error {
defer file.Close() defer file.Close()
t, e := template.New("api").Funcs(funcsMap).Parse(apiTemplate) t, e := template.New("api").Funcs(funcsMap).Parse(apiTemplate)
if e!=nil { if e != nil {
return e return e
} }
return t.Execute(file, api) return t.Execute(file, api)

Loading…
Cancel
Save