LaxOrStrictValidator
This class provides a mechanism to toggle between lax and strict validation modes for data processing. It maintains separate internal validators for each mode and applies the appropriate validation logic based on the configured strictness setting.
Attributes
| Attribute | Type | Description |
|---|---|---|
| strict | bool | Determines whether the validator enforces strict validation rules or allows for more flexible, lax data parsing. |
| lax_validator | Arc< CombinedValidator > | The validation logic used when the validator is operating in lax mode, typically allowing for type coercion. |
| strict_validator | Arc< CombinedValidator > | The validation logic used when the validator is operating in strict mode, requiring exact type matches. |
| name | String | The identifier string used to represent the validator in error messages and schema representations. |
Constructor
Signature
def LaxOrStrictValidator(
strict: bool,
lax_validator: Arc< CombinedValidator >,
strict_validator: Arc< CombinedValidator >,
name: String
)
Parameters
| Name | Type | Description |
|---|---|---|
| strict | bool | Determines whether strict validation should be enforced by default. |
| lax_validator | Arc< CombinedValidator > | The validator used for lax validation logic. |
| strict_validator | Arc< CombinedValidator > | The validator used for strict validation logic. |
| name | String | The name identifier for the validator instance. |
Methods
validate()
def validate(
input: Any,
state: [ValidationState](../../../validation/state/validationstate.md?sid=validators_validation_state_validationstate)
) - > ValidationResult
Validates input data using either a lax or strict validation strategy based on the validator's configuration.
Parameters
| Name | Type | Description |
|---|---|---|
| input | Any | The raw input data to be validated against the schema. |
| state | [ValidationState](../../../validation/state/validationstate.md?sid=validators_validation_state_validationstate) | The current validation context and state used to track errors and configuration during the validation process. |
Returns
| Type | Description |
|---|---|
ValidationResult | The result of the validation process, containing either the validated data or error details. |