betty.json.schema module¶
Provide JSON utilities.
- 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.
- class betty.json.schema.FileBasedSchema[source]¶
Bases:
Schema
A JSON Schema that is stored in a file.
- final class betty.json.schema.JsonSchemaSchema[source]¶
Bases:
FileBasedSchema
The JSON Schema Draft 2020-12 schema.
- class betty.json.schema.Object[source]¶
Bases:
_Type
A JSON Schema
object
type.
- class betty.json.schema.Ref[source]¶
Bases:
Schema
A JSON Schema that references a named Betty schema.
- 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, title: str | None = None, description: str | None = None)[source]¶
- 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) 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]]] [source]¶
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.
- class betty.json.schema.String[source]¶
Bases:
_Type
A JSON Schema
string
type.- class Format[source]¶
Bases:
Enum
A JSON Schema
string
type’sformat
.- 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'¶