Skip to content

Commit

Permalink
Fix: Use of go primitive array type in body give error (#593)
Browse files Browse the repository at this point in the history
* Fixed issues_592: Use of go primitive array type in body give error

* Added unit test for ParseParamComment with body type is array of primitive Go type.
  • Loading branch information
erikfarhanmalik-ralali authored and easonlin404 committed Dec 31, 2019
1 parent 549622f commit 8cedf42
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
1 change: 1 addition & 0 deletions operation.go
Expand Up @@ -144,6 +144,7 @@ func (operation *Operation) ParseParamComment(commentLine string, astFile *ast.F
if strings.HasPrefix(refType, "[]") == true {
objectType = "array"
refType = strings.TrimPrefix(refType, "[]")
refType = TransToValidSchemeType(refType)
} else if IsPrimitiveType(refType) ||
paramType == "formData" && refType == "file" {
objectType = "primitive"
Expand Down
27 changes: 27 additions & 0 deletions operation_test.go
Expand Up @@ -499,6 +499,33 @@ func TestParseParamCommentByBodyType(t *testing.T) {
assert.Equal(t, expected, string(b))
}

func TestParseParamCommentByBodyTypeArrayOfPrimitiveGo(t *testing.T) {
comment := `@Param some_id body []int true "Some ID"`
operation := NewOperation()
operation.parser = New()
err := operation.ParseComment(comment, nil)

assert.NoError(t, err)
b, _ := json.MarshalIndent(operation, "", " ")
expected := `{
"parameters": [
{
"description": "Some ID",
"name": "some_id",
"in": "body",
"required": true,
"schema": {
"type": "array",
"items": {
"type": "integer"
}
}
}
]
}`
assert.Equal(t, expected, string(b))
}

func TestParseParamCommentByBodyTypeErr(t *testing.T) {
comment := `@Param some_id body model.OrderRow true "Some ID"`
operation := NewOperation()
Expand Down

0 comments on commit 8cedf42

Please sign in to comment.