Discriminator + Mapping not working properly
LasneF opened this issue · comments
When combining Discriminator and mapping , validation looks not working (mapping not taken into account)
Context
given the above API spec defining
Pet (Id , type) and 2 kind of cat both beeing pet
NiceCat (having having miaou field)
hunterCat (having hunter field)
Here is the spec
Notice that the PetResult has a discriminator , if petType match NICE schema have to be niceCatResult , if petType match HUNT schema is hunterCatResult
openapi: 3.1.0
info:
title: Curves
version: "1.0"
paths:
/pet:
get:
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/PetResult'
example:
petType: NICE
miaou: true
components:
schemas:
PetResult:
oneOf:
- $ref: '#/components/schemas/niceCatResult'
- $ref: '#/components/schemas/hunterCatResult'
discriminator:
propertyName: petType
mapping:
NICE: '#/components/schemas/niceCatResult'
HUNT: '#/components/schemas/hunterCatResult'
PetCommon:
type: object
required:
- petType
properties:
petType:
type: string
niceCatResult:
allOf:
- $ref: '#/components/schemas/PetCommon'
- type: object
required:
- miaou
properties:
miaou:
type: boolean
hunterCatResult:
allOf:
- $ref: '#/components/schemas/PetCommon'
- type: object
properties:
hunt:
type: string
Current Behavior
the NiceCat looks mapping hunter cat even if it is set as Nice
[CLI] ► start Prism is listening on http://127.0.0.1:4010
[17:05:38] » [HTTP SERVER] get /pet info Request received
Prism raise
[17:01:24] » [VALIDATOR] × error Violation: response.body Request body must match exactly one schema in oneOf
Looks Prism does not leverage on the petType is set to NICE, and so matching the NICE cat model
Expected Behavior
during payload validation the mapping should be taken into account to pickup the right schema
Possible Workaround/Solution
Not sure it is a bug or a limitation, if it is a limitation , this could be mentionned in the documentation that the mapping keyword has no effect upon validation, and so that models in th oneOf must be imcompatible each others
here nice cat could be also hunter cat .
Steps to Reproduce
take the above Spec,
prism mock spec.yml
curl --location 'http://127.0.0.1:4010/pet'
an error trace occurs
[17:05:38] » [VALIDATOR] × error Violation: response.body Request body must match exactly one schema in oneOf
Notice same appears in proxy validation mode
Environment
Prism 5.2.0
@LasneF Prism does not support discriminators at this time, and there's no plan to support them in the foreseeable future. We will turn this into a documentation task and get this limitation listed in Prism documentation.