ModelFieldsValidator
This class validates input data against a defined set of model fields, managing field mapping, strictness settings, and attribute-based loading. It handles complex lookup logic for field aliases and names while providing configurable behavior for extra fields through dedicated sub-validators.
Attributes
| Attribute | Type | Description |
|---|---|---|
| fields | Vec< Field > | A collection of Field objects representing the schema and validation rules for each individual model attribute. |
| model_name | String | The identifier string for the model used primarily for error reporting and internal metadata tracking. |
| extra_behavior | [ExtraBehavior](../../../build/tools/extrabehavior.md?sid=build_tools_extrabehavior) | Determines how the validator handles input keys that are not explicitly defined in the fields list, such as allowing, forbidding, or ignoring them. |
| extras_validator | Option< Arc< CombinedValidator > > | An optional validator applied to the values of extra fields when the extra_behavior is set to allow or process them. |
| extras_keys_validator | Option< Arc< CombinedValidator > > | An optional validator used to enforce constraints or types specifically on the keys of any extra fields provided in the input. |
| strict | bool | A boolean flag that, when enabled, enforces rigid type checking and disallows data coercion during the validation process. |
| from_attributes | bool | Indicates whether the validator should attempt to extract data from object attributes in addition to mapping-like structures. |
| loc_by_alias | bool | Controls whether error locations in the validation output are reported using the field's alias rather than its internal attribute name. |
| lookup | [LookupTree](../../shared/lookup/tree/lookuptree.md?sid=validators_shared_lookup_tree_lookuptree) | A specialized data structure used to efficiently map input keys to their corresponding field definitions during validation. |
| validate_by_alias | Option< bool > | An optional override to force or disable the use of field aliases when looking up values in the input data. |
| validate_by_name | Option< bool > | An optional override to force or disable the use of the original field names when looking up values in the input data. |
Constructor
Signature
def ModelFieldsValidator(
fields: Vec< Field >,
model_name: String,
extra_behavior: [ExtraBehavior](../../../build/tools/extrabehavior.md?sid=build_tools_extrabehavior),
extras_validator: Option< Arc< CombinedValidator > >,
extras_keys_validator: Option< Arc< CombinedValidator > >,
strict: bool,
from_attributes: bool,
loc_by_alias: bool,
lookup: [LookupTree](../../shared/lookup/tree/lookuptree.md?sid=validators_shared_lookup_tree_lookuptree),
validate_by_alias: Option< bool >,
validate_by_name: Option< bool >
) - > [ModelFieldsValidator](modelfieldsvalidator.md?sid=validators_model_fields_modelfieldsvalidator)
Parameters
| Name | Type | Description |
|---|---|---|
| fields | Vec< Field > | A vector of field definitions to be validated. |
| model_name | String | The name of the model being validated. |
| extra_behavior | [ExtraBehavior](../../../build/tools/extrabehavior.md?sid=build_tools_extrabehavior) | Determines how extra fields should be handled (e.g., ignore, allow, forbid). |
| extras_validator | Option< Arc< CombinedValidator > > | An optional validator for extra field values. |
| extras_keys_validator | Option< Arc< CombinedValidator > > | An optional validator for extra field keys. |
| strict | bool | Whether to enforce strict validation mode. |
| from_attributes | bool | Whether to allow data extraction from object attributes. |
| loc_by_alias | bool | Whether to use aliases in error locations. |
| lookup | [LookupTree](../../shared/lookup/tree/lookuptree.md?sid=validators_shared_lookup_tree_lookuptree) | A tree structure used for efficient field lookup. |
| validate_by_alias | Option< bool > | Optional override for validating using field aliases. |
| validate_by_name | Option< bool > | Optional override for validating using field names. |