betty.json.schema module

Provide JSON utilities.

class betty.json.schema.ArraySchema[source]

Bases: Schema

A JSON Schema array.

__init__(items_schema: Schema, *, def_name: str | None = None)[source]
class betty.json.schema.Def[source]

Bases: str

The name of a named Betty schema.

Using this instead of str directly allows Betty to bundle schemas together under a project namespace.

See betty.json.schema.Schema.def_name.

static __new__(cls, def_name: str)[source]
class betty.json.schema.FileBasedSchema[source]

Bases: Schema

A JSON Schema that is stored in a file.

async classmethod new_for(file_path: Path, *, name: str | None = None) Self[source]

Create a new instance.

class betty.json.schema.JsonSchemaReference[source]

Bases: Schema

The JSON Schema schema.

__init__()[source]
class betty.json.schema.JsonSchemaSchema[source]

Bases: FileBasedSchema

The JSON Schema Draft 2020-12 schema.

async classmethod new() Self[source]

Create a new instance.

class betty.json.schema.Ref[source]

Bases: Schema

A JSON Schema that references a named Betty schema.

__init__(def_name: str)[source]
class betty.json.schema.Schema[source]

Bases: object

A JSON Schema.

All schemas using this class MUST follow JSON Schema Draft 2020-12.

To test your own subclasses, use betty.test_utils.json.schema.SchemaTestBase.

__init__(*, def_name: str | None = None, schema: MutableMapping[str, bool | int | float | str | None | MutableSequence[bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]] | MutableMapping[str, bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]]] | None = None)[source]
property def_name: str | None

The schema machine name when embedded into another schema’s $defs.

property defs: MutableMapping[str, bool | int | float | str | None | MutableSequence[bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]] | MutableMapping[str, bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]]]

The JSON Schema’s $defs definitions, kept separately, so they can be merged when this schema is embedded.

Only top-level definitions are supported. You MUST NOT nest definitions. Instead, prefix or suffix their names.

embed(into: Schema) bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump][source]

Embed this schema.

property schema: MutableMapping[str, bool | int | float | str | None | MutableSequence[bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]] | MutableMapping[str, bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump]]]

The raw JSON Schema.

validate(data: Any) None[source]

Validate data against this schema.

betty.json.schema.add_property(into: Schema, property_name: str, property_schema: Schema, property_required: bool = True) None[source]

Add a property to an object schema.