Take a single `enum` and generate its schema. This is similar to the `model_process_schema` function, but applies to ``Enum`` objects.
(enum: Type[Enum], *, field: Optional[ModelField] = None)
| 653 | |
| 654 | |
| 655 | def enum_process_schema(enum: Type[Enum], *, field: Optional[ModelField] = None) -> Dict[str, Any]: |
| 656 | """ |
| 657 | Take a single `enum` and generate its schema. |
| 658 | |
| 659 | This is similar to the `model_process_schema` function, but applies to ``Enum`` objects. |
| 660 | """ |
| 661 | import inspect |
| 662 | |
| 663 | schema_: Dict[str, Any] = { |
| 664 | 'title': enum.__name__, |
| 665 | # Python assigns all enums a default docstring value of 'An enumeration', so |
| 666 | # all enums will have a description field even if not explicitly provided. |
| 667 | 'description': inspect.cleandoc(enum.__doc__ or 'An enumeration.'), |
| 668 | # Add enum values and the enum field type to the schema. |
| 669 | 'enum': [item.value for item in cast(Iterable[Enum], enum)], |
| 670 | } |
| 671 | |
| 672 | add_field_type_to_schema(enum, schema_) |
| 673 | |
| 674 | modify_schema = getattr(enum, '__modify_schema__', None) |
| 675 | if modify_schema: |
| 676 | _apply_modify_schema(modify_schema, field, schema_) |
| 677 | |
| 678 | return schema_ |
| 679 | |
| 680 | |
| 681 | def field_singleton_sub_fields_schema( |
no test coverage detected