anyconfig.schema

anyconfig.schema module.

New in version 0.0.11: Added new API gen_schema() to generate schema object

New in version 0.0.10: Added new API validate() to validate config with JSON schema

anyconfig.schema.validate(obj, schema, format_checker=None, safe=True)

Validate target object with given schema object, loaded from JSON schema.

See also: https://python-jsonschema.readthedocs.org/en/latest/validate/

Parae obj:

Target object (a dict or a dict-like object) to validate

Parameters:
  • schema – Schema object (a dict or a dict-like object) instantiated from schema JSON file or schema JSON string
  • format_checker – A format property checker object of which class is inherited from jsonschema.FormatChecker, it’s default if None given.
  • safe – Exception (jsonschema.ValidationError or jsonschema.SchemaError) will be thrown if it’s True and any validation error occurs.
Returns:

(True if validation succeeded else False, error message)

anyconfig.schema.array_to_schema_node(arr, typemap=None)

Generate a node represents JSON schema object with type annotation added for given object node.

Parameters:
  • arr – Array of dict or MergeableDict objects
  • typemap – Type to JSON schema type mappings
Returns:

Another MergeableDict instance represents JSON schema of items

anyconfig.schema.object_to_schema_nodes_iter(obj, typemap=None)

Generate a node represents JSON schema object with type annotation added for given object node.

Parameters:
  • obj – Dict or MergeableDict object
  • typemap – Type to JSON schema type mappings
Yield:

Another MergeableDict instance represents JSON schema of object

anyconfig.schema.gen_schema(node, typemap=None)

Generate a node represents JSON schema object with type annotation added for given object node.

Parameters:
  • node – Object node :: MergeableDict
  • typemap – Type to JSON schema type mappings
Returns:

Another MergeableDict instance represents JSON schema of this node

Previous topic

anyconfig.mergeabledict

Next topic

Philosophy and design principles of anyconfig

This Page