11from __future__ import annotations
22
3- from dataclasses import dataclass , field , replace
3+ from dataclasses import dataclass , field
44from enum import Enum
5- from typing import Any , Dict , Generator , Iterable , List , Optional , Set
5+ from typing import Any , Dict , Generator , Iterable , List , Optional , Set , Union
66
7- from .properties import EnumProperty , ListProperty , Property , RefProperty , property_from_dict
7+ from .properties import EnumListProperty , EnumProperty , Property , ReferenceListProperty , RefProperty , property_from_dict
88from .reference import Reference
99from .responses import ListRefResponse , RefResponse , Response , response_from_dict
1010
@@ -91,7 +91,7 @@ def _add_body(self, data: Dict[str, Any]) -> None:
9191 self .relative_imports .add (import_string_from_reference (self .form_body_reference , prefix = "..models" ))
9292 if (
9393 self .json_body is not None
94- and isinstance (self .json_body , (ListProperty , RefProperty , EnumProperty ))
94+ and isinstance (self .json_body , (ReferenceListProperty , EnumListProperty , RefProperty , EnumProperty ))
9595 and self .json_body .reference is not None
9696 ):
9797 self .relative_imports .add (import_string_from_reference (self .json_body .reference , prefix = "..models" ))
@@ -108,7 +108,10 @@ def _add_parameters(self, data: Dict[str, Any]) -> None:
108108 prop = property_from_dict (
109109 name = param_dict ["name" ], required = param_dict ["required" ], data = param_dict ["schema" ]
110110 )
111- if isinstance (prop , (ListProperty , RefProperty , EnumProperty )) and prop .reference :
111+ if (
112+ isinstance (prop , (ReferenceListProperty , EnumListProperty , RefProperty , EnumProperty ))
113+ and prop .reference
114+ ):
112115 self .relative_imports .add (import_string_from_reference (prop .reference , prefix = "..models" ))
113116 if param_dict ["in" ] == ParameterLocation .QUERY :
114117 self .query_parameters .append (prop )
@@ -165,7 +168,7 @@ def from_dict(d: Dict[str, Any], /) -> Schema:
165168 required_properties .append (p )
166169 else :
167170 optional_properties .append (p )
168- if isinstance (p , (ListProperty , RefProperty , EnumProperty )) and p .reference :
171+ if isinstance (p , (ReferenceListProperty , EnumListProperty , RefProperty , EnumProperty )) and p .reference :
169172 relative_imports .add (import_string_from_reference (p .reference ))
170173 schema = Schema (
171174 reference = Reference .from_ref (d ["title" ]),
@@ -195,17 +198,19 @@ class OpenAPI:
195198 version : str
196199 schemas : Dict [str , Schema ]
197200 endpoint_collections_by_tag : Dict [str , EndpointCollection ]
198- enums : Dict [str , EnumProperty ]
201+ enums : Dict [str , Union [ EnumProperty , EnumListProperty ] ]
199202
200203 @staticmethod
201- def _check_enums (schemas : Iterable [Schema ], collections : Iterable [EndpointCollection ]) -> Dict [str , EnumProperty ]:
204+ def _check_enums (
205+ schemas : Iterable [Schema ], collections : Iterable [EndpointCollection ]
206+ ) -> Dict [str , Union [EnumProperty , EnumListProperty ]]:
202207 """
203208 Create EnumProperties for every enum in any schema or collection.
204209 Enums are deduplicated by class name.
205210
206211 :raises AssertionError: if two Enums with the same name but different values are detected
207212 """
208- enums : Dict [str , EnumProperty ] = {}
213+ enums : Dict [str , Union [ EnumProperty , EnumListProperty ] ] = {}
209214
210215 def _iterate_properties () -> Generator [Property , None , None ]:
211216 for schema in schemas :
@@ -217,7 +222,7 @@ def _iterate_properties() -> Generator[Property, None, None]:
217222 yield from endpoint .query_parameters
218223
219224 for prop in _iterate_properties ():
220- if not isinstance (prop , EnumProperty ):
225+ if not isinstance (prop , ( EnumProperty , EnumListProperty ) ):
221226 continue
222227
223228 if prop .reference .class_name in enums :
0 commit comments