如何在OpenAPI 2.0中为同一操作定义path和formData参数? [英] How to define path and formData parameters for the same operation in OpenAPI 2.0?

查看:194
本文介绍了如何在OpenAPI 2.0中为同一操作定义path和formData参数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个看起来像/test/{id}/relationships/image的图像上传端点.我想使用OpenAPI 2.0(Swagger 2.0)描述此端点.

I have an image upload endpoint that looks like /test/{id}/relationships/image. I want to describe this endpoint using OpenAPI 2.0 (Swagger 2.0).

端点同时具有path和formData参数.我尝试了以下方法:

The endpoint has both path and formData parameters. I tried the following:

swagger: '2.0'
info:
  title: API
  version: 1.0.0
host: api.server.de
schemes:
  - https
produces:
  - application/json
paths:
  '/test/{id}/relationships/image':
    post:
      operationId: addImage
      consumes:
        - multipart/form-data
      parameters:
        - in: path
          name: id
          required: true
          schema:
            type: integer
            format: int32
        - in: formData
          name: file
          type: file
          required: true
          description: The file to upload.
        - in: formData
          name: metadata
          type: string
          required: false
          description: Description of file contents.
      responses:
        '202':
          description: Uploaded

但是Swagger编辑器显示错误:

But Swagger Editor shows errors:

架构错误位于 path ['/test/{id}/relationships/image'].post.parameters [0] .in应该 等于允许的值之一allowedValues:主体,标头, formData,查询跳至第17行

Schema error at paths['/test/{id}/relationships/image'].post.parameters[0].in should be equal to one of the allowed values allowedValues: body, header, formData, query Jump to line 17

架构错误位于 path ['/test/{id}/relationships/image'].post.parameters [0]不应 具有其他属性extraProperty:架构,名称, 必需跳到第17行

Schema error at paths['/test/{id}/relationships/image'].post.parameters[0] should NOT have additional properties additionalProperty: schema, in, name, required Jump to line 17

我在做什么错了?

推荐答案

在您的path参数中,更改

In your path parameter, change

          schema:
            type: integer
            format: int32

          type: integer
          format: int32

在OpenAPI/Swagger 2.0中,路径,标头,查询和formData参数直接使用type,而没有schema. schema关键字仅用于身体参数.

In OpenAPI/Swagger 2.0, path, header, query and formData parameters use type directly, without a schema. The schema keyword is used for body parameters only.

这篇关于如何在OpenAPI 2.0中为同一操作定义path和formData参数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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