anyconfig.schema
¶
anyconfig.schema module.
Changed in version 0.9.4: Change parameter passed to validate()
, s/.*safe/ac_schema_safe/g
Changed in version 0.8.3: Replace format_checker with cls option
Changed in version 0.7.0: allow passing ac_schema_strict to API gen_schema()
to generate more
strict and precise JSON schema object
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
(data, schema, ac_schema_safe=True, ac_schema_errors=False, **options)¶ Validate target object with given schema object, loaded from JSON schema.
See also: https://python-jsonschema.readthedocs.org/en/latest/validate/
Parae data: 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
- options –
Other keyword options such as:
- ac_schema_safe: Exception (jsonschema.ValidationError or jsonschema.SchemaError or others) will be thrown during validation process due to any validation or related errors. However, these will be catched by default, and will be re-raised if ac_safe is False.
- ac_schema_errors: Lazily yield each of the validation errors and returns all of them if validation fails.
Returns: (True if validation succeeded else False, error message[s])
-
anyconfig.schema.
array_to_schema
(arr, **options)¶ Generate a JSON schema object with type annotation added for given object.
Parameters: - arr – Array of dict or MergeableDict objects
- options –
Other keyword options such as:
- ac_schema_strict: True if more strict (precise) schema is needed
- ac_schema_typemap: Type to JSON schema type mappings
Returns: Another MergeableDict instance represents JSON schema of items
-
anyconfig.schema.
object_to_schema
(obj, **options)¶ Generate a node represents JSON schema object with type annotation added for given object node.
Parameters: - obj – Dict or MergeableDict object
- options –
Other keyword options such as:
- ac_schema_strict: True if more strict (precise) schema is needed
- ac_schema_typemap: Type to JSON schema type mappings
Yield: Another MergeableDict instance represents JSON schema of object
-
anyconfig.schema.
gen_schema
(data, **options)¶ Generate a node represents JSON schema object with type annotation added for given object node.
Parameters: - data – Configuration data object (dict[-like] or namedtuple)
- options –
Other keyword options such as:
- ac_schema_strict: True if more strict (precise) schema is needed
- ac_schema_typemap: Type to JSON schema type mappings
Returns: A dict represents JSON schema of this node