Skip to content

Commit

Permalink
fix: formData parameters in only supports files type (#146)
Browse files Browse the repository at this point in the history
  • Loading branch information
easonlin404 authored Jun 7, 2018
1 parent 2812f2c commit 98128c0
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 1 addition & 1 deletion operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
25 changes: 24 additions & 1 deletion operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand All @@ -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()
Expand Down
3 changes: 1 addition & 2 deletions schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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
}
}

0 comments on commit 98128c0

Please sign in to comment.