fix: Fix issue #1810 (#1811)

* Fix #1810

* Remove go embed

* Format code

* Remove useless code

Co-authored-by: anqiansong <anqiansong@bytedance.com>
master
anqiansong 3 years ago committed by GitHub
parent 2cdff97934
commit 305587aa81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -32,6 +32,10 @@ func DartCommand(c *cli.Context) error {
return err return err
} }
if err := api.Validate(); err != nil {
return err
}
api.Service = api.Service.JoinPrefix() api.Service = api.Service.JoinPrefix()
if !strings.HasSuffix(dir, "/") { if !strings.HasSuffix(dir, "/") {
dir = dir + "/" dir = dir + "/"

@ -61,6 +61,10 @@ func DoGenProject(apiFile, dir, style string) error {
return err return err
} }
if err := api.Validate(); err != nil {
return err
}
cfg, err := config.NewConfig(style) cfg, err := config.NewConfig(style)
if err != nil { if err != nil {
return err return err

@ -28,6 +28,10 @@ func JavaCommand(c *cli.Context) error {
return err return err
} }
if err := api.Validate(); err != nil {
return err
}
api.Service = api.Service.JoinPrefix() api.Service = api.Service.JoinPrefix()
packetName := strings.TrimSuffix(api.Service.Name, "-api") packetName := strings.TrimSuffix(api.Service.Name, "-api")
logx.Must(pathx.MkdirIfNotExist(dir)) logx.Must(pathx.MkdirIfNotExist(dir))

@ -27,6 +27,10 @@ func KtCommand(c *cli.Context) error {
return e return e
} }
if err := api.Validate(); err != nil {
return err
}
api.Service = api.Service.JoinPrefix() api.Service = api.Service.JoinPrefix()
e = genBase(dir, pkg, api) e = genBase(dir, pkg, api)
if e != nil { if e != nil {

@ -26,3 +26,10 @@ func TestParseContent(t *testing.T) {
} }
} }
} }
func TestMissingService(t *testing.T) {
sp, err := ParseContent("")
assert.Nil(t, err)
err = sp.Validate()
assert.Equal(t, spec.ErrMissingService, err)
}

@ -0,0 +1,16 @@
package spec
import "errors"
var ErrMissingService = errors.New("missing service")
// Validate validates Validate the integrity of the spec.
func (s *ApiSpec) Validate() error {
if len(s.Service.Name) == 0 {
return ErrMissingService
}
if len(s.Service.Groups) == 0 {
return ErrMissingService
}
return nil
}

@ -32,6 +32,10 @@ func TsCommand(c *cli.Context) error {
return err return err
} }
if err := api.Validate(); err != nil {
return err
}
api.Service = api.Service.JoinPrefix() api.Service = api.Service.JoinPrefix()
logx.Must(pathx.MkdirIfNotExist(dir)) logx.Must(pathx.MkdirIfNotExist(dir))
logx.Must(genHandler(dir, webAPI, caller, api, unwrapAPI)) logx.Must(genHandler(dir, webAPI, caller, api, unwrapAPI))

@ -17,7 +17,12 @@ func GoValidateApi(c *cli.Context) error {
return errors.New("missing -api") return errors.New("missing -api")
} }
_, err := parser.Parse(apiFile) spec, err := parser.Parse(apiFile)
if err != nil {
return err
}
err = spec.Validate()
if err == nil { if err == nil {
fmt.Println(aurora.Green("api format ok")) fmt.Println(aurora.Green("api format ok"))
} }

Loading…
Cancel
Save