From ca464bf74793f6bc18b622bd751c1a2a8d6d023f Mon Sep 17 00:00:00 2001 From: Eason Lin Date: Fri, 10 Jan 2020 19:49:27 +0800 Subject: [PATCH] feat: support only remain slash (#605) * support only remain slash * fix gofmt * move test in right place Co-authored-by: sdghchj Co-authored-by: Bogdan U --- operation.go | 2 +- operation_test.go | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/operation.go b/operation.go index d966b36ce..b3ee04379 100644 --- a/operation.go +++ b/operation.go @@ -505,7 +505,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 gived `router` comment string. func (operation *Operation) ParseRouterComment(commentLine string) error { diff --git a/operation_test.go b/operation_test.go index 64951a3a0..6653a63e1 100644 --- a/operation_test.go +++ b/operation_test.go @@ -111,6 +111,15 @@ func TestParseRouterComment(t *testing.T) { assert.Equal(t, "GET", operation.HTTPMethod) } +func TestParseRouterOnlySlash(t *testing.T) { + comment := `// @Router / [get]` + operation := NewOperation() + err := operation.ParseComment(comment, nil) + assert.NoError(t, err) + assert.Equal(t, "/", operation.Path) + assert.Equal(t, "GET", operation.HTTPMethod) +} + func TestParseRouterCommentWithPlusSign(t *testing.T) { comment := `/@Router /customer/get-wishlist/{proxy+} [post]` operation := NewOperation()