Skip to content

Commit 655f7c0

Browse files
Nementonp1-ra
authored andcommitted
correct openapi_schema_pydantic schemas breaking changes
- anyOf, allOf, oneOf now default to `None` instead of `[]`
1 parent a36b49c commit 655f7c0

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

openapi_python_client/parser/properties/__init__.py

Lines changed: 12 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,13 @@ 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+
sub_data: List[Union[oai.Schema, oai.Reference]] = []
356+
for _data in [data.anyOf, data.oneOf]:
357+
if isinstance(_data, Iterable):
358+
sub_data.extend(_data)
359+
360+
for i, sub_prop_data in enumerate(sub_data):
356361
sub_prop, schemas = property_from_data(
357362
name=f"{name}_type{i}",
358363
required=required,
@@ -439,8 +444,12 @@ def _property_from_data(
439444
if isinstance(data, oai.Reference):
440445
return _property_from_ref(name=name, required=required, parent=None, data=data, schemas=schemas)
441446

447+
sub_data: List[Union[oai.Schema, oai.Reference]] = []
448+
for _data in [data.allOf, data.anyOf, data.oneOf]:
449+
if isinstance(_data, Iterable):
450+
sub_data.extend(_data)
451+
442452
# 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
444453
if len(sub_data) == 1 and isinstance(sub_data[0], oai.Reference):
445454
return _property_from_ref(name=name, required=required, parent=data, data=sub_data[0], schemas=schemas)
446455

openapi_python_client/parser/properties/property.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class Property:
2222

2323
name: str
2424
required: bool
25-
nullable: bool
25+
nullable: bool = attr.ib(converter=utils.optin_bool_to_bool_converter)
2626
_type_string: ClassVar[str] = ""
2727
_json_type_string: ClassVar[str] = "" # Type of the property after JSON serialization
2828
default: Optional[str] = attr.ib()

openapi_python_client/utils.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import builtins
22
import re
33
from keyword import iskeyword
4-
from typing import List
4+
from typing import List, Optional
55

66
delimiters = " _-"
77

@@ -73,3 +73,13 @@ def to_valid_python_identifier(value: str) -> str:
7373
return new_value
7474

7575
return f"{FIELD_PREFIX}{new_value}"
76+
77+
78+
def optin_bool_to_bool_converter(value: Optional[bool]) -> bool:
79+
"""
80+
Given an Option[bool] return a bool
81+
None are converted to False
82+
"""
83+
if value is None:
84+
return False
85+
return value

0 commit comments

Comments
 (0)