swagger - 在 OpenAPI 2 中等效使用 oneOf(来自 OpenAPI 3)

标签 swagger openapi swagger-2.0

如何使用 oneOf 将此代码段调整为等效的 OpenAPI 2.0 版本?

  formats:
    type: array
    description: Possible parameter format.
    items:
      oneOf:
      - type: string
      - type: object
        description: Matched alias formats
        properties:
          representation:
            type: array
            description: Alias format representations
            items:
              type: string
          match_multiple:
            type: boolean
            optional: true
          display:
            type: string
            description: Display string of alias format

最佳答案

在 OpenAPI 2.0 中,您最多能做的就是使用 typeless schema {} 表示 items,这意味着项目可以是除 null 之外的任何内容 - 数字、对象、字符串等。您无法指定确切的类型对于items,但您可以添加具有不同项目类型的数组的示例

formats:
  type: array
  items: {}  # <--- means "any type" (except null)

  example:
    # example of a string item
    - test

    # example of an object item
    - representation: [one, two]
      match_multiple: false
      display: something

注意:无类型架构 {} 只能在 OAS2 主体参数和响应架构中使用。路径、 header 和表单参数需要数组项的原始类型

关于swagger - 在 OpenAPI 2 中等效使用 oneOf(来自 OpenAPI 3),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70112647/

相关文章:

java - Springfox 从 2.9.2 更新到 2.10.4 后错误 "Unable to infer base url. ..."

node.js - 如何在使用 swagger-ui-express 和 swagger-jsdoc 时正确使用 swagger 文件中的 $ref

javascript - 导入 OAS 生成的 api 时 angular 8 崩溃

swagger - 为定义的 Swagger 路由提供备用(国际)拼写

SwaggerUI/YAML - 映射条目的缩进错误 : unable to find a reason

rest - 在 swagger API 中指定一个字符串数组作为 body 参数

swagger - 如何为 API-Gateway 在 swagger 中设置 "Use Lambda Proxy integration"?

yaml - Swagger 文档错误 `Should be object`

runtime - 夸尔库斯 : Change OpenApi authorization url at runtime

javascript - 有没有办法在 swagger-ui 3.* 中只呈现特定的 api 端点?