|
20 | 20 |
|
21 | 21 | from .field_types import ( # noqa: F401 |
22 | 22 | FieldEncoder, DateFieldEncoder, DateTimeFieldEncoder, UuidField, DecimalField, |
23 | | - IPv4AddressField, IPv6AddressField, DateTimeField, UUID_REGEX |
| 23 | + IPv4AddressField, IPv6AddressField, DateTimeField |
24 | 24 | ) |
25 | 25 | from .type_defs import JsonDict, SchemaType, JsonSchemaMeta, _NULL_TYPE, NULL # noqa: F401 |
26 | 26 | from .type_hints import get_class_type_hints |
@@ -474,8 +474,14 @@ def _validate(cls, data: JsonDict, validate_enums: bool = True): |
474 | 474 | # TODO: Support validating with other schema types |
475 | 475 | schema_validator = cls.__compiled_schema.get(SchemaOptions(DEFAULT_SCHEMA_TYPE, validate_enums)) |
476 | 476 | if schema_validator is None: |
| 477 | + formats = {} |
| 478 | + for encoder in cls._field_encoders.values(): |
| 479 | + schema = encoder.json_schema |
| 480 | + if 'pattern' in schema and 'format' in schema: |
| 481 | + formats[schema['format']] = schema['pattern'] |
| 482 | + |
477 | 483 | schema_validator = fastjsonschema.compile( |
478 | | - cls.json_schema(validate_enums=validate_enums), formats={'uuid': UUID_REGEX} |
| 484 | + cls.json_schema(validate_enums=validate_enums), formats=formats |
479 | 485 | ) |
480 | 486 | cls.__compiled_schema[SchemaOptions(DEFAULT_SCHEMA_TYPE, validate_enums)] = schema_validator |
481 | 487 | schema_validator(data) |
|
0 commit comments