dataclass_schema
Returns a schema for a dataclass. As with ModelSchema, this schema can only be used as a field within
another schema, not as the root type.
def dataclass_schema(
cls: type[Any],
schema: CoreSchema,
fields: list[str],
generic_origin: type[Any] | None = None,
cls_name: str | None = None,
post_init: bool | None = None,
revalidate_instances: Literal['always', 'never', 'subclass-instances'] | None = None,
strict: bool | None = None,
ref: str | None = None,
metadata: dict[str, Any] | None = None,
serialization: SerSchema | None = None,
frozen: bool | None = None,
slots: bool | None = None,
config: CoreConfig | None = None
) - > DataclassSchema
Returns a schema for a dataclass. As with ModelSchema, this schema can only be used as a field within another schema, not as the root type.
Parameters
| Name | Type | Description |
|---|---|---|
| cls | type[Any] | The dataclass type, used to perform subclass checks |
| schema | CoreSchema | The schema to use for the dataclass fields |
| fields | list[str] | Fields of the dataclass, this is used in serialization and in validation during re-validation and while validating assignment |
| generic_origin | `type[Any] | None` = None |
| cls_name | `str | None` = None |
| post_init | `bool | None` = None |
| revalidate_instances | `Literal['always', 'never', 'subclass-instances'] | None` = None |
| strict | `bool | None` = None |
| ref | `str | None` = None |
| metadata | `dict[str, Any] | None` = None |
| serialization | `SerSchema | None` = None |
| frozen | `bool | None` = None |
| slots | `bool | None` = None |
| config | `CoreConfig | None` = None |
Returns
| Type | Description |
|---|---|
DataclassSchema | A dictionary-based schema definition for a dataclass, compatible with pydantic-core validation and serialization. |