-
-
Notifications
You must be signed in to change notification settings - Fork 229
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 4 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
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
112 changes: 112 additions & 0 deletions
112
...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,112 @@ | ||
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 | ||
|
||
|
||
def _get_kwargs( | ||
*, | ||
client: Client, | ||
query_param: List[str] = cast(List[str], UNSET), | ||
) -> Dict[str, Any]: | ||
url = "{}/tests/optional_query_param/".format(client.base_url) | ||
|
||
headers: Dict[str, Any] = client.get_headers() | ||
|
||
if query_param is UNSET: | ||
json_query_param = UNSET | ||
else: | ||
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: List[str] = cast(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: List[str] = cast(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: List[str] = cast(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: List[str] = cast(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.
I think the right thing to do with these would be to make the type
Union[bool, Unset]
when the prop is not required. That way we're not lying about the data that could be in an instance of this class.