【问题标题】:OpenAPI 3 - Reuse of propertiesOpenAPI 3 - 重用属性
【发布时间】:2019-09-05 04:49:59
【问题描述】:

以 OpenAPI 3 定义为例:

components:
  schemas:
    Foo:
      properties:
        string:
          type: string
        enumField:
          type: string
          enum: ['VALUE_1', 'VALUE_2']
    Bar:
      properties:
        enumField:
          type: string
          enum: ['VALUE_1', 'VALUE_2']

有没有办法重复使用enumField 还是每次使用时都必须指定它?

【问题讨论】:

标签: swagger openapi


【解决方案1】:

我不知道是否可以引用单个属性,但您可以使用架构并拆分它。

这是一个基本结构示例,说明您可以做什么:

SchemaBase:
  type: object
  properties:
    foo:
      type: string

SchemaFull:
  allOf:
    - $ref: '#/components/schemas/SchemaBase'
    - type: object
      properties:
        bar:
          type: string

在你的情况下可能是这样的:

components:
  schemas:
    EnumField:
      properties:
        enumField:
          type: string
          enum: ['VALUE_1', 'VALUE_2']
    Foo:
      allOf:
        - $ref: '#/components/schemas/EnumField'
        - properties:
            string:
              type: string
    Bar:
      allOf:
        - $ref: '#/components/schemas/EnumField'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-30
    • 2022-01-03
    • 1970-01-01
    • 2020-05-16
    • 2019-04-04
    • 1970-01-01
    相关资源
    最近更新 更多