相关疑难解决方法(0)

OpenAPI数组内的多种类型

我在使用OpenAPI 3定义可重用的模式组件时遇到了麻烦,因为OpenAPI 3允许包含多种类型的数组.每个项类型都继承自同一父类,但具有特定的子属性.这似乎model在SwaggerHub 的视图中正常工作,但示例视图未正确显示数据.

TLDR; 有没有办法在OpenAPI 3中定义包含不同对象类型的数组?

Response:
  allOf:
    - $ref: '#/components/schemas/BaseResponse'
    - type: object
      title: A full response
      required:
      - things
      properties:
        things:
          type: array
          items:
            anyOf:
              - $ref: '#/components/schemas/ItemOne'
              - $ref: '#/components/schemas/ItemTwo'
              - $ref: '#/components/schemas/ItemThree'
Run Code Online (Sandbox Code Playgroud)

swagger swagger-ui openapi

4
推荐指数
1
解决办法
3609
查看次数

标签 统计

openapi ×1

swagger ×1

swagger-ui ×1