You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Polymorphic models are not being validated correctly. For example Cat and Dog are having an allOf relationship with Animal which has a discriminator property named dtype, then at runtime the request body or the response body could be an Animal or a Cat or a Dog. If the model specified was a Cat then sway would not fail if some required properties of Cat were not provided.
A possible solution
I added"additionalProperties": false on all the models that do not have any additionalProperties set. This makes their json schema stricter. Now if any unknown property is given the validator will fail. On top of that I have changed all the references to polymorphic models to be a oneOf the parent model or it's children. That is wherever Animal is being referenced "$ref": "#/definitions/Animal", I updated that reference to be a oneOf reference
Thus when the modified swagger is given to z-schema validator (package on which sway depends for model validation), it does a crisp job of validating polymorphic model types.
It would be nice to have a config that in sway that customers can set to make model validation stricter.
The text was updated successfully, but these errors were encountered:
Problem
Polymorphic models are not being validated correctly. For example
Cat
andDog
are having anallOf
relationship withAnimal
which has a discriminator property nameddtype
, then at runtime the request body or the response body could be anAnimal
or aCat
or aDog
. If the model specified was aCat
then sway would not fail if some required properties ofCat
were not provided.A possible solution
I added
"additionalProperties": false
on all the models that do not have any additionalProperties set. This makes their json schema stricter. Now if any unknown property is given the validator will fail. On top of that I have changed all the references to polymorphic models to be aoneOf
theparent
model orit's children
. That is whereverAnimal
is being referenced"$ref": "#/definitions/Animal"
, I updated that reference to be aoneOf
referenceThus when the modified swagger is given to
z-schema
validator (package on whichsway
depends for model validation), it does a crisp job of validating polymorphic model types.The text was updated successfully, but these errors were encountered: