Skip to main content

definition_reference_schema

Returns a schema that points to a schema stored in "definitions", this is useful for nested recursive models and also when you want to define validators separately from the main schema, e.g.:

```py
from pydantic_core import SchemaValidator, core_schema

schema_definition = core_schema.definition_reference_schema('list-schema')
schema = core_schema.definitions_schema(
schema=schema_definition,
definitions=[
core_schema.list_schema(items_schema=schema_definition, ref='list-schema'),
],
)
v = SchemaValidator(schema)
assert v.validate_python([()]) == [[]]
```
def definition_reference_schema(
schema_ref: string,
ref: string | None = null,
metadata: dict[str, Any] | None = null,
serialization: SerSchema | None = null
) - > DefinitionReferenceSchema

Returns a schema that points to a schema stored in "definitions", this is useful for nested recursive models and also when you want to define validators separately from the main schema.

Parameters

NameTypeDescription
schema_refstringThe identifier of the schema definition to reference within the definitions collection.
ref`stringNone` = null
metadata`dict[str, Any]None` = null
serialization`SerSchemaNone` = null

Returns

TypeDescription
DefinitionReferenceSchemaA schema dictionary of type 'definition-ref' that references a definition by its unique identifier.