Skip to content

Commit

Permalink
(goctl): fix prefix syntax (#4113)
Browse files Browse the repository at this point in the history
  • Loading branch information
kesonan authored Apr 30, 2024
1 parent 04116f6 commit a9d27cd
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
28 changes: 28 additions & 0 deletions tools/goctl/pkg/parser/api/parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -1247,6 +1247,34 @@ func (p *Parser) parseAtServerKVExpression() *ast.KVExpr {
}
}

valueTok.Type = token.PATH
node := ast.NewTokenNode(valueTok)
node.SetLeadingCommentGroup(leadingCommentGroup)
expr.Value = node
return expr
} else if p.peekTokenIs(token.SUB) {
for {
if p.peekTokenIs(token.SUB) {
if !p.nextToken() {
return nil
}

subTok := p.curTok
if !p.advanceIfPeekTokenIs(token.IDENT) {
return nil
}

idTok := p.curTok
valueTok = token.Token{
Text: valueTok.Text + subTok.Text + idTok.Text,
Position: valueTok.Position,
}
leadingCommentGroup = p.curTokenNode().LeadingCommentGroup
} else {
break
}
}

valueTok.Type = token.PATH
node := ast.NewTokenNode(valueTok)
node.SetLeadingCommentGroup(leadingCommentGroup)
Expand Down
1 change: 1 addition & 0 deletions tools/goctl/pkg/parser/api/parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,7 @@ func TestParser_Parse_atServerStmt(t *testing.T) {
"prefix1:": "/v1/v2_test/v2-beta",
"prefix2:": "v1/v2_test/v2-beta",
"prefix3:": "v1/v2_",
"prefix4:": "a-b-c",
"summary:": `"test"`,
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@
prefix1: /v1/v2_test/v2-beta
prefix2: v1/v2_test/v2-beta
prefix3: v1/v2_
prefix4: a-b-c
summary:"test"
)
12 changes: 7 additions & 5 deletions tools/goctl/pkg/parser/api/parser/testdata/example.api
Original file line number Diff line number Diff line change
Expand Up @@ -180,12 +180,14 @@ service example {
post /example/array/base (DemoOfArrayReq) returns ([]string)
}

@server (
group: /prefix
prefix: foo-bar
summary: "test"
)
service example {
@handler nestDemo1
post /example/nest (NestDemoReq1) returns (NestDemoResp1)

@handler nestDemo2
post /example/nest2 (NestDemoReq2) returns (NestDemoResp2)
@handler prefixDemo
post /example/prefix (PostFormReq) returns (PostFormResp)
}

@server (
Expand Down

0 comments on commit a9d27cd

Please sign in to comment.