openapi-spec-validator icon indicating copy to clipboard operation
openapi-spec-validator copied to clipboard

oneOf fails in post parameter

Open lihan opened this issue 6 years ago • 2 comments

Try validating against the schema from https://swagger.io/docs/specification/data-models/oneof-anyof-allof-not/

Got error of

Failed validating 'oneOf' in schema['properties']['paths']['patternProperties']['^/']['properties']['patch']['properties']['requestBody']:
    {'oneOf': [{'$ref': '#/definitions/requestBody'},
               {'$ref': '#/definitions/reference'}]}

Source spec file

paths:
  /pets:
    patch:
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Dog'
      responses:
        '200':
          description: Updated
components:
  schemas:
    Dog:
      type: object
      properties:
        bark:
          type: boolean
        breed:
          type: string
          enum: [Dingo, Husky, Retriever, Shepherd]
    Cat:
      type: object
      properties:
        hunts:
          type: boolean
        age:
          type: integer

lihan avatar Sep 07 '18 03:09 lihan

The spec validator seems to be working fine with this spec on master once I added some required fields.

# added required fields to your spec
openapi: 3.0.0
info:
  version: 0.0.0
  title: pets
# added required fields to your spec

paths:
  /pets:
    patch:
      requestBody:
        content:
          application/json:
            schema:
              oneOf:
                - $ref: '#/components/schemas/Cat'
                - $ref: '#/components/schemas/Dog'
      responses:
        '200':
          description: Updated
components:
  schemas:
    Dog:
      type: object
      properties:
        bark:
          type: boolean
        breed:
          type: string
          enum: [Dingo, Husky, Retriever, Shepherd]
    Cat:
      type: object
      properties:
        hunts:
          type: boolean
        age:
          type: integer
> openapi-spec-validator --schema 3.0.0 lihan.yaml
OK

I think this may have something to do with the Draft4Validator used in connexion, and not to do with the openapi-spec-validator (the spec itself validates fine).

dtkav avatar Sep 07 '18 04:09 dtkav

Just wanted to follow up on this. I'm also experiencing this problem. Any fixes?

raini35 avatar Aug 30 '19 16:08 raini35