diff --git a/tools/goctl/api/parser/g4/ast/service.go b/tools/goctl/api/parser/g4/ast/service.go index ab4ba7b8..db5c5369 100644 --- a/tools/goctl/api/parser/g4/ast/service.go +++ b/tools/goctl/api/parser/g4/ast/service.go @@ -212,24 +212,40 @@ func (v *ApiVisitor) VisitRoute(ctx *api.RouteContext) interface{} { // VisitBody implements from api.BaseApiParserVisitor func (v *ApiVisitor) VisitBody(ctx *api.BodyContext) interface{} { if ctx.ID() == nil { + if v.debug { + msg := fmt.Sprintf( + `%s line %d: expr "()" is deprecated, if there has no request body, please omit it`, + v.prefix, + ctx.GetStart().GetLine(), + ) + v.log.Warning(msg) + } return nil } - idRxpr := v.newExprWithTerminalNode(ctx.ID()) - if api.IsGolangKeyWord(idRxpr.Text()) { - v.panic(idRxpr, fmt.Sprintf("expecting 'ID', but found golang keyword '%s'", idRxpr.Text())) + idExpr := v.newExprWithTerminalNode(ctx.ID()) + if api.IsGolangKeyWord(idExpr.Text()) { + v.panic(idExpr, fmt.Sprintf("expecting 'ID', but found golang keyword '%s'", idExpr.Text())) } return &Body{ Lp: v.newExprWithToken(ctx.GetLp()), Rp: v.newExprWithToken(ctx.GetRp()), - Name: &Literal{Literal: idRxpr}, + Name: &Literal{Literal: idExpr}, } } // VisitReplybody implements from api.BaseApiParserVisitor func (v *ApiVisitor) VisitReplybody(ctx *api.ReplybodyContext) interface{} { if ctx.DataType() == nil { + if v.debug { + msg := fmt.Sprintf( + `%s line %d: expr "returns ()" or "()" is deprecated, if there has no response body, please omit it`, + v.prefix, + ctx.GetStart().GetLine(), + ) + v.log.Warning(msg) + } return nil } diff --git a/tools/goctl/api/parser/parser.go b/tools/goctl/api/parser/parser.go index f2d70e04..3d40b3e5 100644 --- a/tools/goctl/api/parser/parser.go +++ b/tools/goctl/api/parser/parser.go @@ -17,7 +17,7 @@ type parser struct { // Parse parses the api file func Parse(filename string) (*spec.ApiSpec, error) { - astParser := ast.NewParser(ast.WithParserPrefix(filepath.Base(filename))) + astParser := ast.NewParser(ast.WithParserPrefix(filepath.Base(filename)), ast.WithParserDebug()) ast, err := astParser.Parse(filename) if err != nil { return nil, err