1
1
from __future__ import annotations
2
2
3
- from dataclasses import dataclass , field , replace
3
+ from dataclasses import dataclass , field
4
4
from 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
6
6
7
- from .properties import EnumProperty , ListProperty , Property , RefProperty , property_from_dict
7
+ from .properties import EnumListProperty , EnumProperty , Property , ReferenceListProperty , RefProperty , property_from_dict
8
8
from .reference import Reference
9
9
from .responses import ListRefResponse , RefResponse , Response , response_from_dict
10
10
@@ -91,7 +91,7 @@ def _add_body(self, data: Dict[str, Any]) -> None:
91
91
self .relative_imports .add (import_string_from_reference (self .form_body_reference , prefix = "..models" ))
92
92
if (
93
93
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 ))
95
95
and self .json_body .reference is not None
96
96
):
97
97
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:
108
108
prop = property_from_dict (
109
109
name = param_dict ["name" ], required = param_dict ["required" ], data = param_dict ["schema" ]
110
110
)
111
- if isinstance (prop , (ListProperty , RefProperty , EnumProperty )) and prop .reference :
111
+ if (
112
+ isinstance (prop , (ReferenceListProperty , EnumListProperty , RefProperty , EnumProperty ))
113
+ and prop .reference
114
+ ):
112
115
self .relative_imports .add (import_string_from_reference (prop .reference , prefix = "..models" ))
113
116
if param_dict ["in" ] == ParameterLocation .QUERY :
114
117
self .query_parameters .append (prop )
@@ -165,7 +168,7 @@ def from_dict(d: Dict[str, Any], /) -> Schema:
165
168
required_properties .append (p )
166
169
else :
167
170
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 :
169
172
relative_imports .add (import_string_from_reference (p .reference ))
170
173
schema = Schema (
171
174
reference = Reference .from_ref (d ["title" ]),
@@ -195,17 +198,19 @@ class OpenAPI:
195
198
version : str
196
199
schemas : Dict [str , Schema ]
197
200
endpoint_collections_by_tag : Dict [str , EndpointCollection ]
198
- enums : Dict [str , EnumProperty ]
201
+ enums : Dict [str , Union [ EnumProperty , EnumListProperty ] ]
199
202
200
203
@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 ]]:
202
207
"""
203
208
Create EnumProperties for every enum in any schema or collection.
204
209
Enums are deduplicated by class name.
205
210
206
211
:raises AssertionError: if two Enums with the same name but different values are detected
207
212
"""
208
- enums : Dict [str , EnumProperty ] = {}
213
+ enums : Dict [str , Union [ EnumProperty , EnumListProperty ] ] = {}
209
214
210
215
def _iterate_properties () -> Generator [Property , None , None ]:
211
216
for schema in schemas :
@@ -217,7 +222,7 @@ def _iterate_properties() -> Generator[Property, None, None]:
217
222
yield from endpoint .query_parameters
218
223
219
224
for prop in _iterate_properties ():
220
- if not isinstance (prop , EnumProperty ):
225
+ if not isinstance (prop , ( EnumProperty , EnumListProperty ) ):
221
226
continue
222
227
223
228
if prop .reference .class_name in enums :
0 commit comments