【发布时间】:2015-10-09 11:45:48
【问题描述】:
我有一个对象,它的属性是一个类型为类型列表之一的对象。我的所有尝试都被 Swagger Editor 拒绝,并出现以下错误:
Data does not match any schemas from 'anyOf'
Jump to line 43
Details
Object
code: "ANY_OF_MISSING"
message: "Data does not match any schemas from 'anyOf'"
path: Array [7]
inner: Array [2]
level: 900
type: "Swagger Error"
description: "Data does not match any schemas from 'anyOf'"
lineNumber: 43
完整的swagger规范文件如下(有问题的字段是DataSetsInquiryRsp.dataSets.dataSet):
swagger: '2.0'
info:
title: My API
description: My Awesome API
version: 1.0.0
paths:
/dataSetsInquiry:
get:
description: Retrieve one or more data-sets.
parameters:
- name: ids
in: query
description: List of identifiers of requested data-sets.
required: true
type: array
items:
type: string
responses:
'200':
description: Requested data-sets.
schema:
$ref: '#/definitions/DataSetsInquiryRsp'
default:
description: Unexpected error
schema:
$ref: '#/definitions/Error'
definitions:
DataSetsInquiryRsp:
type: object
additionalProperties: false
properties:
sessionIdentifier:
description: Identifier of the secure session with the server.
type: number
dataSets:
type: object
additionalProperties: false
properties:
id:
type: string
dataSet:
type: array
items:
oneOf:
- $ref: '#/definitions/Customer'
- $ref: '#/definitions/Merchant'
Customer:
type: object
additionalProperties: false
properties:
firstName:
description: First name of the customer
type: string
lastName:
description: Last name of the customer
type: string
Merchant:
type: object
additionalProperties: false
properties:
code:
description: Code the Merchant.
type: string
name:
description: Name of the Merchant.
type: string
【问题讨论】:
-
我的问题是在 2015 年,您指出的问题被我重复了在 2016 年被问过。什么是重复的?另外,我已经回答了问题并说明了我遇到的错误的来源!
-
该问题和答案有更多细节,具体来说,OpenAPI 3.0 现在支持
oneOf/anyOf。只需将其链接到此处以供将来的访问者使用。 -
将我的问题标记为新问题的重复是不准确的。最好更新我的答案并参考对新问题的回复。或者使用其他准确的机制。
标签: swagger jsonschema json-schema-validator