Swagger 招摇过市:如何表示类型为类型列表之一的属性?

Swagger 招摇过市:如何表示类型为类型列表之一的属性?,swagger,jsonschema,json-schema-validator,Swagger,Jsonschema,Json Schema Validator,我有一个对象,它的属性是一个对象,其类型将是类型列表中的一个。我的所有尝试都被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]

我有一个对象,它的属性是一个对象,其类型将是类型列表中的一个。我的所有尝试都被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
不支持
oneOff
。事实上,
Swagger
支持
Json模式的一个子集
,并添加了一些东西(例如数据类型
file


这里糟糕的是,
Swagger
返回的错误。这对匹配没有帮助。到目前为止,我使用过的所有
Json模式
验证器都是这样:,。

我的问题可能在2015年重复,您指出的被我重复的问题在2016年被提出。什么是什么的复制品?此外,我已经回答了这个问题,并解释了我遇到的错误的来源!这个问题和答案有一些更详细的信息,具体来说,
oneOf
/
anyOf
现在在OpenAPI 3.0中得到了支持。只是为了将来的访问者把它链接到这里。将我的问题标记为新问题的副本是不准确的。最好是更新我的答案,并参考对新问题的回答。或者使用另一种精确的机制。
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