|
11 | 11 | from ..errors import ParseError, PropertyError
|
12 | 12 |
|
13 | 13 | if TYPE_CHECKING: # pragma: no cover
|
14 |
| - from .enum_property import EnumProperty |
15 |
| - from .model_property import ModelProperty |
| 14 | + from .property import Property |
16 | 15 | else:
|
17 |
| - EnumProperty = "EnumProperty" |
18 |
| - ModelProperty = "ModelProperty" |
| 16 | + Property = "Property" |
19 | 17 |
|
20 | 18 |
|
21 | 19 | _ReferencePath = NewType("_ReferencePath", str)
|
@@ -58,26 +56,23 @@ def from_string(*, string: str, config: Config) -> "Class":
|
58 | 56 | class Schemas:
|
59 | 57 | """Structure for containing all defined, shareable, and reusable schemas (attr classes and Enums)"""
|
60 | 58 |
|
61 |
| - classes_by_reference: Dict[_ReferencePath, Union[EnumProperty, ModelProperty]] = attr.ib(factory=dict) |
62 |
| - classes_by_name: Dict[_ClassName, Union[EnumProperty, ModelProperty]] = attr.ib(factory=dict) |
| 59 | + classes_by_reference: Dict[_ReferencePath, Property] = attr.ib(factory=dict) |
| 60 | + classes_by_name: Dict[_ClassName, Property] = attr.ib(factory=dict) |
63 | 61 | errors: List[ParseError] = attr.ib(factory=list)
|
64 | 62 |
|
65 | 63 |
|
66 | 64 | def update_schemas_with_data(
|
67 | 65 | *, ref_path: _ReferencePath, data: oai.Schema, schemas: Schemas, config: Config
|
68 | 66 | ) -> Union[Schemas, PropertyError]:
|
69 |
| - from . import build_enum_property, build_model_property |
70 |
| - |
71 |
| - prop: Union[PropertyError, ModelProperty, EnumProperty] |
72 |
| - if data.enum is not None: |
73 |
| - prop, schemas = build_enum_property( |
74 |
| - data=data, name=ref_path, required=True, schemas=schemas, enum=data.enum, parent_name=None, config=config |
75 |
| - ) |
76 |
| - else: |
77 |
| - prop, schemas = build_model_property( |
78 |
| - data=data, name=ref_path, schemas=schemas, required=True, parent_name=None, config=config |
79 |
| - ) |
| 67 | + from . import property_from_data |
| 68 | + |
| 69 | + prop: Union[PropertyError, Property] |
| 70 | + prop, schemas = property_from_data( |
| 71 | + data=data, name=ref_path, schemas=schemas, required=True, parent_name=None, config=config |
| 72 | + ) |
| 73 | + |
80 | 74 | if isinstance(prop, PropertyError):
|
81 | 75 | return prop
|
| 76 | + |
82 | 77 | schemas = attr.evolve(schemas, classes_by_reference={ref_path: prop, **schemas.classes_by_reference})
|
83 | 78 | return schemas
|
0 commit comments