Custom validate function which supports default arguments combined with the "required" property. Note: This function returns cleaned instance with default values assigned. :param use_default: True to support the use of the optional "default" property. :type use_default: ``bool
(
instance,
schema,
cls=None,
use_default=True,
allow_default_none=False,
*args,
**kwargs,
)
| 401 | |
| 402 | |
| 403 | def validate( |
| 404 | instance, |
| 405 | schema, |
| 406 | cls=None, |
| 407 | use_default=True, |
| 408 | allow_default_none=False, |
| 409 | *args, |
| 410 | **kwargs, |
| 411 | ): |
| 412 | """ |
| 413 | Custom validate function which supports default arguments combined with the "required" |
| 414 | property. |
| 415 | |
| 416 | Note: This function returns cleaned instance with default values assigned. |
| 417 | |
| 418 | :param use_default: True to support the use of the optional "default" property. |
| 419 | :type use_default: ``bool`` |
| 420 | """ |
| 421 | instance = fast_deepcopy_dict(instance) |
| 422 | schema_type = schema.get("type", None) |
| 423 | instance_is_dict = isinstance(instance, dict) |
| 424 | |
| 425 | if use_default and allow_default_none: |
| 426 | schema = modify_schema_allow_default_none(schema=schema) |
| 427 | |
| 428 | # TODO: expand default handling to more than just objects |
| 429 | if use_default and schema_type == "object" and instance_is_dict: |
| 430 | instance = assign_default_values(instance=instance, schema=schema) |
| 431 | |
| 432 | # pylint: disable=assignment-from-no-return |
| 433 | jsonschema.validate(instance=instance, schema=schema, cls=cls, *args, **kwargs) |
| 434 | |
| 435 | return instance |
| 436 | |
| 437 | |
| 438 | VALIDATORS = {"draft4": jsonschema.Draft4Validator, "custom": CustomValidator} |
nothing calls this directly
no test coverage detected