MCPcopy Create free account
hub / github.com/StackStorm/st2 / validate

Function validate

st2common/st2common/util/schema/__init__.py:403–435  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

401
402
403def 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
438VALIDATORS = {"draft4": jsonschema.Draft4Validator, "custom": CustomValidator}

Callers

nothing calls this directly

Calls 5

fast_deepcopy_dictFunction · 0.90
assign_default_valuesFunction · 0.85
getMethod · 0.45
validateMethod · 0.45

Tested by

no test coverage detected