Swagger 多部分POST请求中带有参数的招摇过市错误

Swagger 多部分POST请求中带有参数的招摇过市错误,swagger,swagger-2.0,swagger-editor,Swagger,Swagger 2.0,Swagger Editor,我正在使用Swagger Editor来记录一个现有的API,内置于节点中,但它不断给我以下错误: 路径处的架构错误。/upload/Rate.post.parameters[0] 不完全是来自, 此错误出现在“我的代码”的3个位置: 路径./upload/Rate.post.parameters[0] 路径./upload/Rate.post.parameters[1] 路径./users/register.post.parameters[0] 我已经搜索了很多次,但是,例如,这个链接没有

我正在使用Swagger Editor来记录一个现有的API,内置于节点中,但它不断给我以下错误:

路径处的架构错误。/upload/Rate.post.parameters[0] 不完全是来自,

此错误出现在“我的代码”的3个位置:

  • 路径./upload/Rate.post.parameters[0]
  • 路径./upload/Rate.post.parameters[1]
  • 路径./users/register.post.parameters[0]
我已经搜索了很多次,但是,例如,这个链接没有解决我的问题,尽管它是相同的错误:

以下是我对昂首阔步的定义:

  /users/register:
    post:
      tags:
      - "users"
      description: Allows an user to register at the Server
      produces:
        - application/json
      parameters:
        - name: body
          in: body
          description: JSON Object with information for a Register request from an User
          schema: 
            type: object
            required:
              - username
              - password
              - weight
              - height
              - gender
              - restRate
              - age
            properties:
              username:
                type: string
              password:
                type:
                format: password
              weight:
                type: integer
              height:
                type: integer
              gender:
                type: string
              restRate:
                type: integer
              age: 
                type: integer
      # Expected responses for this operation:
      responses:
        # Response code
        200:
          description: Register successful
          schema:
            type: string

  /upload/Rate:
    post:
      tags:
      - "upload"
      description: Allows an user to upload a file into the server
      produces:
        - application/json
      consumes: 
        - multipart/form-data
      parameters:
        - name: body
          in: formData
          description: JSON Object with information for an upload request from an User
          required: false
          schema:
            type: object
            required:   
              - user
              - overlap
              - window 
              - latitude
              - longitude
              - time
              - date
            properties:
              user:
                type: string
              overlap:
                type: string
              window:
                type: string
              latitude:
                type: string
              longitude:
                type: string
              time:
                type: string
              date:
                type: string
        - name: files 
          in: formData
          description: File with the corresponding Rate
          required: false
          schema:
            type: object
            required:
              - rate
            properties:
              rate:
                type: file
      # Expected responses for this operation:
      responses:
        # Response code
        200:
          description: Login successful
          schema:
            type: string
也许这会有所帮助,但一旦我解析了post路由的参数,post路由(上传/速率)应该会收到类似这样的请求:

user = req.body.user;
rr = req.files.rate;
overlap = req.body.overlap;
windowT = req.body.window;
latitude = req.body.latitude;
longitude = req.body.longitude;
time = req.body.time;
date = req.body.date;

谢谢你的帮助和时间

存在多个问题

/upload/register

  • 架构属性
    密码
    缺少
    类型
    的值
  • 属性名称不匹配-
    restHR
    (在
    properties
    下)与
    restRate
    (在
    所需的
    列表中)
上传/速率

  • 这里的问题是由
    多部分/表单数据
    请求中的对象参数引起的。在OpenAPI(fka Swagger)2.0中,表单参数可以是基本值和数组,但不能是对象。因此,您的示例无法使用OpenAPI 2.0进行描述

    如果您正在设计一个新的API(或者如果您能够并且愿意将API实现更改为与OpenAPI 2.0兼容),可能的解决方案是:

    • 将操作更改为使用
      application/json
      ,并将所有输入参数合并到一个json对象中。文件参数需要实现为base64字符串-
      类型:string
      格式:byte
    • 使用
      多部分/表单数据
      ,但将对象参数拆分为单个表单参数

    即将发布的OpenAPI 3.0将支持表单数据中的对象参数: