【发布时间】:2019-12-30 23:49:09
【问题描述】:
我正在为一个 api 创建一个 OpenAPI 3 规范,该规范具有需要一些属性的对象,而对于某些对象,它们是任何属性。当我创建如下规范时,它会引发错误,我无法修复。
EnrollementRequest:
type: object
properties:
consent:
$ref: "#/components/schemas/ConsentEnum"
cid:
$ref: '#/components/schemas/CID'
card:
$ref: '#/components/schemas/Card'
enrollmentDateTime :
description: The date and time of enrollment with respective timezone
format: date-time
example: 2018-11-13T20:20:39+00:00
campaign_code:
description: the campaign-code for which customer wants to enroll
type: string
offer_code:
description: the offer-code for which customer wants to enroll
type: string
channelInfo:
$ref: '#/components/schemas/Channel'
required:
- consent
- cid
- enrollmentDateTime
- channelInfo
anyOf:
- campaign_code
- offer_code
Swagger 编辑器给出如下错误-
Errors
Structural error at components.schemas.EnrollementRequest.anyOf.0
should be object
Jump to line ...
Structural error at components.schemas.EnrollementRequest.anyOf.1
should be object
Jump to line ...
使用以下建议时
anyOf:
- required: [campaign_code]
- required: [offer_code]
验证错误消失了,但 swagger 编辑器架构/模型视图未显示任何内容,如下所示 -
【问题讨论】:
标签: json swagger schema openapi