schema:metaschema

schema:metaschema@0.0.0

version

FieldTypeRequiredDefaultDescription
majorintegerYesThe first segment of the version as written: 1 in 1.2.3
minorintegerNo0The second segment: 2 in 1.2.3, and 0 where the version was written without one
patchintegerNo0The third segment: 3 in 1.2.3, and 0 where the version was written without one
prereleasestringNo""How this version has moved since it was released, with its own leading -, or empty where it has not. -dev marks a schema whose content has changed since the version it declares; a release replaces it with the bumped version and no suffix.

Written as, for example:

typeVariant

One of the types string, typeDefinition.

externalSchemaSpec

FieldTypeRequiredDefaultDescription
idstringNoThe referenced schema document by coordinate, <namespace>:<name>@<version>, resolved against the schema store of the repository holding the referencing document. A coordinate written without a version, or with @latest, floats. An entry locates its document by id or by path, and id is read first.
pathstringNoThe referenced schema document as a file path, relative to the document making the reference, or as a file:// URI. For a reference inside one module; read where the entry states no id.
namestringNoA second name a field may reach this entry by, beside the alias it is keyed under: <name>.<definitionKey> resolves as <alias>.<definitionKey> does
targetstringNoThe Python package whose generated __types__ package holds the referenced classes. Generated code imports them from there, which makes the reference a runtime dependency on that package. Required unless vendor is true.
typeOnlybooleanNofalseWhether the generated import is written under if TYPE_CHECKING:, so the referenced classes serve annotations and are never imported at run time. Accepted only in a definition that declares generics; it still needs a target and cannot be combined with vendor.
vendorbooleanNofalseWhether the referenced definitions, and the definitions those reference in turn, are generated into the referencing package's own __types__ package, so its generated code imports nothing from the package that owns the schema. Needs no target and cannot be combined with typeOnly.

schemaMetadata

FieldTypeRequiredDefaultDescription
schemaVersionversionYesThe meta-schema version this schema document was written under -- the referencing end, hand-written here alone because this document defines the grant that fills it in everywhere else
namestringNoThe schema's name, the second part of the coordinate <namespace>:<name>@<version> an exported schema is referenced by. A field in the document may also name one of its own definitions as <name>.<definitionKey>.
versionversionYesThe version this schema defines itself at -- the defining end, which every schema has and none may omit. Three segments, so a hotfix to a released schema has one to move; a -dev suffix marks content that has changed since this version was released.
namespacestringNoThe namespace the schema is published under, the first part of the coordinate <namespace>:<name>@<version>. An exported schema needs it, and name, to be resolvable by coordinate.
exportbooleanNofalseWhether the schema is published: true, with a name and a namespace, puts it in a schema store, where another document references it by coordinate through the id of an externalSchemas entry. false keeps it internal to the module that holds it, reachable by path alone.
documentRootslist[string]No[]The definitions in this schema that describe a stored document rather than a component of one. Each named definition is granted a schemaVersion field -- the referencing end -- so a document can say what it was written under without its author declaring the field. A definition left out describes a component, and a component carries no version of its own. A schema that describes no document names none.

typeDefinition

FieldTypeRequiredDefaultDescription
baseenum one of list, dict, union, enumYesWhich structured type this is: a list of item, a dict from key to item, a union of the types in anyOf, or an enum of the strings in enumValues
enumValueslist[string]NoFor base: enum: the string values the field may hold. A set that more than one field holds is declared once instead, as a definition stating enum.
itemtypeVariantNoFor base: list, the type of each element; for base: dict, the type of each value. Absent, elements and values are of any type.
keytypeVariantNoFor base: dict: the type of each key. Absent, keys are strings.
anyOflist[typeVariant]NoFor base: union: the types a value may be. A value is tried against each in the order written.

toStringSpec

FieldTypeRequiredDefaultDescription
labelstringNoThe field whose value heads a rendered node, in place of the type name
childrenstringNoThe list field whose items are rendered as this node's own children, without a heading of their own

shorthandSpec

FieldTypeRequiredDefaultDescription
patternstringYesA regular expression a string must match to be read as a value of the definition. Each named capture group fills the field of that name, so every group names a declared field and there is at least one; a group that matched nothing leaves its field to its default.
formatstringNoA template that renders a value back to its string form on serialization, declared only where the string holds everything the value does. A {field} placeholder names a declared field and may reach into that field's own fields, as {version.major}; a stretch between [ and ] renders only when every placeholder inside it has a value.

genericConfig

FieldTypeRequiredDefaultDescription
optionalbooleanNofalseWhether a field typed by this parameter may hold no value: the generated type variable is bound to a model or None, where otherwise it is bound to a model alone
covariantbooleanNofalseWhether the generated type variable is declared covariant, so the definition parameterized by a subtype is accepted where it is expected parameterized by the base type
contravariantbooleanNofalseWhether the generated type variable is declared contravariant, so the definition parameterized by a base type is accepted where it is expected parameterized by a subtype

fieldSpec

FieldTypeRequiredDefaultDescription
typetypeVariantYesWhat the field holds: a built-in type token, the key of a definition in the same document, an <alias>.<definitionKey> reference through externalSchemas, a type parameter the definition declares in generics, or a structured type stating a base. A field written as a bare string states this and nothing else.
helpstringNoA sentence saying what the field holds or is for. It becomes the description of the generated field, readable at run time, and is published in documentation beside the field's name and type.
formatstringNoA template the field's value is rendered through on serialization, of {field} placeholders naming fields of the definition the field is typed by: {major}.{minor} writes a version as two segments. Accepted only on a field whose type is a reference to a definition.
optionalbooleanNofalseWhether a document may leave the field out. Left out with no default, the field holds no value, except a boolean, which is false.
defaultanyNoThe value the field takes where a document leaves it out. On a field typed by an enum it is one of the enum's values; on a field typed by a model it is that model's shorthand string, or {} for the model built from its own defaults.
aliasstringNoThe key a document writes the field under, where that is not the field's name here, as a key holding a hyphen is not: x-normalize for xNormalize
xNormalizelist[string]NoNormalization rules applied to the field's value when a document is loaded, after any the field's type declares. Each is a built-in rule, a parameterized form such as sort-by:<key>, or local:<rule> for a hook the package owning the schema supplies.
xValidatelist[string]NoValidation rules the field's value must pass when a document is loaded, after any the field's type declares. Each is a built-in rule, a parameterized form such as pattern:<regex>, or local:<rule> for a hook the package owning the schema supplies.

schemaDefinition

FieldTypeRequiredDefaultDescription
namestringYesThe definition's name, which its generated class and module are named from: module-kind generates the class ModuleKind in the module module_kind. It may not contain a period.
fieldsdict[string, fieldSpec]No{}The fields of a model, by field name. Each is a field spec, or a bare type as the short form of a spec stating only type. Not declared beside anyOf or enum.
anyOflist[typeVariant]NoThe types a value of this definition may be, which makes the definition a union: a named type alias with no fields of its own. Not declared beside fields, enum, extends, protocol or generics.
enumlist[string]NoThe values this definition names, declared once so every field holding that set references it rather than spelling the values again
protocolbooleanNofalseWhether a structural interface is generated beside the model, named <Class>Protocol and declaring the same fields, for code that accepts anything of that shape. Only a model may declare it: not a union, an enum or a definition with generics.
extendsstringNoThe definition this model inherits its fields from, by its key in this document or as an <alias>.<definitionKey> reference. An enum cannot be extended, and a union, an enum or a definition with generics cannot extend.
genericsdict[string, genericConfig]No{}The type parameters of a generic definition, by parameter name; a field names one as its type. A name written with no configuration takes every default. A generic definition is generated as a frozen dataclass and not as a validated model, so it declares no anyOf, protocol, extends or shorthand, and its fields declare no alias, x-normalize or x-validate.
shorthandshorthandSpecNoA string form a value of this model may be written in, expanded into its fields when a document is loaded, and optionally the template that renders it back. Needs declared fields and is not supported beside generics.
exampleslist[any]No[]Values of this definition as a document writes them, shown to a reader beside the definition. Worth stating for a definition whose values are written in a form of its own, such as one declaring shorthand; each should load as a value of the definition.
toStringtoStringSpecNoHow a value of this model is rendered as text for a reader: which field heads it, and which list field holds the items rendered as its children
xNormalizelist[string]NoThe normalization rules every field of this type carries, run before the field's own
xValidatelist[string]NoThe validation rules every field of this type carries, run before the field's own

schemaDocument

FieldTypeRequiredDefaultDescription
metadataschemaMetadataYesWhat the document is: the meta-schema version it is written under, the version the schema defines itself at, the name and namespace it is published by, and which of its definitions describe a stored document
externalSchemasdict[string, externalSchemaSpec]No{}The other schema documents this one references, each under an alias. A field names a definition in one by writing <alias>.<definitionKey> as its type.
definitionsdict[string, schemaDefinition]YesThe types the schema declares, by key. A field in the same document names one by its key, and a field in another document names it as <alias>.<definitionKey>.
sourceUristringNoWhere the document was read from, as a file:// URI. Filled in when the document is loaded and never written in one; a reference by relative path resolves against it.
sourcePathanyNoWhere the document was read from, as a file path. Filled in when the document is loaded and never written in one; read where sourceUri is absent.