Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add support for parenthesis in router patterns #1859

Merged
merged 3 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -707,7 +707,7 @@ func parseMimeTypeList(mimeTypeList string, typeList *[]string, format string) e
return nil
}

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

// ParseRouterComment parses comment for given `router` comment string.
func (operation *Operation) ParseRouterComment(commentLine string, deprecated bool) error {
Expand Down
12 changes: 12 additions & 0 deletions operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,18 @@ func TestParseRouterCommentWithDollarSign(t *testing.T) {
assert.Equal(t, "POST", operation.RouterProperties[0].HTTPMethod)
}

func TestParseRouterCommentWithParens(t *testing.T) {
t.Parallel()

comment := `/@Router /customer({id}) [get]`
operation := NewOperation(nil)
err := operation.ParseComment(comment, nil)
assert.NoError(t, err)
assert.Len(t, operation.RouterProperties, 1)
assert.Equal(t, "/customer({id})", operation.RouterProperties[0].Path)
assert.Equal(t, "GET", operation.RouterProperties[0].HTTPMethod)
}

func TestParseRouterCommentNoDollarSignAtPathStartErr(t *testing.T) {
t.Parallel()

Expand Down