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.AllOf

  Bases: `_Container`

  A JSON Schema `allOf`.

class betty.json.schema.AnyOf

  Bases: `_Container`

  A JSON Schema `anyOf`.

class betty.json.schema.Array

  Bases: `_Type`

  A JSON Schema `array` type.

  __init__(items: Schema, *, def_name: str | None = None, title: str | None = None, description: str | None = None)

class betty.json.schema.Boolean

  Bases: `_Type`

  A JSON Schema `boolean` type.

class betty.json.schema.Const

  Bases: `Schema`

  A JSON Schema `const`.

  __init__(const: bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump], *, def_name: str | None = None, title: str | None = None, description: 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.Enum

  Bases: `Schema`

  A JSON Schema `enum`.

  __init__(*values: bool | int | float | str | None | MutableSequence[Dump] | MutableMapping[str, Dump], def_name: str | None = None, title: str | None = None, description: str | None = None)

class betty.json.schema.FileBasedSchema

  Bases: `Schema`

  A JSON Schema that is stored in a file.

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

    Create a new instance.

class betty.json.schema.Integer

  Bases: `_Type`

  A JSON Schema `integer` type.

class betty.json.schema.JsonSchemaReference

  Bases: `String`

  The JSON Schema schema.

  __init__()

final 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.Null

  Bases: `_Type`

  A JSON Schema `null` type.

class betty.json.schema.Number

  Bases: `_Type`

  A JSON Schema `number` type.

class betty.json.schema.Object

  Bases: `_Type`

  A JSON Schema `object` type.

  __init__(*, def_name: str | None = None, title: str | None = None, description: str | None = None)
  add_property(property_name: str, property_schema: Schema, property_required: bool = True) → None

    Add a property to the object schema.

class betty.json.schema.OneOf

  Bases: `_Container`

  A JSON Schema `oneOf`.

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, title: str | None = None, description: str | 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.

  property description: str | None

    The schema’s human-readable US English (long) description.

  embed(into: 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]]]

    Embed this schema.

    This is where the raw schema may be enhanced before being returned.

  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.

  property title: str | None

    The schema’s human-readable US English (short) title.

  validate(data: Any) → None

    Validate data against this schema.

class betty.json.schema.String

  Bases: `_Type`

  A JSON Schema `string` type.

  class Format

    Bases: `Enum`

    A JSON Schema `string` type’s `format`.

    DATE = 'date'
    DATE_TIME = 'date-time'
    DURATION = 'duration'
    EMAIL = 'email'
    HOSTNAME = 'hostname'
    IDN_EMAIL = 'idn-email'
    IDN_HOSTNAME = 'idn-hostname'
    IPV4 = 'ipv4'
    IPV6 = 'ipv6'
    IRI = 'iri'
    IRI_REFERENCE = 'iri-reference'
    JSON_POINTER = 'json-pointer'
    REGEX = 'regex'
    RELATIVE_JSON_POINTER = 'relative-json-pointer'
    TIME = 'time'
    URI = 'uri'
    URI_REFERENCE = 'uri-reference'
    URI_TEMPLATE = 'uri-template'
    UUID = 'uuid'
  __init__(*, def_name: str | None = None, title: str | None = None, description: str | None = None, min_length: int | None = None, max_length: int | None = None, pattern: str | None = None, format: Format | None = None)