Skip to content

Commit

Permalink
text/plain allowed in request body (#1029)
Browse files Browse the repository at this point in the history
  • Loading branch information
sdghchj authored Oct 20, 2021
1 parent 9981d9f commit 0548f60
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 4 deletions.
12 changes: 8 additions & 4 deletions operation.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,11 +313,15 @@ func (operation *Operation) ParseParamComment(commentLine string, astFile *ast.F
return nil
}
case "body":
schema, err := operation.parseAPIObjectSchema(objectType, refType, astFile)
if err != nil {
return err
if objectType == PRIMITIVE {
param.Schema = PrimitiveSchema(refType)
} else {
schema, err := operation.parseAPIObjectSchema(objectType, refType, astFile)
if err != nil {
return err
}
param.Schema = schema
}
param.Schema = schema
default:
return fmt.Errorf("%s is not supported paramType", paramType)
}
Expand Down
26 changes: 26 additions & 0 deletions operation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1256,6 +1256,32 @@ func TestParseParamCommentByBodyType(t *testing.T) {
assert.Equal(t, expected, string(b))
}

func TestParseParamCommentByBodyTextPlain(t *testing.T) {
t.Parallel()

comment := `@Param text body string true "Text to process"`
operation := NewOperation(nil)

err := operation.ParseComment(comment, nil)

assert.NoError(t, err)
b, _ := json.MarshalIndent(operation, "", " ")
expected := `{
"parameters": [
{
"description": "Text to process",
"name": "text",
"in": "body",
"required": true,
"schema": {
"type": "string"
}
}
]
}`
assert.Equal(t, expected, string(b))
}

func TestParseParamCommentByBodyTypeWithDeepNestedFields(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 0548f60

Please sign in to comment.