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
Our data can be either a string, or an object with property x, which itself can be either a string, or an object with property x1. If x is not provided, the default should be an object, and the default of x1 should be True. The function below creates a schema for this scenario; it also takes an optional schema_url, which if provided, is added as $schema to the subschema where the data is an object:
Now if we create a schema without schema_url, everything works as expected. For example, if we pass an empty dictionary as our data, it successfully validates, x is set to an empty dict, and the default value of x1 is added to it:
Interestingly, if schema_url is set to anything else (either other schema specification URLs or even invalid URLs), again everything works as expected. For example all these work:
forschema_urlin ("https://json-schema.org/draft-07/schema", "NOT A URL"):
data= {}
schema=make_schema(schema_url)
validator(schema).validate(data)
print(data)
The text was updated successfully, but these errors were encountered:
This sounds like the (not yet solved) #994 (which will likely be solved only once we have a new validation API) -- have a look there, and if it seems different let me know.
(PRs to improve the example code are also welcome.)
Using the example in the documentation, extend
Draft202012Validator
to set default values:Our data can be either a string, or an object with property
x
, which itself can be either a string, or an object with propertyx1
. Ifx
is not provided, the default should be an object, and the default ofx1
should beTrue
. The function below creates a schema for this scenario; it also takes an optionalschema_url
, which if provided, is added as$schema
to the subschema where the data is an object:Now if we create a schema without
schema_url
, everything works as expected. For example, if we pass an empty dictionary as our data, it successfully validates,x
is set to an empty dict, and the default value ofx1
is added to it:returns
However, if
schema_url
is set tohttps://json-schema.org/draft/2020-12/schema
, then we get aValidationError
:Interestingly, if
schema_url
is set to anything else (either other schema specification URLs or even invalid URLs), again everything works as expected. For example all these work:The text was updated successfully, but these errors were encountered: