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 (#552)

Thanks for your contribution.
  • Loading branch information
Nephylhim authored and ubogdan committed Nov 9, 2019
1 parent c05c273 commit fb06668
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion operation.go
Original file line number Diff line number Diff line change
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\.\/\-{}\+:]+)[[:blank:]]+\[(\w+)]`)

// ParseRouterComment parses comment for gived `router` comment string.
func (operation *Operation) ParseRouterComment(commentLine string) error {
Expand Down
25 changes: 24 additions & 1 deletion operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,30 @@ func TestParseRouterCommentWithPlusSign(t *testing.T) {
assert.Equal(t, "POST", operation.HTTPMethod)
}

func TestParseRouterCommentOccursErr(t *testing.T) {
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 TestParseRouterCommentNoColonSignAtPathStartErr(t *testing.T) {
comment := `/@Router :customer/get-wishlist/{wishlist_id}:move [post]`
operation := NewOperation()
err := operation.ParseComment(comment, nil)
assert.Error(t, err)
}

func TestParseRouterCommentMethodSeparationErr(t *testing.T) {
comment := `/@Router /api/{id}|,*[get`
operation := NewOperation()
err := operation.ParseComment(comment, nil)
assert.Error(t, err)
}

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

0 comments on commit fb06668

Please sign in to comment.