Swagger send body and formData parameter

John picture John · Apr 26, 2016 · Viewed 40.8k times · Source

I'm using Swagger 2.0 and I have a problem to send multiple post parameters. I have a swagger error 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 need a JSON format but a side I have other parameter like files to upload and filename.

How can I do to send body and formData parameters both ?

Here is the web service definition :

  /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

Answer

aK26 picture aK26 · Oct 19, 2016

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