Skip to main content

schema_of

Generate a JSON schema (as dict) for the passed model or dynamically generated one.

def schema_of(
type_: Any,
title: NameFactory | None = None,
by_alias: bool = True,
ref_template: str = DEFAULT_REF_TEMPLATE,
schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema
) - > dict[str, Any]

Generate a JSON schema (as dict) for the passed model or dynamically generated one.

Parameters

NameTypeDescription
type_AnyThe Pydantic model or Python type for which the JSON schema is generated.
title`NameFactoryNone` = None
by_aliasbool = TrueWhether to use field aliases as keys in the generated JSON schema.
ref_templatestr = DEFAULT_REF_TEMPLATEThe format string used for generating internal JSON schema references.
schema_generatortype[GenerateJsonSchema] = GenerateJsonSchemaThe class used to customize the logic for generating the JSON schema.

Returns

TypeDescription
dict[str, Any]A dictionary representing the JSON schema of the provided type.