domain.validators.registry¶
src.domain.validators.registry
¶
Validation Rules Registry (F8.4).
Single source of truth for all validation rules with self-enforcing compliance tests.
This registry follows the same architectural pattern as: - F7.7: Domain Events Registry (metadata-driven, auto-wiring) - F8.1: Provider Registry (single source of truth, 100% coverage) - F8.3: Rate Limit Registry Compliance (self-enforcing validation)
Pattern: Registry Pattern with metadata catalog and helper functions.
Reference
- docs/architecture/validation-registry-architecture.md
- docs/architecture/registry-pattern-architecture.md
Classes¶
ValidationCategory
¶
Bases: str, Enum
Categories for validation rules.
Used to group validators by their domain purpose.
Source code in src/domain/validators/registry.py
ValidationRuleMetadata
dataclass
¶
Metadata for a single validation rule.
Contains all information needed to use a validator: function, constraints, documentation, and examples.
Attributes:
| Name | Type | Description |
|---|---|---|
rule_name |
str
|
Unique identifier for the rule (e.g., 'email', 'password'). |
validator_function |
Callable[[str], str]
|
Callable that validates input and returns validated value. |
field_constraints |
dict[str, int | str]
|
Pydantic Field constraints (min_length, max_length, pattern). |
description |
str
|
Human-readable description of validation requirements. |
examples |
list[str]
|
List of valid example values. |
category |
ValidationCategory
|
Category for grouping (AUTHENTICATION, API_PARAMETERS, etc.). |
Example
metadata = ValidationRuleMetadata( ... rule_name="email", ... validator_function=validate_email, ... field_constraints={"min_length": 5, "max_length": 255}, ... description="Email address with format validation", ... examples=["user@example.com"], ... category=ValidationCategory.AUTHENTICATION, ... )
Source code in src/domain/validators/registry.py
Functions¶
get_validation_rule
¶
Get validation rule metadata by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rule_name
|
str
|
Name of the validation rule (e.g., 'email', 'password'). |
required |
Returns:
| Type | Description |
|---|---|
ValidationRuleMetadata | None
|
ValidationRuleMetadata if found, None otherwise. |
Example
rule = get_validation_rule("email") if rule: ... validated = rule.validator_function("user@example.com")
Source code in src/domain/validators/registry.py
get_all_validation_rules
¶
Get all validation rules in the registry.
Returns:
| Type | Description |
|---|---|
list[ValidationRuleMetadata]
|
List of all ValidationRuleMetadata objects. |
Example
all_rules = get_all_validation_rules() print(f"Total rules: {len(all_rules)}")
Source code in src/domain/validators/registry.py
get_rules_by_category
¶
Get all validation rules in a specific category.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
category
|
ValidationCategory
|
Category to filter by (AUTHENTICATION, API_PARAMETERS, etc.). |
required |
Returns:
| Type | Description |
|---|---|
list[ValidationRuleMetadata]
|
List of ValidationRuleMetadata objects in the category. |
Example
auth_rules = get_rules_by_category(ValidationCategory.AUTHENTICATION) print(f"Auth rules: {len(auth_rules)}")
Source code in src/domain/validators/registry.py
get_statistics
¶
Get registry statistics.
Returns:
| Type | Description |
|---|---|
dict[str, int | dict[str, int]]
|
Dictionary with: |
dict[str, int | dict[str, int]]
|
|
dict[str, int | dict[str, int]]
|
|
Example
stats = get_statistics() print(f"Total: {stats['total_rules']}") print(f"Auth: {stats['by_category'][
'authentication']}")