Skip to main content

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

AttributeTypeDescription
fieldsVec< Field >A collection of Field objects representing the schema and validation rules for each individual model attribute.
model_nameStringThe 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_validatorOption< 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_validatorOption< Arc< CombinedValidator > >An optional validator used to enforce constraints or types specifically on the keys of any extra fields provided in the input.
strictboolA boolean flag that, when enabled, enforces rigid type checking and disallows data coercion during the validation process.
from_attributesboolIndicates whether the validator should attempt to extract data from object attributes in addition to mapping-like structures.
loc_by_aliasboolControls 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_aliasOption< bool >An optional override to force or disable the use of field aliases when looking up values in the input data.
validate_by_nameOption< 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

NameTypeDescription
fieldsVec< Field >A vector of field definitions to be validated.
model_nameStringThe 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_validatorOption< Arc< CombinedValidator > >An optional validator for extra field values.
extras_keys_validatorOption< Arc< CombinedValidator > >An optional validator for extra field keys.
strictboolWhether to enforce strict validation mode.
from_attributesboolWhether to allow data extraction from object attributes.
loc_by_aliasboolWhether 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_aliasOption< bool >Optional override for validating using field aliases.
validate_by_nameOption< bool >Optional override for validating using field names.