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
Want to start by saying thanks for writing and maintaining this package.
I noticed an issue with handling validation errors for values inside a anyOf (and likely oneOf) not being surfaced as expected. If you have any anyOf that further down contains a number field with a minimum set, instead of getting back an error message on the number field when you enter a value below the minimum, you get a generic error saying "Some required fields are missing" above the django field.
I looked into the JSONSchemaValidator and believe I have identified why this is happening. Looking at the implementation of validate_anyOf (this also applies to oneOf equivalent) it is relying on the possible subschemas validate functions to not raise an exception if the schema matches the data. However if you have min/max rules on some fields in the subschema it will raise the same exception making the anyOf check think that the schema isn't a match. Then once it loops through all of the possible subschemas and doesn't find a match it raises the "Some required fields are missing" exception.
In the meantime my workaround is to implement a custom validator to handle these minimum value checks.
The text was updated successfully, but these errors were encountered:
The validator can't know which subschema the user has selected (because that info is UI related and is never transferred to the backend). So we have to loop over all the subschemas to try and find a match for the given data.
Maybe adding support to something similar OpenAPI discriminator could help here. That combined with const and widget: hidden should be enough to help finding which subschema to validate against.
From the spec it only applies to object types. But that covers almost all cases no? From JSON's perspective, subclassing array, integer, boolean, doesn't make much sense, right?
What would be a case to use anyOf and array + another type? Could you please give me an example?
Hi!
Want to start by saying thanks for writing and maintaining this package.
I noticed an issue with handling validation errors for values inside a
anyOf
(and likelyoneOf
) not being surfaced as expected. If you have anyanyOf
that further down contains a number field with a minimum set, instead of getting back an error message on the number field when you enter a value below the minimum, you get a generic error saying "Some required fields are missing" above the django field.An example schema to reproduce this below:
I looked into the
JSONSchemaValidator
and believe I have identified why this is happening. Looking at the implementation ofvalidate_anyOf
(this also applies tooneOf
equivalent) it is relying on the possible subschemas validate functions to not raise an exception if the schema matches the data. However if you have min/max rules on some fields in the subschema it will raise the same exception making theanyOf
check think that the schema isn't a match. Then once it loops through all of the possible subschemas and doesn't find a match it raises the "Some required fields are missing" exception.In the meantime my workaround is to implement a custom validator to handle these minimum value checks.
The text was updated successfully, but these errors were encountered: