Skip to content

Commit 1f51974

Browse files
committed
correct openapi_schema_pydantic schemas breaking changes
- anyOf, allOf, oneOf now default to `None` instead of `[]`
1 parent a36b49c commit 1f51974

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

openapi_python_client/parser/properties/__init__.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
"property_from_data",
1010
]
1111

12-
from itertools import chain
1312
from typing import Any, ClassVar, Dict, Generic, Iterable, Iterator, List, Optional, Set, Tuple, TypeVar, Union
1413

1514
import attr
@@ -352,7 +351,14 @@ def build_union_property(
352351
*, data: oai.Schema, name: str, required: bool, schemas: Schemas, parent_name: str, config: Config
353352
) -> Tuple[Union[UnionProperty, PropertyError], Schemas]:
354353
sub_properties: List[Property] = []
355-
for i, sub_prop_data in enumerate(chain(data.anyOf, data.oneOf)):
354+
355+
for i, sub_prop_data in enumerate(
356+
[
357+
data
358+
for sublists in filter(lambda x: isinstance(x, Iterable), [[], data.anyOf, data.oneOf])
359+
for data in sublists
360+
]
361+
):
356362
sub_prop, schemas = property_from_data(
357363
name=f"{name}_type{i}",
358364
required=required,
@@ -440,7 +446,11 @@ def _property_from_data(
440446
return _property_from_ref(name=name, required=required, parent=None, data=data, schemas=schemas)
441447

442448
# A union of a single reference should just be passed through to that reference (don't create copy class)
443-
sub_data = (data.allOf or []) + data.anyOf + data.oneOf
449+
sub_data = [
450+
data
451+
for sublists in filter(lambda x: isinstance(x, Iterable), [[], data.allOf, data.anyOf, data.oneOf])
452+
for data in sublists
453+
]
444454
if len(sub_data) == 1 and isinstance(sub_data[0], oai.Reference):
445455
return _property_from_ref(name=name, required=required, parent=data, data=sub_data[0], schemas=schemas)
446456

0 commit comments

Comments
 (0)