Skip to content

Commit

Permalink
parser / properties / do not restrict reference pointer type to `enum…
Browse files Browse the repository at this point in the history
…` or `object`
  • Loading branch information
Nementon authored and p1-ra committed May 12, 2021
1 parent 6375ba4 commit 3ca13f4
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions openapi_python_client/parser/properties/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,9 @@
from ..errors import ParseError, PropertyError, RecursiveReferenceInterupt

if TYPE_CHECKING: # pragma: no cover
from .enum_property import EnumProperty
from .model_property import ModelProperty
from .property import Property
else:
EnumProperty = "EnumProperty"
ModelProperty = "ModelProperty"
Property = "Property"

T = TypeVar("T")
_ReferencePath = NewType("_ReferencePath", str)
Expand Down Expand Up @@ -64,10 +62,10 @@ class Schemas:
"""Structure for containing all defined, shareable, and reusable schemas (attr classes and Enums)"""

classes_by_reference: Dict[
_ReferencePath, _Holder[Union[EnumProperty, ModelProperty, RecursiveReferenceInterupt]]
_ReferencePath, _Holder[Union[Property, RecursiveReferenceInterupt]]
] = attr.ib(factory=dict)
classes_by_name: Dict[
_ClassName, _Holder[Union[EnumProperty, ModelProperty, RecursiveReferenceInterupt]]
_ClassName, _Holder[Union[Property, RecursiveReferenceInterupt]]
] = attr.ib(factory=dict)
errors: List[ParseError] = attr.ib(factory=list)

Expand Down Expand Up @@ -105,17 +103,12 @@ def _update_schemas_with_reference(
def _update_schemas_with_data(
*, ref_path: _ReferencePath, data: oai.Schema, schemas: Schemas, visited: Set[_ReferencePath], config: Config
) -> Union[Schemas, PropertyError]:
from . import build_enum_property, build_model_property
from . import property_from_data

prop: Union[PropertyError, ModelProperty, EnumProperty]
if data.enum is not None:
prop, schemas = build_enum_property(
data=data, name=ref_path, required=True, schemas=schemas, enum=data.enum, parent_name=None, config=config
)
else:
prop, schemas = build_model_property(
data=data, name=ref_path, schemas=schemas, required=True, parent_name=None, config=config
)
prop: Union[PropertyError, Property]
prop, schemas = property_from_data(
data=data, name=ref_path, schemas=schemas, required=True, parent_name="", config=config
)

holder = schemas.classes_by_reference.get(ref_path)
if isinstance(prop, PropertyError):
Expand Down

0 comments on commit 3ca13f4

Please sign in to comment.