betty.json.schema module - Betty documentation

Hide navigation sidebar
Hide table of contents sidebar
Skip to content
Back to top
View this page
Toggle table of contents sidebar

# betty.json.schema module

Provide JSON utilities.

class betty.json.schema.ArraySchema

  Bases: `Schema`

  A JSON Schema array.

  __init__(items_schema: Schema, *, def_name: str | None = None)

class betty.json.schema.Def

  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)

class betty.json.schema.FileBasedSchema

  Bases: `Schema`

  A JSON Schema that is stored in a file.

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

    Create a new instance.

class betty.json.schema.JsonSchemaReference

  Bases: `Schema`

  The JSON Schema schema.

  __init__()

class betty.json.schema.JsonSchemaSchema

  Bases: `FileBasedSchema`

  The JSON Schema Draft 2020-12 schema.

  async classmethod new() → Self

    Create a new instance.

class betty.json.schema.Ref

  Bases: `Schema`

  A JSON Schema that references a named Betty schema.

  __init__(def_name: str)

class betty.json.schema.Schema

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

    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

    Validate data against this schema.

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

  Add a property to an object schema.