model_json_schema
Utility function to generate a JSON Schema for a model.
def model_json_schema(
cls: type[BaseModel] | type[PydanticDataclass],
by_alias: bool = True,
ref_template: str = DEFAULT_REF_TEMPLATE,
union_format: Literal['any_of', 'primitive_type_array'] = 'any_of',
schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema,
mode: JsonSchemaMode = 'validation'
) - > dict[str, Any]
Utility function to generate a JSON Schema for a model.
Parameters
| Name | Type | Description |
|---|---|---|
| cls | `type[BaseModel] | type[PydanticDataclass]` |
| by_alias | bool = True | If True (the default), fields will be serialized according to their alias. If False, fields will be serialized according to their attribute name. |
| ref_template | str = DEFAULT_REF_TEMPLATE | The template to use for generating JSON Schema references. |
| union_format | Literal['any_of', 'primitive_type_array'] = 'any_of' | The format to use when combining schemas from unions together; either 'any_of' for standard keyword combination or 'primitive_type_array' for a type array fallback. |
| schema_generator | type[GenerateJsonSchema] = GenerateJsonSchema | The class to use for generating the JSON Schema. |
| mode | JsonSchemaMode = 'validation' | The mode to use for generating the JSON Schema, determining if the schema is tailored for validation or serialization. |
Returns
| Type | Description |
|---|---|
dict[str, Any] | The generated JSON Schema. |