From 70f63188967efdf13d28be19e9167b2137ad4d25 Mon Sep 17 00:00:00 2001 From: Thomas COUSSOT Date: Wed, 6 Nov 2019 17:06:46 +0100 Subject: [PATCH] fix: router now support colon sign. Useful for custom methods using custom verbs --- operation.go | 2 +- operation_test.go | 25 ++++++++++++++++++++++++- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/operation.go b/operation.go index 2cbd797df..f207413d2 100644 --- a/operation.go +++ b/operation.go @@ -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 { diff --git a/operation_test.go b/operation_test.go index e95716e78..f3d5273af 100644 --- a/operation_test.go +++ b/operation_test.go @@ -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)