【问题标题】:How can I override examples in openapi?如何覆盖 openapi 中的示例?
【发布时间】:2020-06-08 11:44:31
【问题描述】:

我有响应结构:

responses:
  '200':
    description: OK
    content:
      application/json:
        schema:
          type: object
          properties:
            data:
              allOf:
              - { $ref: ../../components/schemas/Product.yaml }
              example:
                active: false

还有 Product.yaml 之一:

type: object
description: Product
properties:
  id:
    description: ID
    type: integer
    example: 1
  name:
    description: Name
    type: string
    example: 'fresh baguette'
  active:
    description: Is active
    type: boolean
    example: true

所以我想覆盖活动示例,当我这样做时:

data:
  allOf:
  - { $ref: ../../components/schemas/Product.yaml }
  example:
    active: false

在“响应样本”下的 redoc ui 中,我看到了唯一的活动属性。

我的问题是如何在不覆盖每个产品属性的情况下覆盖仅活动属性的示例?

【问题讨论】:

  • 我的openapi版本是3.0.2

标签: swagger openapi


【解决方案1】:

在示例中无法覆盖单个属性值。您需要提供整个示例:

responses:
  '200':
    description: OK
    content:
      application/json:
        schema:
          type: object
          properties:
            data:
              $ref: ../../components/schemas/Product.yaml

          example:
            data:
              id: 1
              name: fresh baguette
              active: false

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    • 1970-01-01
    • 2019-07-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多