1

I have an object that has a property that is an object whose type would be one of list of types. All my attempts have been rejected by Swagger Editor with the following error:

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

The full swagger specification file is as follows (the field in question is 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
4

1 回答 1

2

好吧,问题只是Swagger不支持的事实oneOff。事实上,Swagger支持一个子集Json-Schema并添加一些东西(file例如数据类型)。

这里不好的是返回的错误Swagger。它没有帮助匹配。Json-Schema到目前为止,我使用过的所有验证器都是这种情况: is-my-json-valid, jsen.

于 2015-10-11T17:00:38.510 回答