1 openapi
我有两个模式对象:
'#/components/schemas/customer' '#/components/schemas/account'
有没有办法我们可以使用开放 API 3.0 规范使用 '#/components/schemas/customer' 和 '#/components/schemas/account' 定义发布响应正文
这取决于用例。
1) 如果响应是 或customer,account则使用oneOf:
responses:
'200':
description: A `customer` object or an `account` object
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/customer'
- $ref: '#/components/schemas/account'
# Example for Swagger UI - see the note below
example:
foo: bar
Run Code Online (Sandbox Code Playgroud)
Swagger UI 用户请注意:目前 Swagger UI不会从oneOf架构生成示例。解决方法是example在oneOf.
2) 如果响应具有来自customer和 的一组组合属性account,请使用allOf:
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/MyResponse'
components:
MyResponse:
allOf:
- $ref: '#/components/schemas/customer'
- $ref: '#/components/schemas/account'
Run Code Online (Sandbox Code Playgroud)
3) 如果响应有两个属性,其中一个是对象customer,另一个是account对象,则使用以下内容:
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/MyResponse'
components:
MyResponse:
type: object
properties:
customer:
$ref: '#/components/schemas/customer'
account:
$ref: '#/components/schemas/account'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2040 次 |
| 最近记录: |