Skip to content

Commit

Permalink
Feat: Add support for parenthesis in router patterns (#1859)
Browse files Browse the repository at this point in the history
  • Loading branch information
alifemove authored Oct 17, 2024
1 parent 7159b0f commit d323b48
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
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

0 comments on commit d323b48

Please sign in to comment.