Code optimized (#523)
* optimized markdown generator * optimized markdown generator * optimized markdown generator * add more comment * add comment * add comment * add comments for rpc tool * add comments for model tool * add comments for model tool * add comments for model tool * add comments for config tool * add comments for config tool * add comments * add comments * add comments * add comments * add comment * remove rpc main head info * add comment * optimized Co-authored-by: anqiansong <anqiansong@xiaoheiban.cn>
This commit is contained in:
@@ -11,12 +11,13 @@ import (
|
||||
"github.com/urfave/cli"
|
||||
)
|
||||
|
||||
// TsCommand provides the entry to generting typescript codes
|
||||
func TsCommand(c *cli.Context) error {
|
||||
apiFile := c.String("api")
|
||||
dir := c.String("dir")
|
||||
webApi := c.String("webapi")
|
||||
webAPI := c.String("webapi")
|
||||
caller := c.String("caller")
|
||||
unwrapApi := c.Bool("unwrap")
|
||||
unwrapAPI := c.Bool("unwrap")
|
||||
if len(apiFile) == 0 {
|
||||
return errors.New("missing -api")
|
||||
}
|
||||
@@ -32,7 +33,7 @@ func TsCommand(c *cli.Context) error {
|
||||
}
|
||||
|
||||
logx.Must(util.MkdirIfNotExist(dir))
|
||||
logx.Must(genHandler(dir, webApi, caller, api, unwrapApi))
|
||||
logx.Must(genHandler(dir, webAPI, caller, api, unwrapAPI))
|
||||
logx.Must(genComponents(dir, api))
|
||||
|
||||
fmt.Println(aurora.Green("Done."))
|
||||
|
||||
@@ -18,7 +18,7 @@ const (
|
||||
`
|
||||
)
|
||||
|
||||
func genHandler(dir, webApi, caller string, api *spec.ApiSpec, unwrapApi bool) error {
|
||||
func genHandler(dir, webAPI, caller string, api *spec.ApiSpec, unwrapAPI bool) error {
|
||||
filename := strings.Replace(api.Service.Name, "-api", "", 1) + ".ts"
|
||||
if err := util.RemoveIfExist(path.Join(dir, filename)); err != nil {
|
||||
return err
|
||||
@@ -37,11 +37,11 @@ func genHandler(dir, webApi, caller string, api *spec.ApiSpec, unwrapApi bool) e
|
||||
caller = "webapi"
|
||||
}
|
||||
importCaller := caller
|
||||
if unwrapApi {
|
||||
if unwrapAPI {
|
||||
importCaller = "{ " + importCaller + " }"
|
||||
}
|
||||
if len(webApi) > 0 {
|
||||
imports += `import ` + importCaller + ` from ` + "\"" + webApi + "\""
|
||||
if len(webAPI) > 0 {
|
||||
imports += `import ` + importCaller + ` from ` + "\"" + webAPI + "\""
|
||||
}
|
||||
|
||||
if len(api.Types) != 0 {
|
||||
@@ -53,7 +53,7 @@ func genHandler(dir, webApi, caller string, api *spec.ApiSpec, unwrapApi bool) e
|
||||
imports += fmt.Sprintf(`%sexport * from "%s"`, util.NL, "./"+outputFile)
|
||||
}
|
||||
|
||||
apis, err := genApi(api, caller)
|
||||
apis, err := genAPI(api, caller)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -65,7 +65,7 @@ func genHandler(dir, webApi, caller string, api *spec.ApiSpec, unwrapApi bool) e
|
||||
})
|
||||
}
|
||||
|
||||
func genApi(api *spec.ApiSpec, caller string) (string, error) {
|
||||
func genAPI(api *spec.ApiSpec, caller string) (string, error) {
|
||||
var builder strings.Builder
|
||||
for _, group := range api.Service.Groups {
|
||||
for _, route := range group.Routes {
|
||||
@@ -157,7 +157,7 @@ func callParamsForRoute(route spec.Route, group spec.Group) string {
|
||||
}
|
||||
|
||||
func pathForRoute(route spec.Route, group spec.Group) string {
|
||||
prefix := group.GetAnnotation("pathPrefix")
|
||||
prefix := group.GetAnnotation(pathPrefix)
|
||||
if len(prefix) == 0 {
|
||||
return "\"" + route.Path + "\""
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ func writeProperty(writer io.Writer, member spec.Member, indent int) error {
|
||||
}
|
||||
|
||||
optionalTag := ""
|
||||
if member.IsOptional() || member.IsOmitempty() {
|
||||
if member.IsOptional() || member.IsOmitEmpty() {
|
||||
optionalTag = "?"
|
||||
}
|
||||
name, err := member.GetPropertyName()
|
||||
|
||||
Reference in New Issue
Block a user