Skip to content

feat: Change optional Open API query parameters to allow `None #318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from ...models.an_enum import AnEnum
from ...models.http_validation_error import HTTPValidationError
from ...models.model_with_union_property import ModelWithUnionProperty
from ...types import UNSET, Unset


Expand Down Expand Up @@ -50,6 +51,7 @@ def httpx_request(
union_prop: Union[Unset, float, str] = "not a float",
union_prop_with_ref: Union[Unset, float, AnEnum] = 0.6,
enum_prop: Union[Unset, AnEnum] = UNSET,
model_prop: Union[ModelWithUnionProperty, Unset] = UNSET,
) -> Response[Union[None, HTTPValidationError]]:

json_datetime_prop: Union[Unset, str] = UNSET
Expand Down Expand Up @@ -89,27 +91,33 @@ def httpx_request(
if not isinstance(enum_prop, Unset):
json_enum_prop = enum_prop

json_model_prop: Union[Unset, Dict[str, Any]] = UNSET
if not isinstance(model_prop, Unset):
json_model_prop = model_prop.to_dict()

params: Dict[str, Any] = {}
if string_prop is not UNSET:
if not isinstance(string_prop, Unset) and string_prop is not None:
params["string_prop"] = string_prop
if datetime_prop is not UNSET:
if not isinstance(json_datetime_prop, Unset) and json_datetime_prop is not None:
params["datetime_prop"] = json_datetime_prop
if date_prop is not UNSET:
if not isinstance(json_date_prop, Unset) and json_date_prop is not None:
params["date_prop"] = json_date_prop
if float_prop is not UNSET:
if not isinstance(float_prop, Unset) and float_prop is not None:
params["float_prop"] = float_prop
if int_prop is not UNSET:
if not isinstance(int_prop, Unset) and int_prop is not None:
params["int_prop"] = int_prop
if boolean_prop is not UNSET:
if not isinstance(boolean_prop, Unset) and boolean_prop is not None:
params["boolean_prop"] = boolean_prop
if list_prop is not UNSET:
if not isinstance(json_list_prop, Unset) and json_list_prop is not None:
params["list_prop"] = json_list_prop
if union_prop is not UNSET:
if not isinstance(json_union_prop, Unset) and json_union_prop is not None:
params["union_prop"] = json_union_prop
if union_prop_with_ref is not UNSET:
if not isinstance(json_union_prop_with_ref, Unset) and json_union_prop_with_ref is not None:
params["union_prop_with_ref"] = json_union_prop_with_ref
if enum_prop is not UNSET:
if not isinstance(json_enum_prop, Unset) and json_enum_prop is not None:
params["enum_prop"] = json_enum_prop
if not isinstance(json_model_prop, Unset) and json_model_prop is not None:
params.update(json_model_prop)

response = client.request(
"post",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def httpx_request(
json_query_param = query_param

params: Dict[str, Any] = {}
if query_param is not UNSET:
if not isinstance(json_query_param, Unset) and json_query_param is not None:
params["query_param"] = json_query_param

response = client.request(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
""" Contains all the data models used in inputs/outputs """

from .a_model import AModel
from .a_model_model import AModelModel
from .a_model_not_required_model import AModelNotRequiredModel
from .a_model_not_required_nullable_model import AModelNotRequiredNullableModel
from .a_model_nullable_model import AModelNullableModel
from .an_enum import AnEnum
from .an_int_enum import AnIntEnum
from .body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost
Expand Down
50 changes: 50 additions & 0 deletions end_to_end_tests/golden-record-custom/custom_e2e/models/a_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
import attr
from dateutil.parser import isoparse

from ..models.a_model_model import AModelModel
from ..models.a_model_not_required_model import AModelNotRequiredModel
from ..models.a_model_not_required_nullable_model import AModelNotRequiredNullableModel
from ..models.a_model_nullable_model import AModelNullableModel
from ..models.an_enum import AnEnum
from ..models.different_enum import DifferentEnum
from ..types import UNSET, Unset
Expand All @@ -17,12 +21,16 @@ class AModel:
a_camel_date_time: Union[datetime.datetime, datetime.date]
a_date: datetime.date
required_not_nullable: str
model: AModelModel
a_nullable_date: Optional[datetime.date]
required_nullable: Optional[str]
nullable_model: Optional[AModelNullableModel]
nested_list_of_enums: Union[Unset, List[List[DifferentEnum]]] = UNSET
attr_1_leading_digit: Union[Unset, str] = UNSET
not_required_nullable: Union[Unset, Optional[str]] = UNSET
not_required_not_nullable: Union[Unset, str] = UNSET
not_required_model: Union[AModelNotRequiredModel, Unset] = UNSET
not_required_nullable_model: Union[Optional[AModelNotRequiredNullableModel], Unset] = UNSET

def to_dict(self) -> Dict[str, Any]:
an_enum_value = self.an_enum_value.value
Expand All @@ -35,6 +43,8 @@ def to_dict(self) -> Dict[str, Any]:

a_date = self.a_date.isoformat()
required_not_nullable = self.required_not_nullable
model = self.model.to_dict()

nested_list_of_enums: Union[Unset, List[Any]] = UNSET
if not isinstance(self.nested_list_of_enums, Unset):
nested_list_of_enums = []
Expand All @@ -52,6 +62,17 @@ def to_dict(self) -> Dict[str, Any]:
required_nullable = self.required_nullable
not_required_nullable = self.not_required_nullable
not_required_not_nullable = self.not_required_not_nullable
nullable_model = self.nullable_model.to_dict() if self.nullable_model else None

not_required_model: Union[Unset, Dict[str, Any]] = UNSET
if not isinstance(self.not_required_model, Unset):
not_required_model = self.not_required_model.to_dict()

not_required_nullable_model: Union[None, Unset, Dict[str, Any]] = UNSET
if not isinstance(self.not_required_nullable_model, Unset):
not_required_nullable_model = (
self.not_required_nullable_model.to_dict() if self.not_required_nullable_model else None
)

field_dict: Dict[str, Any] = {}
field_dict.update(
Expand All @@ -60,8 +81,10 @@ def to_dict(self) -> Dict[str, Any]:
"aCamelDateTime": a_camel_date_time,
"a_date": a_date,
"required_not_nullable": required_not_nullable,
"model": model,
"a_nullable_date": a_nullable_date,
"required_nullable": required_nullable,
"nullable_model": nullable_model,
}
)
if nested_list_of_enums is not UNSET:
Expand All @@ -72,6 +95,10 @@ def to_dict(self) -> Dict[str, Any]:
field_dict["not_required_nullable"] = not_required_nullable
if not_required_not_nullable is not UNSET:
field_dict["not_required_not_nullable"] = not_required_not_nullable
if not_required_model is not UNSET:
field_dict["not_required_model"] = not_required_model
if not_required_nullable_model is not UNSET:
field_dict["not_required_nullable_model"] = not_required_nullable_model

return field_dict

Expand Down Expand Up @@ -99,6 +126,8 @@ def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.dat

required_not_nullable = d.pop("required_not_nullable")

model = AModelModel.from_dict(d.pop("model"))

nested_list_of_enums = []
_nested_list_of_enums = d.pop("nested_list_of_enums", UNSET)
for nested_list_of_enums_item_data in _nested_list_of_enums or []:
Expand All @@ -124,17 +153,38 @@ def _parse_a_camel_date_time(data: Any) -> Union[datetime.datetime, datetime.dat

not_required_not_nullable = d.pop("not_required_not_nullable", UNSET)

nullable_model = None
_nullable_model = d.pop("nullable_model")
if _nullable_model is not None:
nullable_model = AModelNullableModel.from_dict(cast(Dict[str, Any], _nullable_model))

not_required_model: Union[AModelNotRequiredModel, Unset] = UNSET
_not_required_model = d.pop("not_required_model", UNSET)
if not isinstance(_not_required_model, Unset):
not_required_model = AModelNotRequiredModel.from_dict(cast(Dict[str, Any], _not_required_model))

not_required_nullable_model = None
_not_required_nullable_model = d.pop("not_required_nullable_model", UNSET)
if _not_required_nullable_model is not None and not isinstance(_not_required_nullable_model, Unset):
not_required_nullable_model = AModelNotRequiredNullableModel.from_dict(
cast(Dict[str, Any], _not_required_nullable_model)
)

a_model = AModel(
an_enum_value=an_enum_value,
a_camel_date_time=a_camel_date_time,
a_date=a_date,
required_not_nullable=required_not_nullable,
model=model,
nested_list_of_enums=nested_list_of_enums,
a_nullable_date=a_nullable_date,
attr_1_leading_digit=attr_1_leading_digit,
required_nullable=required_nullable,
not_required_nullable=not_required_nullable,
not_required_not_nullable=not_required_not_nullable,
nullable_model=nullable_model,
not_required_model=not_required_model,
not_required_nullable_model=not_required_nullable_model,
)

return a_model
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from typing import Any, Dict, List, Union

import attr

from ..models.an_enum import AnEnum
from ..models.an_int_enum import AnIntEnum
from ..types import UNSET, Unset


@attr.s(auto_attribs=True)
class AModelModel:
""" """

a_property: Union[Unset, AnEnum, AnIntEnum] = UNSET
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
a_property: Union[Unset, AnEnum, AnIntEnum]
if isinstance(self.a_property, Unset):
a_property = UNSET
elif isinstance(self.a_property, AnEnum):
a_property = UNSET
if not isinstance(self.a_property, Unset):
a_property = self.a_property

else:
a_property = UNSET
if not isinstance(self.a_property, Unset):
a_property = self.a_property

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update({})
if a_property is not UNSET:
field_dict["a_property"] = a_property

return field_dict

@staticmethod
def from_dict(src_dict: Dict[str, Any]) -> "AModelModel":
d = src_dict.copy()

def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
data = None if isinstance(data, Unset) else data
a_property: Union[Unset, AnEnum, AnIntEnum]
try:
a_property = UNSET
_a_property = data
if _a_property is not None:
a_property = AnEnum(_a_property)

return a_property
except: # noqa: E722
pass
a_property = UNSET
_a_property = data
if _a_property is not None:
a_property = AnIntEnum(_a_property)

return a_property

a_property = _parse_a_property(d.pop("a_property", UNSET))

a_model_model = AModelModel(
a_property=a_property,
)

a_model_model.additional_properties = d
return a_model_model

@property
def additional_keys(self) -> List[str]:
return list(self.additional_properties.keys())

def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]

def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value

def __delitem__(self, key: str) -> None:
del self.additional_properties[key]

def __contains__(self, key: str) -> bool:
return key in self.additional_properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from typing import Any, Dict, List, Union

import attr

from ..models.an_enum import AnEnum
from ..models.an_int_enum import AnIntEnum
from ..types import UNSET, Unset


@attr.s(auto_attribs=True)
class AModelNotRequiredModel:
""" """

a_property: Union[Unset, AnEnum, AnIntEnum] = UNSET
additional_properties: Dict[str, Any] = attr.ib(init=False, factory=dict)

def to_dict(self) -> Dict[str, Any]:
a_property: Union[Unset, AnEnum, AnIntEnum]
if isinstance(self.a_property, Unset):
a_property = UNSET
elif isinstance(self.a_property, AnEnum):
a_property = UNSET
if not isinstance(self.a_property, Unset):
a_property = self.a_property

else:
a_property = UNSET
if not isinstance(self.a_property, Unset):
a_property = self.a_property

field_dict: Dict[str, Any] = {}
field_dict.update(self.additional_properties)
field_dict.update({})
if a_property is not UNSET:
field_dict["a_property"] = a_property

return field_dict

@staticmethod
def from_dict(src_dict: Dict[str, Any]) -> "AModelNotRequiredModel":
d = src_dict.copy()

def _parse_a_property(data: Any) -> Union[Unset, AnEnum, AnIntEnum]:
data = None if isinstance(data, Unset) else data
a_property: Union[Unset, AnEnum, AnIntEnum]
try:
a_property = UNSET
_a_property = data
if _a_property is not None:
a_property = AnEnum(_a_property)

return a_property
except: # noqa: E722
pass
a_property = UNSET
_a_property = data
if _a_property is not None:
a_property = AnIntEnum(_a_property)

return a_property

a_property = _parse_a_property(d.pop("a_property", UNSET))

a_model_not_required_model = AModelNotRequiredModel(
a_property=a_property,
)

a_model_not_required_model.additional_properties = d
return a_model_not_required_model

@property
def additional_keys(self) -> List[str]:
return list(self.additional_properties.keys())

def __getitem__(self, key: str) -> Any:
return self.additional_properties[key]

def __setitem__(self, key: str, value: Any) -> None:
self.additional_properties[key] = value

def __delitem__(self, key: str) -> None:
del self.additional_properties[key]

def __contains__(self, key: str) -> bool:
return key in self.additional_properties
Loading