我在openapi文件中有两个模式:
SchemaA:
type: object
properties:
property_a1:
type: string
property_a2:
type: string
SchemaB:
type: object
properties:
property_b1:
type: string
property_b2:
type: string
我想要的结果模式是:
ResultantSchema:
type: object
properties:
property_a1:
type: string
property_a2:
type: string
property_b1:
type: string
property_b2:
type: string
我尝试使用allOf操作符组合如下:
ResultantSchema:
type: object
properties:
- $ref: '#/SchemaA'
- $ref: '#/SchemaB'
但是这会产生一个包含两个对象的schema:
WrongResultantSchema:
- type: object
properties:
property_a1:
type: string
property_a2:
type: string
- type: object
properties:
property_b1:
type: string
property_b2:
type: string
这是错误的…是否有任何方法来实现一个单一的对象,而不是两个嵌套的对象的结果模式?
下面是如何在OpenAPI 3.0中组合多个模式:
ResultantSchema:
allOf:
- $ref: '#/components/schemas/SchemaA'
- $ref: '#/components/schemas/SchemaB'
在OpenAPI 2.0 (swagger: '2.0'
):
ResultantSchema:
allOf:
- $ref: '#/definitions/SchemaA'
- $ref: '#/definitions/SchemaB'