我正在使用app.swaggerhub.com生成标准2.0规范。
我的代码如下:
036 definitions:
--- // code that defines 'fieldRequirement' and 'slideRequirement'
106 requirement:
107 type: array
108 items:
109 oneOf:
110 - $ref: '#/definitions/fieldRequirement'
111 - $ref: '#/definitions/slideRequirement'
这将在同一行(106)上返回3个错误:
106 should NOT have additional properties additionalProperty: oneOf
106 should be array
106 should match some schema in anyOf
我要完成的是一个模型,该模型允许将fieldRequirement或slideRequirement作为需求中的数组元素。
答案 0 :(得分:1)
oneOf
,只有swagger 3.0不支持。
但是,如果您不能升级到swagger 3.0,则可以在字段discriminator
中使用多态,在这种情况下,您需要一个文件:
requirement:
type: array
items:
- $ref: '#/definitions/Requirement'
...
definitions:
Requirement:
type: object
discriminator: requirementType
properties:
requirementType:
type: string
required:
- requirementType
FieldRequirement:
allOf:
- $ref: '#/definitions/Requirement'
- type: object
properties:
...
SlideRequirement:
allOf:
- $ref: '#/definitions/Requirement'
- type: object
properties:
...