-
-
Notifications
You must be signed in to change notification settings - Fork 228
Better compatibility for "required" vs. "nullable" #230
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
Merged
dbanty
merged 14 commits into
openapi-generators:main
from
emann:feature/add-unset-value-and-model-to-dict-params
Nov 6, 2020
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
be09dad
Added support for UNSET values and better differentiation between req…
emann 921f235
Fixed typing issues in golden record and added some test endpoints
emann ae9e2b3
Brought test coverage back to what it was before
emann 957ce46
Updated Changelog
emann fb4cb6f
Apply suggestions from code review
emann 8f7d51b
Removed to_dict params and cleaned up type strings
emann 961f6df
Fixed typing issues (again)
emann 0ab3ddf
Apply suggestions from code review
emann 9e9ebbe
Cleaned up union type strings when property is not required + require…
emann 6bc9542
Merge branch 'main' of https://github.com/triaxtec/openapi-python-cli…
emann a669ba6
Regenerated the golden record
emann 65cd367
UNSET is now a falsey value
emann 9926753
Fixed changelog entry
emann 2a8c51f
Regenerated e2e tests
emann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,67 +7,73 @@ | |
from ...client import Client | ||
from ...models.an_enum import AnEnum | ||
from ...models.http_validation_error import HTTPValidationError | ||
from ...types import Response | ||
from ...types import UNSET, Response, Unset | ||
|
||
|
||
def _get_kwargs( | ||
*, | ||
client: Client, | ||
json_body: Dict[Any, Any], | ||
string_prop: Optional[str] = "the default string", | ||
datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), | ||
date_prop: Optional[datetime.date] = isoparse("1010-10-10").date(), | ||
float_prop: Optional[float] = 3.14, | ||
int_prop: Optional[int] = 7, | ||
boolean_prop: Optional[bool] = False, | ||
list_prop: Optional[List[AnEnum]] = None, | ||
union_prop: Optional[Union[Optional[float], Optional[str]]] = "not a float", | ||
enum_prop: Optional[AnEnum] = None, | ||
string_prop: Union[Unset, str] = "the default string", | ||
datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), | ||
date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), | ||
float_prop: Union[Unset, float] = 3.14, | ||
int_prop: Union[Unset, int] = 7, | ||
boolean_prop: Union[Unset, bool] = UNSET, | ||
list_prop: Union[Unset, List[AnEnum]] = UNSET, | ||
union_prop: Union[Unset, Union[float, str]] = "not a float", | ||
enum_prop: Union[Unset, AnEnum] = UNSET, | ||
) -> Dict[str, Any]: | ||
url = "{}/tests/defaults".format(client.base_url) | ||
|
||
headers: Dict[str, Any] = client.get_headers() | ||
|
||
json_datetime_prop = datetime_prop.isoformat() if datetime_prop else None | ||
json_datetime_prop: Union[Unset, str] = UNSET | ||
if not isinstance(datetime_prop, Unset): | ||
json_datetime_prop = datetime_prop.isoformat() | ||
|
||
json_date_prop = date_prop.isoformat() if date_prop else None | ||
json_date_prop: Union[Unset, str] = UNSET | ||
if not isinstance(date_prop, Unset): | ||
json_date_prop = date_prop.isoformat() | ||
|
||
if list_prop is None: | ||
json_list_prop = None | ||
else: | ||
json_list_prop: Union[Unset, List[Any]] = UNSET | ||
if not isinstance(list_prop, Unset): | ||
json_list_prop = [] | ||
for list_prop_item_data in list_prop: | ||
list_prop_item = list_prop_item_data.value | ||
|
||
json_list_prop.append(list_prop_item) | ||
|
||
if union_prop is None: | ||
json_union_prop: Optional[Union[Optional[float], Optional[str]]] = None | ||
json_union_prop: Union[Unset, Union[float, str]] | ||
if isinstance(union_prop, Unset): | ||
json_union_prop = UNSET | ||
elif isinstance(union_prop, float): | ||
json_union_prop = union_prop | ||
else: | ||
json_union_prop = union_prop | ||
|
||
json_enum_prop = enum_prop.value if enum_prop else None | ||
json_enum_prop: Union[Unset, AnEnum] = UNSET | ||
if not isinstance(enum_prop, Unset): | ||
json_enum_prop = enum_prop.value | ||
|
||
params: Dict[str, Any] = {} | ||
if string_prop is not None: | ||
if string_prop is not UNSET: | ||
params["string_prop"] = string_prop | ||
if datetime_prop is not None: | ||
if datetime_prop is not UNSET: | ||
params["datetime_prop"] = json_datetime_prop | ||
if date_prop is not None: | ||
if date_prop is not UNSET: | ||
params["date_prop"] = json_date_prop | ||
if float_prop is not None: | ||
if float_prop is not UNSET: | ||
params["float_prop"] = float_prop | ||
if int_prop is not None: | ||
if int_prop is not UNSET: | ||
params["int_prop"] = int_prop | ||
if boolean_prop is not None: | ||
if boolean_prop is not UNSET: | ||
params["boolean_prop"] = boolean_prop | ||
if list_prop is not None: | ||
if list_prop is not UNSET: | ||
params["list_prop"] = json_list_prop | ||
if union_prop is not None: | ||
if union_prop is not UNSET: | ||
params["union_prop"] = json_union_prop | ||
if enum_prop is not None: | ||
if enum_prop is not UNSET: | ||
params["enum_prop"] = json_enum_prop | ||
|
||
json_json_body = json_body | ||
|
@@ -103,15 +109,15 @@ def sync_detailed( | |
*, | ||
client: Client, | ||
json_body: Dict[Any, Any], | ||
string_prop: Optional[str] = "the default string", | ||
datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), | ||
date_prop: Optional[datetime.date] = isoparse("1010-10-10").date(), | ||
float_prop: Optional[float] = 3.14, | ||
int_prop: Optional[int] = 7, | ||
boolean_prop: Optional[bool] = False, | ||
list_prop: Optional[List[AnEnum]] = None, | ||
union_prop: Optional[Union[Optional[float], Optional[str]]] = "not a float", | ||
enum_prop: Optional[AnEnum] = None, | ||
string_prop: Union[Unset, str] = "the default string", | ||
datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), | ||
date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), | ||
float_prop: Union[Unset, float] = 3.14, | ||
int_prop: Union[Unset, int] = 7, | ||
boolean_prop: Union[Unset, bool] = UNSET, | ||
list_prop: Union[Unset, List[AnEnum]] = UNSET, | ||
union_prop: Union[Unset, Union[float, str]] = "not a float", | ||
enum_prop: Union[Unset, AnEnum] = UNSET, | ||
) -> Response[Union[None, HTTPValidationError]]: | ||
kwargs = _get_kwargs( | ||
client=client, | ||
|
@@ -138,15 +144,15 @@ def sync( | |
*, | ||
client: Client, | ||
json_body: Dict[Any, Any], | ||
string_prop: Optional[str] = "the default string", | ||
datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), | ||
date_prop: Optional[datetime.date] = isoparse("1010-10-10").date(), | ||
float_prop: Optional[float] = 3.14, | ||
int_prop: Optional[int] = 7, | ||
boolean_prop: Optional[bool] = False, | ||
list_prop: Optional[List[AnEnum]] = None, | ||
union_prop: Optional[Union[Optional[float], Optional[str]]] = "not a float", | ||
enum_prop: Optional[AnEnum] = None, | ||
string_prop: Union[Unset, str] = "the default string", | ||
datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), | ||
date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), | ||
float_prop: Union[Unset, float] = 3.14, | ||
int_prop: Union[Unset, int] = 7, | ||
boolean_prop: Union[Unset, bool] = UNSET, | ||
list_prop: Union[Unset, List[AnEnum]] = UNSET, | ||
union_prop: Union[Unset, Union[float, str]] = "not a float", | ||
enum_prop: Union[Unset, AnEnum] = UNSET, | ||
) -> Optional[Union[None, HTTPValidationError]]: | ||
""" """ | ||
|
||
|
@@ -169,15 +175,15 @@ async def asyncio_detailed( | |
*, | ||
client: Client, | ||
json_body: Dict[Any, Any], | ||
string_prop: Optional[str] = "the default string", | ||
datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), | ||
date_prop: Optional[datetime.date] = isoparse("1010-10-10").date(), | ||
float_prop: Optional[float] = 3.14, | ||
int_prop: Optional[int] = 7, | ||
boolean_prop: Optional[bool] = False, | ||
list_prop: Optional[List[AnEnum]] = None, | ||
union_prop: Optional[Union[Optional[float], Optional[str]]] = "not a float", | ||
enum_prop: Optional[AnEnum] = None, | ||
string_prop: Union[Unset, str] = "the default string", | ||
datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), | ||
date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), | ||
float_prop: Union[Unset, float] = 3.14, | ||
int_prop: Union[Unset, int] = 7, | ||
boolean_prop: Union[Unset, bool] = UNSET, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This default used to be False, was that a mistake or did we change the spec? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
list_prop: Union[Unset, List[AnEnum]] = UNSET, | ||
union_prop: Union[Unset, Union[float, str]] = "not a float", | ||
enum_prop: Union[Unset, AnEnum] = UNSET, | ||
) -> Response[Union[None, HTTPValidationError]]: | ||
kwargs = _get_kwargs( | ||
client=client, | ||
|
@@ -203,15 +209,15 @@ async def asyncio( | |
*, | ||
client: Client, | ||
json_body: Dict[Any, Any], | ||
string_prop: Optional[str] = "the default string", | ||
datetime_prop: Optional[datetime.datetime] = isoparse("1010-10-10T00:00:00"), | ||
date_prop: Optional[datetime.date] = isoparse("1010-10-10").date(), | ||
float_prop: Optional[float] = 3.14, | ||
int_prop: Optional[int] = 7, | ||
boolean_prop: Optional[bool] = False, | ||
list_prop: Optional[List[AnEnum]] = None, | ||
union_prop: Optional[Union[Optional[float], Optional[str]]] = "not a float", | ||
enum_prop: Optional[AnEnum] = None, | ||
string_prop: Union[Unset, str] = "the default string", | ||
datetime_prop: Union[Unset, datetime.datetime] = isoparse("1010-10-10T00:00:00"), | ||
date_prop: Union[Unset, datetime.date] = isoparse("1010-10-10").date(), | ||
float_prop: Union[Unset, float] = 3.14, | ||
int_prop: Union[Unset, int] = 7, | ||
boolean_prop: Union[Unset, bool] = UNSET, | ||
list_prop: Union[Unset, List[AnEnum]] = UNSET, | ||
union_prop: Union[Unset, Union[float, str]] = "not a float", | ||
enum_prop: Union[Unset, AnEnum] = UNSET, | ||
) -> Optional[Union[None, HTTPValidationError]]: | ||
""" """ | ||
|
||
|
111 changes: 111 additions & 0 deletions
111
...s/golden-record/my_test_api_client/api/tests/optional_value_tests_optional_query_param.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
from typing import Any, Dict, List, Optional, Union, cast | ||
|
||
import httpx | ||
|
||
from ...client import Client | ||
from ...models.http_validation_error import HTTPValidationError | ||
from ...types import UNSET, Response, Unset | ||
|
||
|
||
def _get_kwargs( | ||
*, | ||
client: Client, | ||
query_param: Union[Unset, List[str]] = UNSET, | ||
) -> Dict[str, Any]: | ||
url = "{}/tests/optional_query_param/".format(client.base_url) | ||
|
||
headers: Dict[str, Any] = client.get_headers() | ||
|
||
json_query_param: Union[Unset, List[Any]] = UNSET | ||
if not isinstance(query_param, Unset): | ||
json_query_param = query_param | ||
|
||
params: Dict[str, Any] = {} | ||
if query_param is not UNSET: | ||
params["query_param"] = json_query_param | ||
|
||
return { | ||
"url": url, | ||
"headers": headers, | ||
"cookies": client.get_cookies(), | ||
"timeout": client.get_timeout(), | ||
"params": params, | ||
} | ||
|
||
|
||
def _parse_response(*, response: httpx.Response) -> Optional[Union[None, HTTPValidationError]]: | ||
if response.status_code == 200: | ||
return None | ||
if response.status_code == 422: | ||
return HTTPValidationError.from_dict(cast(Dict[str, Any], response.json())) | ||
return None | ||
|
||
|
||
def _build_response(*, response: httpx.Response) -> Response[Union[None, HTTPValidationError]]: | ||
return Response( | ||
status_code=response.status_code, | ||
content=response.content, | ||
headers=response.headers, | ||
parsed=_parse_response(response=response), | ||
) | ||
|
||
|
||
def sync_detailed( | ||
*, | ||
client: Client, | ||
query_param: Union[Unset, List[str]] = UNSET, | ||
) -> Response[Union[None, HTTPValidationError]]: | ||
kwargs = _get_kwargs( | ||
client=client, | ||
query_param=query_param, | ||
) | ||
|
||
response = httpx.get( | ||
**kwargs, | ||
) | ||
|
||
return _build_response(response=response) | ||
|
||
|
||
def sync( | ||
*, | ||
client: Client, | ||
query_param: Union[Unset, List[str]] = UNSET, | ||
) -> Optional[Union[None, HTTPValidationError]]: | ||
""" Test optional query parameters """ | ||
|
||
return sync_detailed( | ||
client=client, | ||
query_param=query_param, | ||
).parsed | ||
|
||
|
||
async def asyncio_detailed( | ||
*, | ||
client: Client, | ||
query_param: Union[Unset, List[str]] = UNSET, | ||
) -> Response[Union[None, HTTPValidationError]]: | ||
kwargs = _get_kwargs( | ||
client=client, | ||
query_param=query_param, | ||
) | ||
|
||
async with httpx.AsyncClient() as _client: | ||
response = await _client.get(**kwargs) | ||
|
||
return _build_response(response=response) | ||
|
||
|
||
async def asyncio( | ||
*, | ||
client: Client, | ||
query_param: Union[Unset, List[str]] = UNSET, | ||
) -> Optional[Union[None, HTTPValidationError]]: | ||
""" Test optional query parameters """ | ||
|
||
return ( | ||
await asyncio_detailed( | ||
client=client, | ||
query_param=query_param, | ||
) | ||
).parsed |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to handle nested unions better. I wonder if there's a function in typing somewhere that can simplify types like this. Not necessary for this PR but would be a good future enhancement.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think manually adding Unset to the union should work fine, I'll give that a shot