Mark deprecated syntax (#1148)
This commit is contained in:
@@ -212,24 +212,40 @@ func (v *ApiVisitor) VisitRoute(ctx *api.RouteContext) interface{} {
|
|||||||
// VisitBody implements from api.BaseApiParserVisitor
|
// VisitBody implements from api.BaseApiParserVisitor
|
||||||
func (v *ApiVisitor) VisitBody(ctx *api.BodyContext) interface{} {
|
func (v *ApiVisitor) VisitBody(ctx *api.BodyContext) interface{} {
|
||||||
if ctx.ID() == nil {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
idRxpr := v.newExprWithTerminalNode(ctx.ID())
|
idExpr := v.newExprWithTerminalNode(ctx.ID())
|
||||||
if api.IsGolangKeyWord(idRxpr.Text()) {
|
if api.IsGolangKeyWord(idExpr.Text()) {
|
||||||
v.panic(idRxpr, fmt.Sprintf("expecting 'ID', but found golang keyword '%s'", idRxpr.Text()))
|
v.panic(idExpr, fmt.Sprintf("expecting 'ID', but found golang keyword '%s'", idExpr.Text()))
|
||||||
}
|
}
|
||||||
|
|
||||||
return &Body{
|
return &Body{
|
||||||
Lp: v.newExprWithToken(ctx.GetLp()),
|
Lp: v.newExprWithToken(ctx.GetLp()),
|
||||||
Rp: v.newExprWithToken(ctx.GetRp()),
|
Rp: v.newExprWithToken(ctx.GetRp()),
|
||||||
Name: &Literal{Literal: idRxpr},
|
Name: &Literal{Literal: idExpr},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// VisitReplybody implements from api.BaseApiParserVisitor
|
// VisitReplybody implements from api.BaseApiParserVisitor
|
||||||
func (v *ApiVisitor) VisitReplybody(ctx *api.ReplybodyContext) interface{} {
|
func (v *ApiVisitor) VisitReplybody(ctx *api.ReplybodyContext) interface{} {
|
||||||
if ctx.DataType() == nil {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ type parser struct {
|
|||||||
|
|
||||||
// Parse parses the api file
|
// Parse parses the api file
|
||||||
func Parse(filename string) (*spec.ApiSpec, error) {
|
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)
|
ast, err := astParser.Parse(filename)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in New Issue
Block a user