base_schema

Schema

class wysdom.Schema

Bases: abc.ABC

Abstract base class for JSON schemas. Objects of type Schema can be used to generate jsonschema-compatible dictionaries, and to validate potential input data against those schemas.

Objects of type Schema are also callable, and when called will create DOM objects or primitive Python object containing the data that is supplied to them.

is_valid(value: Any)bool

Determine whether a given object conforms to this schema.

Parameters

value – An object to test for validity against this schema

Returns

True if the object is valid, otherwise False

abstract property jsonschema_definition

The underlying jsonschema-compatible schema definition for this schema.

Returns

A jsonschema-compatible dictionary.

property jsonschema_full_schema

The jsonschema definition to use when using this schema as a standalone schema.

Returns

A jsonschema-compatible dictionary.

property jsonschema_ref_schema

The jsonschema definition to use when referring to this schema in another schema. If schema_ref_name is defined, this will be a reference using the “$ref” keyword. If schema_ref_name is None, the raw definition of the schema will be used.

Returns

A jsonschema-compatible dictionary.

property referenced_schemas

A dict of named schemas (i.e. schemas with a defined schema_ref_name) that are referenced in this schema, including itself if applicable.

Returns

A dict of Schema objects indexed by their schema_ref_name.

property schema_ref_name

A unique reference name to use when this schema is referred to by other schemas. If this returns a string, references to this schema will use the $ref keyword without replicating the full schema. If this property returns None, the full contents of the schema will be used.

Returns

A string with a unique reference name if defined, else None.

validate(value: Any)None

Determine whether a given object conforms to this schema, and throw an error if not.

Parameters

value – An object to test for validity against this schema

SchemaAnything

class wysdom.SchemaAnything

Bases: wysdom.base_schema.Schema.Schema

A schema where any valid JSON will be accepted.

property jsonschema_definition

The underlying jsonschema-compatible schema definition for this schema.

Returns

A jsonschema-compatible dictionary.

SchemaConst

class wysdom.SchemaConst(value: str)

Bases: wysdom.base_schema.Schema.Schema

A schema requiring a string constant.

property jsonschema_definition

The underlying jsonschema-compatible schema definition for this schema.

Returns

A jsonschema-compatible dictionary.

value: str = None

SchemaEnum

SchemaNone

class wysdom.SchemaNone

Bases: wysdom.base_schema.SchemaType.SchemaType

A schema requiring a null value.

type_name: str = 'null'

SchemaPattern

SchemaPrimitive

class wysdom.SchemaPrimitive(python_type: Optional[Type] = None)

Bases: wysdom.base_schema.SchemaType.SchemaType

A schema requiring a primitive variable type

Parameters

python_type – The primitive Python type expected by this schema

JSON_TYPES: Dict[Type, str] = {<class 'str'>: 'string', <class 'bool'>: 'boolean', <class 'int'>: 'integer', <class 'float'>: 'number'}
python_type: Type = None
property type_name
Returns

Value for the JSON schema “type” keyword

SchemaType

class wysdom.SchemaType

Bases: wysdom.base_schema.Schema.Schema, abc.ABC

Abstract base class for any schema with the “type” keyword

property jsonschema_definition

The underlying jsonschema-compatible schema definition for this schema.

Returns

A jsonschema-compatible dictionary.

abstract property type_name
Returns

Value for the JSON schema “type” keyword