Skip to content

Commit

Permalink
change the regular expression to fix the issue #853 caused by PR #837
Browse files Browse the repository at this point in the history
  • Loading branch information
sdghchj committed Dec 8, 2020
1 parent a4053fb commit 64db275
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,9 +603,9 @@ func findTypeDef(importPath, typeName string) (*ast.TypeSpec, error) {
return nil, fmt.Errorf("type spec not found")
}

var responsePattern = regexp.MustCompile(`([\w,]+)[\s]+([\w\{\}]+)[\s]+([\w\-\.\/\{\}=,\[\]]+)[^"]*(.*)?`)
var responsePattern = regexp.MustCompile(`([\w,]+)[\s]+([\w\{\}]+)[\s]+([\w\-\.\/\{\}=,\[\]]+)[\s]+(.*)?`)

//RepsonseType{data1=Type1,data2=Type2}
//ResponseType{data1=Type1,data2=Type2}
var combinedPattern = regexp.MustCompile(`^([\w\-\.\/\[\]]+)\{(.*)\}$`)

func (operation *Operation) parseObjectSchema(refType string, astFile *ast.File) (*spec.Schema, error) {
Expand Down
20 changes: 10 additions & 10 deletions operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ func TestParseResponseCommentWithBasicType(t *testing.T) {
}

func TestParseResponseCommentWithBasicTypeAndCodes(t *testing.T) {
comment := `@Success 200,201,default {string} string "it's ok'"`
comment := `@Success 200,201,default {string} string "it's ok"`
operation := NewOperation(nil)
err := operation.ParseComment(comment, nil)
assert.NoError(t, err, "ParseComment should not fail")
Expand All @@ -681,19 +681,19 @@ func TestParseResponseCommentWithBasicTypeAndCodes(t *testing.T) {
expected := `{
"responses": {
"200": {
"description": "it's ok'",
"description": "it's ok",
"schema": {
"type": "string"
}
},
"201": {
"description": "it's ok'",
"description": "it's ok",
"schema": {
"type": "string"
}
},
"default": {
"description": "it's ok'",
"description": "it's ok",
"schema": {
"type": "string"
}
Expand All @@ -704,7 +704,7 @@ func TestParseResponseCommentWithBasicTypeAndCodes(t *testing.T) {
}

func TestParseEmptyResponseComment(t *testing.T) {
comment := `@Success 200 "it's ok"`
comment := `@Success 200 "it is ok"`
operation := NewOperation(nil)
err := operation.ParseComment(comment, nil)
assert.NoError(t, err, "ParseComment should not fail")
Expand All @@ -714,15 +714,15 @@ func TestParseEmptyResponseComment(t *testing.T) {
expected := `{
"responses": {
"200": {
"description": "it's ok"
"description": "it is ok"
}
}
}`
assert.Equal(t, expected, string(b))
}

func TestParseEmptyResponseCommentWithCodes(t *testing.T) {
comment := `@Success 200,201,default "it's ok"`
comment := `@Success 200,201,default "it is ok"`
operation := NewOperation(nil)
err := operation.ParseComment(comment, nil)
assert.NoError(t, err, "ParseComment should not fail")
Expand All @@ -732,13 +732,13 @@ func TestParseEmptyResponseCommentWithCodes(t *testing.T) {
expected := `{
"responses": {
"200": {
"description": "it's ok"
"description": "it is ok"
},
"201": {
"description": "it's ok"
"description": "it is ok"
},
"default": {
"description": "it's ok"
"description": "it is ok"
}
}
}`
Expand Down

0 comments on commit 64db275

Please sign in to comment.