* Fix #1810 * Remove go embed * Format code * Remove useless code Co-authored-by: anqiansong <anqiansong@bytedance.com>
This commit is contained in:
@@ -32,6 +32,10 @@ func DartCommand(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := api.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
api.Service = api.Service.JoinPrefix()
|
||||
if !strings.HasSuffix(dir, "/") {
|
||||
dir = dir + "/"
|
||||
|
||||
@@ -61,6 +61,10 @@ func DoGenProject(apiFile, dir, style string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := api.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cfg, err := config.NewConfig(style)
|
||||
if err != nil {
|
||||
return err
|
||||
|
||||
@@ -28,6 +28,10 @@ func JavaCommand(c *cli.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := api.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
api.Service = api.Service.JoinPrefix()
|
||||
packetName := strings.TrimSuffix(api.Service.Name, "-api")
|
||||
logx.Must(pathx.MkdirIfNotExist(dir))
|
||||
|
||||
@@ -27,6 +27,10 @@ func KtCommand(c *cli.Context) error {
|
||||
return e
|
||||
}
|
||||
|
||||
if err := api.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
api.Service = api.Service.JoinPrefix()
|
||||
e = genBase(dir, pkg, api)
|
||||
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)
|
||||
}
|
||||
|
||||
16
tools/goctl/api/spec/validate.go
Normal file
16
tools/goctl/api/spec/validate.go
Normal file
@@ -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
|
||||
}
|
||||
|
||||
if err := api.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
api.Service = api.Service.JoinPrefix()
|
||||
logx.Must(pathx.MkdirIfNotExist(dir))
|
||||
logx.Must(genHandler(dir, webAPI, caller, api, unwrapAPI))
|
||||
|
||||
@@ -17,7 +17,12 @@ func GoValidateApi(c *cli.Context) error {
|
||||
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 {
|
||||
fmt.Println(aurora.Green("api format ok"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user