Apply model validators to a schema. If mode == 'inner', only "before" validators are applied If mode == 'outer', validators other than "before" are applied If mode == 'all', all validators are applied Args: schema: The schema to apply validators on. validators: An i
(
schema: core_schema.CoreSchema,
validators: Iterable[Decorator[ModelValidatorDecoratorInfo]],
mode: Literal['inner', 'outer', 'all'],
)
| 2610 | |
| 2611 | |
| 2612 | def apply_model_validators( |
| 2613 | schema: core_schema.CoreSchema, |
| 2614 | validators: Iterable[Decorator[ModelValidatorDecoratorInfo]], |
| 2615 | mode: Literal['inner', 'outer', 'all'], |
| 2616 | ) -> core_schema.CoreSchema: |
| 2617 | """Apply model validators to a schema. |
| 2618 | |
| 2619 | If mode == 'inner', only "before" validators are applied |
| 2620 | If mode == 'outer', validators other than "before" are applied |
| 2621 | If mode == 'all', all validators are applied |
| 2622 | |
| 2623 | Args: |
| 2624 | schema: The schema to apply validators on. |
| 2625 | validators: An iterable of validators. |
| 2626 | mode: The validator mode. |
| 2627 | |
| 2628 | Returns: |
| 2629 | The updated schema. |
| 2630 | """ |
| 2631 | ref: str | None = schema.pop('ref', None) # type: ignore |
| 2632 | for validator in validators: |
| 2633 | if mode == 'inner' and validator.info.mode != 'before': |
| 2634 | continue |
| 2635 | if mode == 'outer' and validator.info.mode == 'before': |
| 2636 | continue |
| 2637 | info_arg = inspect_validator(validator.func, mode=validator.info.mode, type='model') |
| 2638 | if validator.info.mode == 'wrap': |
| 2639 | if info_arg: |
| 2640 | schema = core_schema.with_info_wrap_validator_function(function=validator.func, schema=schema) |
| 2641 | else: |
| 2642 | schema = core_schema.no_info_wrap_validator_function(function=validator.func, schema=schema) |
| 2643 | elif validator.info.mode == 'before': |
| 2644 | if info_arg: |
| 2645 | schema = core_schema.with_info_before_validator_function(function=validator.func, schema=schema) |
| 2646 | else: |
| 2647 | schema = core_schema.no_info_before_validator_function(function=validator.func, schema=schema) |
| 2648 | else: |
| 2649 | assert validator.info.mode == 'after' |
| 2650 | if info_arg: |
| 2651 | schema = core_schema.with_info_after_validator_function(function=validator.func, schema=schema) |
| 2652 | else: |
| 2653 | schema = core_schema.no_info_after_validator_function(function=validator.func, schema=schema) |
| 2654 | if ref: |
| 2655 | schema['ref'] = ref # type: ignore |
| 2656 | return schema |
| 2657 | |
| 2658 | |
| 2659 | def wrap_default(field_info: FieldInfo, schema: core_schema.CoreSchema) -> core_schema.CoreSchema: |
no test coverage detected