昂首阔步发送正文和formData参数 [英] Swagger send body and formData parameter

查看:3368
本文介绍了昂首阔步发送正文和formData参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Swagger 2.0,并且在发送多个post参数时遇到问题.我有一个大幅度的错误Operation cannot have a body parameter and a formData parameter,而且我不知道如何解决.在我的定义中,我有一个body参数,此参数需要JSON格式,但另一方面,我还有其他参数,例如要上传的文件和文件名.

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.

我该如何同时发送body和formData参数?

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

这是Web服务定义:

  /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

推荐答案

根据 swagger 规范

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

这篇关于昂首阔步发送正文和formData参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆