【问题标题】:Equivalent use of oneOf (from OpenAPI 3) in OpenAPI 2在 OpenAPI 2 中等效使用 oneOf(来自 OpenAPI 3)
【发布时间】:2022-01-03 19:41:48
【问题描述】:

如何将这个带有oneOf 的sn-p 调整为等效的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

【问题讨论】:

标签: swagger openapi swagger-2.0


【解决方案1】:

在 OpenAPI 2.0 中,您最多可以使用typeless schema {} 代替items,这意味着项目可以是除null 之外的任何东西——数字、对象、字符串等。您不能指定items 的确切类型,但您可以添加具有不同项目类型的数组的 example。

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 正文参数和响应架构。路径、标题和表单参数需要用于数组项的原始 type。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-09-30
    • 2020-10-26
    • 1970-01-01
    • 1970-01-01
    • 2021-08-26
    • 2019-09-05
    • 2022-12-01
    相关资源
    最近更新 更多