From 98128c0ec9c96ebf8ab53c2d0917901aadc84843 Mon Sep 17 00:00:00 2001 From: Eason Lin Date: Thu, 7 Jun 2018 15:22:08 +0800 Subject: [PATCH] fix: formData parameters in only supports files type (#146) --- operation.go | 2 +- operation_test.go | 25 ++++++++++++++++++++++++- schema.go | 3 +-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/operation.go b/operation.go index 80a1f18e1..f9dda52b1 100644 --- a/operation.go +++ b/operation.go @@ -129,7 +129,7 @@ func (operation *Operation) ParseParamComment(commentLine string) error { } } case "formData": - param = createParameter(paramType, description, name, "file", required) + param = createParameter(paramType, description, name, TransToValidSchemeType(schemaType), required) } param = operation.parseAndExtractionParamAttribute(commentLine, schemaType, param) operation.Operation.Parameters = append(operation.Operation.Parameters, param) diff --git a/operation_test.go b/operation_test.go index 995a7424d..551fad5d3 100644 --- a/operation_test.go +++ b/operation_test.go @@ -315,7 +315,7 @@ func TestParseParamCommentByBodyTypeErr(t *testing.T) { } func TestParseParamCommentByFormDataType(t *testing.T) { - comment := `@Param file formData file true "this is a test file"` + comment := `@Param file formData file true "this is a test file"` operation := NewOperation() operation.parser = New() @@ -337,6 +337,29 @@ func TestParseParamCommentByFormDataType(t *testing.T) { assert.Equal(t, expected, string(b)) } +func TestParseParamCommentByFormDataTypeUint64(t *testing.T) { + comment := `@Param file formData uint64 true "this is a test file"` + operation := NewOperation() + operation.parser = New() + + err := operation.ParseComment(comment) + assert.NoError(t, err) + + b, _ := json.MarshalIndent(operation, "", " ") + expected := `{ + "parameters": [ + { + "type": "integer", + "description": "this is a test file", + "name": "file", + "in": "formData", + "required": true + } + ] +}` + assert.Equal(t, expected, string(b)) +} + func TestParseParamCommentNotMatch(t *testing.T) { comment := `@Param some_id body mock true` operation := NewOperation() diff --git a/schema.go b/schema.go index f07ead285..7667ffa03 100644 --- a/schema.go +++ b/schema.go @@ -12,7 +12,7 @@ func CheckSchemaType(typeName string) { } } -// TransToValidSchemeType is int type will transfer to integer which is goswagger supported type +// TransToValidSchemeType indicates type will transfer golang basic type to swagger supported type. func TransToValidSchemeType(typeName string) string { switch typeName { case "uint", "int", "uint8", "int8", "uint16", "int16", "byte": @@ -28,7 +28,6 @@ func TransToValidSchemeType(typeName string) string { case "string": return "string" default: - // panic(fmt.Errorf("%s is not valid go basic types", typeName)) return typeName // to support user defined types } }