dataclass_field
Returns a schema for a dataclass field, e.g.:
from pydantic_core import SchemaValidator, core_schema
field = core_schema.dataclass_field(
name='a', schema=core_schema.str_schema(), kw_only=False
)
schema = core_schema.dataclass_args_schema('Foobar', [field])
v = SchemaValidator(schema)
assert v.validate_python({'a': 'hello'}) == ({'a': 'hello'}, None)
def dataclass_field(
name: str,
schema: CoreSchema,
kw_only: bool | None = None,
init: bool | None = None,
init_only: bool | None = None,
validation_alias: str | list[str | int] | list[list[str | int]] | None = None,
serialization_alias: str | None = None,
serialization_exclude: bool | None = None,
metadata: dict[str, Any] | None = None,
serialization_exclude_if: Callable[[Any], bool] | None = None,
frozen: bool | None = None
) - > DataclassField
Returns a schema for a dataclass field
Parameters
| Name | Type | Description |
|---|---|---|
| name | str | The name to use for the argument parameter |
| schema | CoreSchema | The schema to use for the argument parameter |
| kw_only | `bool | None` = None |
| init | `bool | None` = None |
| init_only | `bool | None` = None |
| validation_alias | `str | list[str |
| serialization_alias | `str | None` = None |
| serialization_exclude | `bool | None` = None |
| metadata | `dict[str, Any] | None` = None |
| serialization_exclude_if | `Callable[[Any], bool] | None` = None |
| frozen | `bool | None` = None |
Returns
| Type | Description |
|---|---|
DataclassField | A dictionary representing the schema configuration for a single dataclass field |