* Fix #1810 * Remove go embed * Format code * Remove useless code Co-authored-by: anqiansong <anqiansong@bytedance.com>
@@ -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 {
cfg, err := config.NewConfig(style)
if err != nil {
@@ -28,6 +28,10 @@ func JavaCommand(c *cli.Context) error {
packetName := strings.TrimSuffix(api.Service.Name, "-api")
logx.Must(pathx.MkdirIfNotExist(dir))
@@ -27,6 +27,10 @@ func KtCommand(c *cli.Context) error {
return e
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)
+}
@@ -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 nil
@@ -32,6 +32,10 @@ func TsCommand(c *cli.Context) error {
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 {
+ err = spec.Validate()
if err == nil {
fmt.Println(aurora.Green("api format ok"))