Swagger:如何表示类型为 oneOf 类型列表的 属性?
Swagger: how to represent a property whose type is oneOf a list of types?
我有一个具有 属性 的对象,该对象的类型是类型列表之一。我的所有尝试都被 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
好吧,问题只是 Swagger
不支持 oneOff
。事实上,Swagger
支持 Json-Schema
的一个子集并添加了一些东西(例如数据类型 file
)。
这里不好的是Swagger
返回的错误。它无助于匹配。这是我迄今为止合作过的所有 Json-Schema
个验证器的情况:is-my-json-valid
, jsen
.
我有一个具有 属性 的对象,该对象的类型是类型列表之一。我的所有尝试都被 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
好吧,问题只是 Swagger
不支持 oneOff
。事实上,Swagger
支持 Json-Schema
的一个子集并添加了一些东西(例如数据类型 file
)。
这里不好的是Swagger
返回的错误。它无助于匹配。这是我迄今为止合作过的所有 Json-Schema
个验证器的情况:is-my-json-valid
, jsen
.