equest & reponse bodies fail validation when using oneOf to specify alternate schemas
Below the YAML. The additional properties validation is disabled!.
openapi: 3.0.3
info:
version: 1.0.0
title: My Application
servers:
- url: http://localhost:8080/api
paths:
/Pets:
post:
summary: Add a new pet
requestBody:
description: A JSON object containing pet information
content:
application/json:
schema:
oneOf:
- $ref: '#/components/schemas/Cat'
- $ref: '#/components/schemas/Dog'
discriminator:
propertyName: type
responses:
'201':
description: Created
default:
description: Error
components:
schemas:
Cat:
type: object
required:
- type
- whatever
properties:
type:
type: string
whatever:
type: string
meow:
type: string
Dog:
type: object
required:
- type
- whatever
properties:
type:
type: string
whatever:
type: string
bark:
type: string
When you do the following request:
{ "type": "Cat", "whatever": "Cat" }
I expect that the validator will do only one match because of the discriminator field. It should know it should try to match it to Cat Schema.
But the error i get is :
[ERROR][REQUEST][POST Pets @body] Instance failed to match exactly one schema (matched 2 out of 2)
Pretty much like https://bitbucket.org/atlassian/swagger-request-validator/issues/143/request-reponse-bodies-fail-validation but now with DISCRIMINATOR.
This seems to be a bug and also it could be an optimizing of the validation.
Is duplicate of https://bitbucket.org/atlassian/swagger-request-validator/issues/289/discriminator-does-not-seem-to-be