validate.go 530 B

123456789101112131415161718192021222324252627282930
  1. package validate
  2. import (
  3. "errors"
  4. "fmt"
  5. "github.com/logrusorgru/aurora"
  6. "github.com/urfave/cli"
  7. "github.com/zeromicro/go-zero/tools/goctl/api/parser"
  8. )
  9. // GoValidateApi verifies whether the api has a syntax error
  10. func GoValidateApi(c *cli.Context) error {
  11. apiFile := c.String("api")
  12. if len(apiFile) == 0 {
  13. return errors.New("missing -api")
  14. }
  15. spec, err := parser.Parse(apiFile)
  16. if err != nil {
  17. return err
  18. }
  19. err = spec.Validate()
  20. if err == nil {
  21. fmt.Println(aurora.Green("api format ok"))
  22. }
  23. return err
  24. }