Swagger send body and formData parameter

I am using Swagger 2.0 and I have a problem sending multiple message parameters. I have a swagger Operation cannot have a body parameter and a formData parameter , and I don't know how to fix it. In my definition, I have a body parameter, and this parameter needs JSON format, but I have another parameter, like files to upload and a file name.

How do I do to send body and formData parameters as?

Here is the definition of a web service:

  /updateDatas: post: summary: Upadate datas description: | Update datas consumes: - multipart/form-data produces: - application/json parameters: - name: firstFileName in: formData description: First file name. required: true type: string - name: secondFileName in: formData description: Second file name. required: true type: string - name: datas in: body description: Json object informations. required: true schema: $ref: '#/definitions/Datas' - name: firstFile in: formData description: First file .jpg required: true type: file - name: clientFile in: formData description: Second file .jpg required: true type: file tags: - Application responses: '200': description: Uploaded schema: $ref: '#/definitions/Upload' '401': description: Unauthorized Bad Token 
+8
rest multipartform-data swagger
source share
2 answers

One way to solve the problem is to set the "data" as the form parameter with the type "file". Here is an example:

  parameters: - name: petId in: path description: ID of pet to update required: true type: integer format: int64 - name: additionalMetadata in: formData description: Additional data to pass to server required: false type: string - name: file in: formData description: file to upload required: false type: file 

Link: https://github.com/swagger-api/swagger-codegen/blob/master/modules/swagger-codegen/src/test/resources/2_0/petstore.yaml#L257

UPDATE: body parameters and form parameters cannot coexist: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#parameterObject

The body is the payload added to the HTTP request. Since there can only be one payload, there can only be one body parameter. The parameter name body does not affect the parameter itself and is used for documentation purposes only. Because shape parameters are also in payload, body and shape parameters cannot exist together for the same operation.

+5
source share

According to the parameters, see type:body and type:formData cannot exist together for the same operation.

+5
source share

All Articles