DataclassArgsSchema
This class defines a schema for dataclass arguments within a type-safe dictionary structure. It specifies required properties such as the dataclass name and its associated fields, while providing optional configurations for computed fields, serialization behavior, and metadata. This schema is primarily used to represent the structural and behavioral requirements for validating and serializing dataclass-based data structures.
Attributes
| Attribute | Type | Description |
|---|---|---|
| type | 'dataclass-args' | Fixed identifier string used to distinguish this schema as a dataclass arguments validator. |
| dataclass_name | string | The human-readable name of the dataclass used for error messages and representation. |
| fields | list[[DataclassField](dataclassfield.md?sid=pydantic_core_core_schema_dataclassfield)] | A list of field definitions that determine how input data is validated and mapped to dataclass attributes. |
| computed_fields | list[[ComputedField](../../../../serializers/computed/fields/computedfield.md?sid=serializers_computed_fields_computedfield)] | A list of properties or methods decorated as computed fields to be included in the schema output. |
| collect_init_only | boolean = False | Whether to capture and store arguments that are passed to the constructor but not defined as fields. |
| ref | string | A unique string identifier used for recursive schema references and shared definitions. |
| metadata | dict[str, Any] | A dictionary of custom configuration data used to extend schema behavior or store plugin-specific information. |
| serialization | SerSchema | Custom serialization configuration that defines how the dataclass arguments are converted back to raw data. |
| extra_behavior | [ExtraBehavior](../../../../build/tools/extrabehavior.md?sid=build_tools_extrabehavior) | Configuration setting that determines how the validator handles unexpected fields not defined in the schema. |
Constructor
Signature
def DataclassArgsSchema() - > null
Methods
type()
def type() - > Literal['dataclass-args']
Identifies the schema type as a dataclass argument structure.
Returns
| Type | Description |
|---|---|
Literal['dataclass-args'] | The fixed literal string 'dataclass-args' used for schema identification |
dataclass_name()
def dataclass_name() - > str
Specifies the human-readable name of the dataclass for error reporting and documentation.
Returns
| Type | Description |
|---|---|
str | The name of the dataclass |
fields()
def fields() - > list[[DataclassField](dataclassfield.md?sid=pydantic_core_core_schema_dataclassfield)]
Defines the list of fields that correspond to the dataclass's init parameters.
Returns
| Type | Description |
|---|---|
list[[DataclassField](dataclassfield.md?sid=pydantic_core_core_schema_dataclassfield)] | A list of field definitions used for validation and instantiation |
computed_fields()
def computed_fields() - > list[[ComputedField](../../../../serializers/computed/fields/computedfield.md?sid=serializers_computed_fields_computedfield)]
Lists fields that are calculated from other attributes rather than being supplied during initialization.
Returns
| Type | Description |
|---|---|
list[[ComputedField](../../../../serializers/computed/fields/computedfield.md?sid=serializers_computed_fields_computedfield)] | A list of computed field definitions |
collect_init_only()
def collect_init_only() - > bool
Determines whether to include fields that are only present in the constructor and not stored as attributes.
Returns
| Type | Description |
|---|---|
bool | True if init-only variables should be collected, False otherwise |
ref()
def ref() - > str
Provides a unique identifier for the schema to allow for recursive definitions or shared references.
Returns
| Type | Description |
|---|---|
str | The reference string used for internal schema linking |
metadata()
def metadata() - > dict[str, Any]
Stores an extensible dictionary of custom data associated with the dataclass schema.
Returns
| Type | Description |
|---|---|
dict[str, Any] | A dictionary containing arbitrary metadata |
serialization()
def serialization() - > SerSchema
Configures how the dataclass should be transformed into a serialized format.
Returns
| Type | Description |
|---|---|
SerSchema | The serialization configuration schema |
extra_behavior()
def extra_behavior() - > [ExtraBehavior](../../../../build/tools/extrabehavior.md?sid=build_tools_extrabehavior)
Defines how the validator should handle extra fields that are not explicitly defined in the schema.
Returns
| Type | Description |
|---|---|
[ExtraBehavior](../../../../build/tools/extrabehavior.md?sid=build_tools_extrabehavior) | The behavior setting for handling unexpected input fields |