Skip to content

Commit d323b48

Browse files
authored
Feat: Add support for parenthesis in router patterns (#1859)
1 parent 7159b0f commit d323b48

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

operation.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,7 @@ func parseMimeTypeList(mimeTypeList string, typeList *[]string, format string) e
707707
return nil
708708
}
709709

710-
var routerPattern = regexp.MustCompile(`^(/[\w./\-{}+:$]*)[[:blank:]]+\[(\w+)]`)
710+
var routerPattern = regexp.MustCompile(`^(/[\w./\-{}\(\)+:$]*)[[:blank:]]+\[(\w+)]`)
711711

712712
// ParseRouterComment parses comment for given `router` comment string.
713713
func (operation *Operation) ParseRouterComment(commentLine string, deprecated bool) error {

operation_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,18 @@ func TestParseRouterCommentWithDollarSign(t *testing.T) {
175175
assert.Equal(t, "POST", operation.RouterProperties[0].HTTPMethod)
176176
}
177177

178+
func TestParseRouterCommentWithParens(t *testing.T) {
179+
t.Parallel()
180+
181+
comment := `/@Router /customer({id}) [get]`
182+
operation := NewOperation(nil)
183+
err := operation.ParseComment(comment, nil)
184+
assert.NoError(t, err)
185+
assert.Len(t, operation.RouterProperties, 1)
186+
assert.Equal(t, "/customer({id})", operation.RouterProperties[0].Path)
187+
assert.Equal(t, "GET", operation.RouterProperties[0].HTTPMethod)
188+
}
189+
178190
func TestParseRouterCommentNoDollarSignAtPathStartErr(t *testing.T) {
179191
t.Parallel()
180192

0 commit comments

Comments
 (0)