Skip to content

Commit

Permalink
fix: router now support colon sign. Useful for custom methods using c…
Browse files Browse the repository at this point in the history
…ustom verbs
  • Loading branch information
Nephylhim committed Nov 6, 2019
1 parent c05c273 commit 381b917
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 1 addition & 1 deletion operation.go
Expand Up @@ -437,7 +437,7 @@ func parseMimeTypeList(mimeTypeList string, typeList *[]string, format string) e
return nil
}

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

// ParseRouterComment parses comment for gived `router` comment string.
func (operation *Operation) ParseRouterComment(commentLine string) error {
Expand Down
9 changes: 9 additions & 0 deletions operation_test.go
Expand Up @@ -120,6 +120,15 @@ func TestParseRouterCommentWithPlusSign(t *testing.T) {
assert.Equal(t, "POST", operation.HTTPMethod)
}

func TestParseRouterCommentWithColonSign(t *testing.T) {
comment := `/@Router /customer/get-wishlist/{wishlist_id}:move [post]`
operation := NewOperation()
err := operation.ParseComment(comment, nil)
assert.NoError(t, err)
assert.Equal(t, "/customer/get-wishlist/{wishlist_id}:move", operation.Path)
assert.Equal(t, "POST", operation.HTTPMethod)
}

func TestParseRouterCommentOccursErr(t *testing.T) {
comment := `/@Router /customer/get-wishlist/{wishlist_id}`
operation := NewOperation()
Expand Down

0 comments on commit 381b917

Please sign in to comment.