Skip to main content

GenerateJsonSchema

A class for generating JSON schemas.

This class generates JSON schemas based on configured parameters. The default schema dialect is https://json-schema.org/draft/2020-12/schema. The class uses by_alias to configure how fields with multiple names are handled and ref_template to format reference names.

Attributes

AttributeTypeDescription
schema_dialectstring = https://json-schema.org/draft/2020-12/schemaThe JSON schema dialect used to generate the schema.
ignored_warning_kindsset[JsonSchemaWarningKind] = {'skipped-choice'}Warnings to ignore when generating the schema, allowing subclasses to control which warnings are emitted.

Constructor

Signature

def GenerateJsonSchema(
by_alias: bool = True,
ref_template: str = DEFAULT_REF_TEMPLATE,
union_format: Literal['any_of', 'primitive_type_array'] = 'any_of'
)

Parameters

NameTypeDescription
by_aliasbool = TrueWhether to use field aliases in the generated schemas.
ref_templatestr = DEFAULT_REF_TEMPLATEThe format string to use when generating reference names.
union_formatLiteral['any_of', 'primitive_type_array'] = 'any_of'The format to use when combining schemas from unions together.

Methods


mode()

@classmethod
def mode() - > JsonSchemaMode

Determines the current JSON schema mode, prioritizing configuration overrides over the internal state.

Returns

TypeDescription
JsonSchemaModeThe active mode, either 'validation' or 'serialization'

build_schema_type_to_method()

@classmethod
def build_schema_type_to_method() - > dict[CoreSchemaOrFieldType, Callable[[CoreSchemaOrField], JsonSchemaValue]]

Builds a dictionary mapping fields to methods for generating JSON schemas.

Returns

TypeDescription
dict[CoreSchemaOrFieldType, Callable[[CoreSchemaOrField], JsonSchemaValue]]A dictionary containing the mapping of CoreSchemaOrFieldType to a handler method.

generate_definitions()

@classmethod
def generate_definitions(
inputs: Sequence[tuple[JsonSchemaKeyT, JsonSchemaMode, core_schema.CoreSchema]]
) - > tuple[dict[tuple[JsonSchemaKeyT, JsonSchemaMode], JsonSchemaValue], dict[DefsRef, JsonSchemaValue]]

Generates JSON schema definitions from a list of core schemas, pairing the generated definitions with a mapping that links the input keys to the definition references.

Parameters

NameTypeDescription
inputsSequence[tuple[JsonSchemaKeyT, JsonSchemaMode, core_schema.CoreSchema]]A sequence of tuples containing the key, mode, and core schema to process

Returns

TypeDescription
tuple[dict[tuple[JsonSchemaKeyT, JsonSchemaMode], JsonSchemaValue], dict[DefsRef, JsonSchemaValue]]A tuple containing the input-to-schema mapping and the final dictionary of definitions.

generate()

@classmethod
def generate(
schema: CoreSchema,
mode: JsonSchemaMode = validation
) - > JsonSchemaValue

Generates a JSON schema for a specified schema in a specified mode.

Parameters

NameTypeDescription
schemaCoreSchemaThe Pydantic core schema to convert
modeJsonSchemaMode = validationThe mode in which to generate the schema

Returns

TypeDescription
JsonSchemaValueA JSON schema representing the specified schema.

generate_inner()

@classmethod
def generate_inner(
schema: CoreSchemaOrField
) - > JsonSchemaValue

Generates a JSON schema for a given core schema.

Parameters

NameTypeDescription
schemaCoreSchemaOrFieldThe given core schema or field to process

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

sort()

@classmethod
def sort(
value: JsonSchemaValue,
parent_key: str | None = null
) - > JsonSchemaValue

Override this method to customize the sorting of the JSON schema (e.g., don't sort at all, sort all keys unconditionally, etc.)

Parameters

NameTypeDescription
valueJsonSchemaValueThe JSON schema dictionary to sort
parent_key`strNone` = null

Returns

TypeDescription
JsonSchemaValueThe sorted JSON schema

invalid_schema()

@classmethod
def invalid_schema(
schema: core_schema.InvalidSchema
) - > JsonSchemaValue

Placeholder - should never be called.

Parameters

NameTypeDescription
schemacore_schema.InvalidSchemaThe invalid core schema

Returns

TypeDescription
JsonSchemaValueNone; raises RuntimeError

any_schema()

@classmethod
def any_schema(
schema: core_schema.AnySchema
) - > JsonSchemaValue

Generates a JSON schema that matches any value.

Parameters

NameTypeDescription
schemacore_schema.AnySchemaThe core schema

Returns

TypeDescription
JsonSchemaValueAn empty dictionary representing an 'any' schema

none_schema()

@classmethod
def none_schema(
schema: core_schema.NoneSchema
) - > JsonSchemaValue

Generates a JSON schema that matches None.

Parameters

NameTypeDescription
schemacore_schema.NoneSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type set to 'null'

bool_schema()

@classmethod
def bool_schema(
schema: core_schema.BoolSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a bool value.

Parameters

NameTypeDescription
schemacore_schema.BoolSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type set to 'boolean'

int_schema()

@classmethod
def int_schema(
schema: core_schema.IntSchema
) - > JsonSchemaValue

Generates a JSON schema that matches an int value.

Parameters

NameTypeDescription
schemacore_schema.IntSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type 'integer' and applicable numeric validations

float_schema()

@classmethod
def float_schema(
schema: core_schema.FloatSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a float value.

Parameters

NameTypeDescription
schemacore_schema.FloatSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type 'number' and applicable numeric validations

decimal_schema()

@classmethod
def decimal_schema(
schema: core_schema.DecimalSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a decimal value.

Parameters

NameTypeDescription
schemacore_schema.DecimalSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema using regex patterns and numeric constraints to represent decimals

str_schema()

@classmethod
def str_schema(
schema: core_schema.StringSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a string value.

Parameters

NameTypeDescription
schemacore_schema.StringSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type 'string' and applicable string validations

bytes_schema()

@classmethod
def bytes_schema(
schema: core_schema.BytesSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a bytes value.

Parameters

NameTypeDescription
schemacore_schema.BytesSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type 'string' and format 'base64url' or 'binary'

date_schema()

@classmethod
def date_schema(
schema: core_schema.DateSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a date value.

Parameters

NameTypeDescription
schemacore_schema.DateSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type 'string' and format 'date'

time_schema()

@classmethod
def time_schema(
schema: core_schema.TimeSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a time value.

Parameters

NameTypeDescription
schemacore_schema.TimeSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type 'string' and format 'time'

datetime_schema()

@classmethod
def datetime_schema(
schema: core_schema.DatetimeSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a datetime value.

Parameters

NameTypeDescription
schemacore_schema.DatetimeSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type 'string' and format 'date-time'

timedelta_schema()

@classmethod
def timedelta_schema(
schema: core_schema.TimedeltaSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a timedelta value.

Parameters

NameTypeDescription
schemacore_schema.TimedeltaSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type 'number' or 'string' depending on configuration

literal_schema()

@classmethod
def literal_schema(
schema: core_schema.LiteralSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a literal value.

Parameters

NameTypeDescription
schemacore_schema.LiteralSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema using 'const' or 'enum' to represent literal values

missing_sentinel_schema()

@classmethod
def missing_sentinel_schema(
schema: core_schema.MissingSentinelSchema
) - > JsonSchemaValue

Generates a JSON schema that matches the MISSING sentinel value.

Parameters

NameTypeDescription
schemacore_schema.MissingSentinelSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueNone; raises PydanticOmit

enum_schema()

@classmethod
def enum_schema(
schema: core_schema.EnumSchema
) - > JsonSchemaValue

Generates a JSON schema that matches an Enum value.

Parameters

NameTypeDescription
schemacore_schema.EnumSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with 'enum' values and metadata derived from the Enum class

is_instance_schema()

@classmethod
def is_instance_schema(
schema: core_schema.IsInstanceSchema
) - > JsonSchemaValue

Handles JSON schema generation for a core schema that checks if a value is an instance of a class.

Parameters

NameTypeDescription
schemacore_schema.IsInstanceSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema or an error

is_subclass_schema()

@classmethod
def is_subclass_schema(
schema: core_schema.IsSubclassSchema
) - > JsonSchemaValue

Handles JSON schema generation for a core schema that checks if a value is a subclass of a class.

Parameters

NameTypeDescription
schemacore_schema.IsSubclassSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueAn empty dictionary for V1 compatibility

callable_schema()

@classmethod
def callable_schema(
schema: core_schema.CallableSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a callable value.

Parameters

NameTypeDescription
schemacore_schema.CallableSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema or an error

list_schema()

@classmethod
def list_schema(
schema: core_schema.ListSchema
) - > JsonSchemaValue

Returns a schema that matches a list schema.

Parameters

NameTypeDescription
schemacore_schema.ListSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type 'array' and defined items

tuple_positional_schema()

@classmethod
def tuple_positional_schema(
schema: core_schema.TupleSchema
) - > JsonSchemaValue

Replaced by tuple_schema.

Parameters

NameTypeDescription
schemacore_schema.TupleSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated tuple schema

tuple_variable_schema()

@classmethod
def tuple_variable_schema(
schema: core_schema.TupleSchema
) - > JsonSchemaValue

Replaced by tuple_schema.

Parameters

NameTypeDescription
schemacore_schema.TupleSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated tuple schema

tuple_schema()

@classmethod
def tuple_schema(
schema: core_schema.TupleSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a tuple schema e.g. tuple[int, str, bool] or tuple[int, ...].

Parameters

NameTypeDescription
schemacore_schema.TupleSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type 'array' using prefixItems or items

set_schema()

@classmethod
def set_schema(
schema: core_schema.SetSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a set schema.

Parameters

NameTypeDescription
schemacore_schema.SetSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type 'array' and uniqueItems set to true

frozenset_schema()

@classmethod
def frozenset_schema(
schema: core_schema.FrozenSetSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a frozenset schema.

Parameters

NameTypeDescription
schemacore_schema.FrozenSetSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type 'array' and uniqueItems set to true

generator_schema()

@classmethod
def generator_schema(
schema: core_schema.GeneratorSchema
) - > JsonSchemaValue

Returns a JSON schema that represents the provided GeneratorSchema.

Parameters

NameTypeDescription
schemacore_schema.GeneratorSchemaThe schema

Returns

TypeDescription
JsonSchemaValueA schema with type 'array' representing the generator's output

dict_schema()

@classmethod
def dict_schema(
schema: core_schema.DictSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a dict schema.

Parameters

NameTypeDescription
schemacore_schema.DictSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type 'object' using additionalProperties or patternProperties

function_before_schema()

@classmethod
def function_before_schema(
schema: core_schema.BeforeValidatorFunctionSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a function-before schema.

Parameters

NameTypeDescription
schemacore_schema.BeforeValidatorFunctionSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe schema for the input or the inner schema

function_after_schema()

@classmethod
def function_after_schema(
schema: core_schema.AfterValidatorFunctionSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a function-after schema.

Parameters

NameTypeDescription
schemacore_schema.AfterValidatorFunctionSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe schema for the inner schema

function_plain_schema()

@classmethod
def function_plain_schema(
schema: core_schema.PlainValidatorFunctionSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a function-plain schema.

Parameters

NameTypeDescription
schemacore_schema.PlainValidatorFunctionSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe schema for the input or an error

function_wrap_schema()

@classmethod
def function_wrap_schema(
schema: core_schema.WrapValidatorFunctionSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a function-wrap schema.

Parameters

NameTypeDescription
schemacore_schema.WrapValidatorFunctionSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe schema for the input or the inner schema

default_schema()

@classmethod
def default_schema(
schema: core_schema.WithDefaultSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema with a default value.

Parameters

NameTypeDescription
schemacore_schema.WithDefaultSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe inner schema updated with a 'default' key

get_default_value()

@classmethod
def get_default_value(
schema: core_schema.WithDefaultSchema
) - > Any

Get the default value to be used when generating a JSON Schema for a core schema with a default.

Parameters

NameTypeDescription
schemacore_schema.WithDefaultSchemaThe 'with-default' core schema.

Returns

TypeDescription
AnyThe default value to use, or NoDefault if no default value is available.

nullable_schema()

@classmethod
def nullable_schema(
schema: core_schema.NullableSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that allows null values.

Parameters

NameTypeDescription
schemacore_schema.NullableSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA union schema including the inner schema and a null schema

union_schema()

@classmethod
def union_schema(
schema: core_schema.UnionSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that allows values matching any of the given schemas.

Parameters

NameTypeDescription
schemacore_schema.UnionSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA union of the generated schemas for each choice

get_union_of_schemas()

@classmethod
def get_union_of_schemas(
schemas: list[JsonSchemaValue]
) - > JsonSchemaValue

Returns the JSON Schema representation for the union of the provided JSON Schemas.

Parameters

NameTypeDescription
schemaslist[JsonSchemaValue]The list of JSON Schemas to be included in the union.

Returns

TypeDescription
JsonSchemaValueThe JSON Schema representing the union of schemas.

tagged_union_schema()

@classmethod
def tagged_union_schema(
schema: core_schema.TaggedUnionSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that allows values matching any of the given schemas, where the schemas are tagged with a discriminator field that indicates which schema should be used to validate the value.

Parameters

NameTypeDescription
schemacore_schema.TaggedUnionSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema using 'oneOf' and an optional 'discriminator' object

chain_schema()

@classmethod
def chain_schema(
schema: core_schema.ChainSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a core_schema.ChainSchema.

Parameters

NameTypeDescription
schemacore_schema.ChainSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe schema for the first step (validation) or last step (serialization)

lax_or_strict_schema()

@classmethod
def lax_or_strict_schema(
schema: core_schema.LaxOrStrictSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that allows values matching either the lax schema or the strict schema.

Parameters

NameTypeDescription
schemacore_schema.LaxOrStrictSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe schema for either the strict or lax branch based on configuration

json_or_python_schema()

@classmethod
def json_or_python_schema(
schema: core_schema.JsonOrPythonSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that allows values matching either the JSON schema or the Python schema.

Parameters

NameTypeDescription
schemacore_schema.JsonOrPythonSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

typed_dict_schema()

@classmethod
def typed_dict_schema(
schema: core_schema.TypedDictSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a typed dict.

Parameters

NameTypeDescription
schemacore_schema.TypedDictSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueA schema with type 'object' and defined properties for the typed dict

typed_dict_field_schema()

@classmethod
def typed_dict_field_schema(
schema: core_schema.TypedDictField
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a typed dict field.

Parameters

NameTypeDescription
schemacore_schema.TypedDictFieldThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

dataclass_field_schema()

@classmethod
def dataclass_field_schema(
schema: core_schema.DataclassField
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a dataclass field.

Parameters

NameTypeDescription
schemacore_schema.DataclassFieldThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

model_field_schema()

@classmethod
def model_field_schema(
schema: core_schema.ModelField
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a model field.

Parameters

NameTypeDescription
schemacore_schema.ModelFieldThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

computed_field_schema()

@classmethod
def computed_field_schema(
schema: core_schema.ComputedField
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a computed field.

Parameters

NameTypeDescription
schemacore_schema.ComputedFieldThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

model_schema()

@classmethod
def model_schema(
schema: core_schema.ModelSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a model.

Parameters

NameTypeDescription
schemacore_schema.ModelSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

resolve_ref_schema()

@classmethod
def resolve_ref_schema(
json_schema: JsonSchemaValue
) - > JsonSchemaValue

Resolve a JsonSchemaValue to the non-ref schema if it is a $ref schema.

Parameters

NameTypeDescription
json_schemaJsonSchemaValueThe schema to resolve.

Returns

TypeDescription
JsonSchemaValueThe resolved schema.

model_fields_schema()

@classmethod
def model_fields_schema(
schema: core_schema.ModelFieldsSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a model's fields.

Parameters

NameTypeDescription
schemacore_schema.ModelFieldsSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

field_is_present()

@classmethod
def field_is_present(
field: CoreSchemaField
) - > bool

Whether the field should be included in the generated JSON schema.

Parameters

NameTypeDescription
fieldCoreSchemaFieldThe schema for the field itself.

Returns

TypeDescription
boolTrue if the field should be included in the generated JSON schema, False otherwise.

field_is_required()

@classmethod
def field_is_required(
field: core_schema.ModelField | core_schema.DataclassField | core_schema.TypedDictField,
total: bool
) - > bool

Whether the field should be marked as required in the generated JSON schema.

Parameters

NameTypeDescription
field`core_schema.ModelFieldcore_schema.DataclassField
totalboolIndicates if the TypedDict this field belongs to is total

Returns

TypeDescription
boolTrue if the field should be marked as required in the generated JSON schema, False otherwise.

dataclass_args_schema()

@classmethod
def dataclass_args_schema(
schema: core_schema.DataclassArgsSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a dataclass's constructor arguments.

Parameters

NameTypeDescription
schemacore_schema.DataclassArgsSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

dataclass_schema()

@classmethod
def dataclass_schema(
schema: core_schema.DataclassSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a dataclass.

Parameters

NameTypeDescription
schemacore_schema.DataclassSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

arguments_schema()

@classmethod
def arguments_schema(
schema: core_schema.ArgumentsSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a function's arguments.

Parameters

NameTypeDescription
schemacore_schema.ArgumentsSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

kw_arguments_schema()

@classmethod
def kw_arguments_schema(
arguments: list[core_schema.ArgumentsParameter],
var_kwargs_schema: CoreSchema | None
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a function's keyword arguments.

Parameters

NameTypeDescription
argumentslist[core_schema.ArgumentsParameter]The core schema parameters
var_kwargs_schema`CoreSchemaNone`

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

p_arguments_schema()

@classmethod
def p_arguments_schema(
arguments: list[core_schema.ArgumentsParameter],
var_args_schema: CoreSchema | None
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a function's positional arguments.

Parameters

NameTypeDescription
argumentslist[core_schema.ArgumentsParameter]The core schema parameters
var_args_schema`CoreSchemaNone`

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

get_argument_name()

@classmethod
def get_argument_name(
argument: core_schema.ArgumentsParameter | core_schema.ArgumentsV3Parameter
) - > str

Retrieves the name of an argument.

Parameters

NameTypeDescription
argument`core_schema.ArgumentsParametercore_schema.ArgumentsV3Parameter`

Returns

TypeDescription
strThe name of the argument.

arguments_v3_schema()

@classmethod
def arguments_v3_schema(
schema: core_schema.ArgumentsV3Schema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a function's arguments.

Parameters

NameTypeDescription
schemacore_schema.ArgumentsV3SchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

call_schema()

@classmethod
def call_schema(
schema: core_schema.CallSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a function call.

Parameters

NameTypeDescription
schemacore_schema.CallSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

custom_error_schema()

@classmethod
def custom_error_schema(
schema: core_schema.CustomErrorSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a custom error.

Parameters

NameTypeDescription
schemacore_schema.CustomErrorSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

json_schema()

@classmethod
def json_schema(
schema: core_schema.JsonSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a JSON object.

Parameters

NameTypeDescription
schemacore_schema.JsonSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

url_schema()

@classmethod
def url_schema(
schema: core_schema.UrlSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a URL.

Parameters

NameTypeDescription
schemacore_schema.UrlSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

multi_host_url_schema()

@classmethod
def multi_host_url_schema(
schema: core_schema.MultiHostUrlSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a URL that can be used with multiple hosts.

Parameters

NameTypeDescription
schemacore_schema.MultiHostUrlSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

uuid_schema()

@classmethod
def uuid_schema(
schema: core_schema.UuidSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a UUID.

Parameters

NameTypeDescription
schemacore_schema.UuidSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

definitions_schema()

@classmethod
def definitions_schema(
schema: core_schema.DefinitionsSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that defines a JSON object with definitions.

Parameters

NameTypeDescription
schemacore_schema.DefinitionsSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

definition_ref_schema()

@classmethod
def definition_ref_schema(
schema: core_schema.DefinitionReferenceSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a schema that references a definition.

Parameters

NameTypeDescription
schemacore_schema.DefinitionReferenceSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

ser_schema()

@classmethod
def ser_schema(
schema: core_schema.SerSchema | core_schema.IncExSeqSerSchema | core_schema.IncExDictSerSchema
) - > JsonSchemaValue | None

Generates a JSON schema that matches a schema that defines a serialized object.

Parameters

NameTypeDescription
schema`core_schema.SerSchemacore_schema.IncExSeqSerSchema

Returns

TypeDescription
`JsonSchemaValueNone`

complex_schema()

@classmethod
def complex_schema(
schema: core_schema.ComplexSchema
) - > JsonSchemaValue

Generates a JSON schema that matches a complex number.

Parameters

NameTypeDescription
schemacore_schema.ComplexSchemaThe core schema

Returns

TypeDescription
JsonSchemaValueThe generated JSON schema.

get_title_from_name()

@classmethod
def get_title_from_name(
name: str
) - > str

Retrieves a title from a name.

Parameters

NameTypeDescription
namestrThe name to retrieve a title from.

Returns

TypeDescription
strThe title.

field_title_should_be_set()

@classmethod
def field_title_should_be_set(
schema: CoreSchemaOrField
) - > bool

Returns true if a field with the given schema should have a title set based on the field name.

Parameters

NameTypeDescription
schemaCoreSchemaOrFieldThe schema to check.

Returns

TypeDescription
boolTrue if the field should have a title set, False otherwise.

normalize_name()

@classmethod
def normalize_name(
name: str
) - > str

Normalizes a name to be used as a key in a dictionary.

Parameters

NameTypeDescription
namestrThe name to normalize.

Returns

TypeDescription
strThe normalized name.

get_defs_ref()

@classmethod
def get_defs_ref(
core_mode_ref: CoreModeRef
) - > DefsRef

Override this method to change the way that definitions keys are generated from a core reference.

Parameters

NameTypeDescription
core_mode_refCoreModeRefThe core reference.

Returns

TypeDescription
DefsRefThe definitions key.

get_cache_defs_ref_schema()

@classmethod
def get_cache_defs_ref_schema(
core_ref: CoreRef
) - > tuple[DefsRef, JsonSchemaValue]

This method wraps the get_defs_ref method with some cache-lookup/population logic, and returns both the produced defs_ref and the JSON schema that will refer to the right definition.

Parameters

NameTypeDescription
core_refCoreRefThe core reference to get the definitions reference for.

Returns

TypeDescription
tuple[DefsRef, JsonSchemaValue]A tuple of the definitions reference and the JSON schema that will refer to it.

handle_ref_overrides()

@classmethod
def handle_ref_overrides(
json_schema: JsonSchemaValue
) - > JsonSchemaValue

Remove any sibling keys that are redundant with the referenced schema.

Parameters

NameTypeDescription
json_schemaJsonSchemaValueThe schema to remove redundant sibling keys from.

Returns

TypeDescription
JsonSchemaValueThe schema with redundant sibling keys removed.

get_schema_from_definitions()

@classmethod
def get_schema_from_definitions(
json_ref: JsonRef
) - > JsonSchemaValue | None

Retrieves the JSON schema associated with a specific reference from the internal definitions dictionary.

Parameters

NameTypeDescription
json_refJsonRefThe JSON reference key to look up

Returns

TypeDescription
`JsonSchemaValueNone`

encode_default()

@classmethod
def encode_default(
dft: Any
) - > Any

Encode a default value to a JSON-serializable value.

Parameters

NameTypeDescription
dftAnyThe default value to encode.

Returns

TypeDescription
AnyThe encoded default value.

update_with_validations()

@classmethod
def update_with_validations(
json_schema: JsonSchemaValue,
core_schema: CoreSchema,
mapping: dict[str, str]
) - > null

Update the json_schema with the corresponding validations specified in the core_schema, using the provided mapping to translate keys in core_schema to the appropriate keys for a JSON schema.

Parameters

NameTypeDescription
json_schemaJsonSchemaValueThe JSON schema to update.
core_schemaCoreSchemaThe core schema to get the validations from.
mappingdict[str, str]A mapping from core_schema attribute names to the corresponding JSON schema attribute names.

Returns

TypeDescription
nullNone; the schema is updated in place

get_flattened_anyof()

@classmethod
def get_flattened_anyof(
schemas: list[JsonSchemaValue]
) - > JsonSchemaValue

Flattens nested 'anyOf' schemas into a single list and deduplicates them.

Parameters

NameTypeDescription
schemaslist[JsonSchemaValue]The list of schemas to flatten

Returns

TypeDescription
JsonSchemaValueA schema containing the flattened and deduplicated anyOf list

get_json_ref_counts()

@classmethod
def get_json_ref_counts(
json_schema: JsonSchemaValue
) - > dict[JsonRef, int]

Get all values corresponding to the key '$ref' anywhere in the json_schema.

Parameters

NameTypeDescription
json_schemaJsonSchemaValueThe schema to analyze

Returns

TypeDescription
dict[JsonRef, int]A dictionary mapping each JSON reference to its occurrence count

handle_invalid_for_json_schema()

@classmethod
def handle_invalid_for_json_schema(
schema: CoreSchemaOrField,
error_info: str
) - > JsonSchemaValue

Raises a PydanticInvalidForJsonSchema error with details about the unsupported schema type.

Parameters

NameTypeDescription
schemaCoreSchemaOrFieldThe schema that cannot be converted
error_infostrA string describing the error context

Returns

TypeDescription
JsonSchemaValueNone; always raises an exception

emit_warning()

@classmethod
def emit_warning(
kind: JsonSchemaWarningKind,
detail: str
) - > null

This method simply emits PydanticJsonSchemaWarnings based on handling in the warning_message method.

Parameters

NameTypeDescription
kindJsonSchemaWarningKindThe kind of warning to emit
detailstrAdditional details about the warning

Returns

TypeDescription
nullNone

render_warning_message()

@classmethod
def render_warning_message(
kind: JsonSchemaWarningKind,
detail: str
) - > str | None

This method is responsible for ignoring warnings as desired, and for formatting the warning messages.

Parameters

NameTypeDescription
kindJsonSchemaWarningKindThe kind of warning to render.
detailstrA string with additional details about the warning.

Returns

TypeDescription
`strNone`