From 8cedf4206a5650204be4065e109c4e7c62be5e0a Mon Sep 17 00:00:00 2001 From: erikfarhanmalik-ralali <56909677+erikfarhanmalik-ralali@users.noreply.github.com> Date: Tue, 31 Dec 2019 20:06:49 +0700 Subject: [PATCH] Fix: Use of go primitive array type in body give error (#593) * 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. --- operation.go | 1 + operation_test.go | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+) diff --git a/operation.go b/operation.go index db598ade9..490d855e4 100644 --- a/operation.go +++ b/operation.go @@ -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" diff --git a/operation_test.go b/operation_test.go index dcf9044b9..160bd89ef 100644 --- a/operation_test.go +++ b/operation_test.go @@ -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()