在单个模式中引用多个模式
Reference multiple schema in a single schema
在 swaggerhub 中,我正在尝试构建一个 restful API。我为此创建了 n 个 POJO 以供请求。我想将它们表示为其他 POJO 示例中的引用:
ClientInformation:
type: object
schema:
$ref: '#/definitions/EditClient'
$ref: '#/definitions/OtherDetails' #Duplicate mapping key error I see at this line
properties:
notes:
type: string
example: This is a test
description: A description
我尝试了 ,
但没有成功。欢迎推荐。
如果 ClientInformation
是 EditClient
和 OtherDetails
模式的合并,您需要 allOf
:
ClientInformation:
allOf:
- $ref: '#/definitions/EditClient'
- $ref: '#/definitions/OtherDetails'
- type: object
properties:
notes:
type: string
example: This is a test
description: A description
如果 ClientInformation
具有作为其他模式实例的属性,您可以 $ref
属性 模式如下:
ClientInformation:
type: object
properties:
notes:
type: string
example: This is a test
description: A description
foo:
$ref: '#/definitions/EditClient'
bar:
$ref: '#/definitions/OtherDetails'
在 swaggerhub 中,我正在尝试构建一个 restful API。我为此创建了 n 个 POJO 以供请求。我想将它们表示为其他 POJO 示例中的引用:
ClientInformation:
type: object
schema:
$ref: '#/definitions/EditClient'
$ref: '#/definitions/OtherDetails' #Duplicate mapping key error I see at this line
properties:
notes:
type: string
example: This is a test
description: A description
我尝试了 ,
但没有成功。欢迎推荐。
如果 ClientInformation
是 EditClient
和 OtherDetails
模式的合并,您需要 allOf
:
ClientInformation:
allOf:
- $ref: '#/definitions/EditClient'
- $ref: '#/definitions/OtherDetails'
- type: object
properties:
notes:
type: string
example: This is a test
description: A description
如果 ClientInformation
具有作为其他模式实例的属性,您可以 $ref
属性 模式如下:
ClientInformation:
type: object
properties:
notes:
type: string
example: This is a test
description: A description
foo:
$ref: '#/definitions/EditClient'
bar:
$ref: '#/definitions/OtherDetails'