Skip to content

feat: Include both UNSET and None static types for nullable or optional query params #462

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
merged 1 commit into from
Aug 15, 2021
Merged
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 @@ -3,6 +3,7 @@
from typing import Type

from .default import DefaultEndpoints
from .location import LocationEndpoints
from .parameters import ParametersEndpoints
from .tag1 import Tag1Endpoints
from .tests import TestsEndpoints
Expand All @@ -24,3 +25,7 @@ def parameters(cls) -> Type[ParametersEndpoints]:
@classmethod
def tag1(cls) -> Type[Tag1Endpoints]:
return Tag1Endpoints

@classmethod
def location(cls) -> Type[LocationEndpoints]:
return LocationEndpoints
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
""" Contains methods for accessing the API Endpoints """

import types

from . import get_location_query_optionality


class LocationEndpoints:
@classmethod
def get_location_query_optionality(cls) -> types.ModuleType:
return get_location_query_optionality
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
json_body_tests_json_body_post,
no_response_tests_no_response_get,
octet_stream_tests_octet_stream_get,
optional_value_tests_optional_query_param,
post_form_data,
test_inline_objects,
token_with_cookie_auth_token_with_cookie_get,
Expand Down Expand Up @@ -129,13 +128,6 @@ def test_inline_objects(cls) -> types.ModuleType:
"""
return test_inline_objects

@classmethod
def optional_value_tests_optional_query_param(cls) -> types.ModuleType:
"""
Test optional query parameters
"""
return optional_value_tests_optional_query_param

@classmethod
def token_with_cookie_auth_token_with_cookie_get(cls) -> types.ModuleType:
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def _get_kwargs(
*,
client: Client,
common: Union[Unset, str] = UNSET,
common: Union[Unset, None, str] = UNSET,
) -> Dict[str, Any]:
url = "{}/common_parameters".format(client.base_url)

Expand Down Expand Up @@ -42,7 +42,7 @@ def _build_response(*, response: httpx.Response) -> Response[Any]:
def sync_detailed(
*,
client: Client,
common: Union[Unset, str] = UNSET,
common: Union[Unset, None, str] = UNSET,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
Expand All @@ -59,7 +59,7 @@ def sync_detailed(
async def asyncio_detailed(
*,
client: Client,
common: Union[Unset, str] = UNSET,
common: Union[Unset, None, str] = UNSET,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
def _get_kwargs(
*,
client: Client,
common: Union[Unset, str] = UNSET,
common: Union[Unset, None, str] = UNSET,
) -> Dict[str, Any]:
url = "{}/common_parameters".format(client.base_url)

Expand Down Expand Up @@ -42,7 +42,7 @@ def _build_response(*, response: httpx.Response) -> Response[Any]:
def sync_detailed(
*,
client: Client,
common: Union[Unset, str] = UNSET,
common: Union[Unset, None, str] = UNSET,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
Expand All @@ -59,7 +59,7 @@ def sync_detailed(
async def asyncio_detailed(
*,
client: Client,
common: Union[Unset, str] = UNSET,
common: Union[Unset, None, str] = UNSET,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import datetime
from typing import Any, Dict, Union

import httpx

from ...client import Client
from ...types import UNSET, Response, Unset


def _get_kwargs(
*,
client: Client,
not_null_required: datetime.datetime,
null_required: Union[Unset, None, datetime.datetime] = UNSET,
null_not_required: Union[Unset, None, datetime.datetime] = UNSET,
not_null_not_required: Union[Unset, None, datetime.datetime] = UNSET,
) -> Dict[str, Any]:
url = "{}/location/query/optionality".format(client.base_url)

headers: Dict[str, Any] = client.get_headers()
cookies: Dict[str, Any] = client.get_cookies()

json_not_null_required = not_null_required.isoformat()

json_null_required: Union[Unset, None, str] = UNSET
if not isinstance(null_required, Unset):
json_null_required = null_required.isoformat() if null_required else None

json_null_not_required: Union[Unset, None, str] = UNSET
if not isinstance(null_not_required, Unset):
json_null_not_required = null_not_required.isoformat() if null_not_required else None

json_not_null_not_required: Union[Unset, None, str] = UNSET
if not isinstance(not_null_not_required, Unset):
json_not_null_not_required = not_null_not_required.isoformat() if not_null_not_required else None

params: Dict[str, Any] = {
"not_null_required": json_not_null_required,
"null_required": json_null_required,
"null_not_required": json_null_not_required,
"not_null_not_required": json_not_null_not_required,
}
params = {k: v for k, v in params.items() if v is not UNSET and v is not None}

return {
"url": url,
"headers": headers,
"cookies": cookies,
"timeout": client.get_timeout(),
"params": params,
}


def _build_response(*, response: httpx.Response) -> Response[Any]:
return Response(
status_code=response.status_code,
content=response.content,
headers=response.headers,
parsed=None,
)


def sync_detailed(
*,
client: Client,
not_null_required: datetime.datetime,
null_required: Union[Unset, None, datetime.datetime] = UNSET,
null_not_required: Union[Unset, None, datetime.datetime] = UNSET,
not_null_not_required: Union[Unset, None, datetime.datetime] = UNSET,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
not_null_required=not_null_required,
null_required=null_required,
null_not_required=null_not_required,
not_null_not_required=not_null_not_required,
)

response = httpx.get(
**kwargs,
)

return _build_response(response=response)


async def asyncio_detailed(
*,
client: Client,
not_null_required: datetime.datetime,
null_required: Union[Unset, None, datetime.datetime] = UNSET,
null_not_required: Union[Unset, None, datetime.datetime] = UNSET,
not_null_not_required: Union[Unset, None, datetime.datetime] = UNSET,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
not_null_required=not_null_required,
null_required=null_required,
null_not_required=null_not_required,
not_null_not_required=not_null_not_required,
)

async with httpx.AsyncClient() as _client:
response = await _client.get(**kwargs)

return _build_response(response=response)
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def _get_kwargs(
*,
client: Client,
param_path: str,
param_query: Union[Unset, str] = UNSET,
param_query: Union[Unset, None, str] = UNSET,
) -> Dict[str, Any]:
url = "{}/common_parameters_overriding/{param}".format(client.base_url, param=param_path)

Expand Down Expand Up @@ -44,7 +44,7 @@ def sync_detailed(
*,
client: Client,
param_path: str,
param_query: Union[Unset, str] = UNSET,
param_query: Union[Unset, None, str] = UNSET,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
Expand All @@ -63,7 +63,7 @@ async def asyncio_detailed(
*,
client: Client,
param_path: str,
param_query: Union[Unset, str] = UNSET,
param_query: Union[Unset, None, str] = UNSET,
) -> Response[Any]:
kwargs = _get_kwargs(
client=client,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def _get_kwargs(
*,
client: Client,
param_path: str,
param_query: Union[Unset, str] = UNSET,
param_query: Union[Unset, None, str] = UNSET,
param_header: Union[Unset, str] = UNSET,
param_cookie: Union[Unset, str] = UNSET,
) -> Dict[str, Any]:
Expand Down Expand Up @@ -52,7 +52,7 @@ def sync_detailed(
*,
client: Client,
param_path: str,
param_query: Union[Unset, str] = UNSET,
param_query: Union[Unset, None, str] = UNSET,
param_header: Union[Unset, str] = UNSET,
param_cookie: Union[Unset, str] = UNSET,
) -> Response[Any]:
Expand All @@ -75,7 +75,7 @@ async def asyncio_detailed(
*,
client: Client,
param_path: str,
param_query: Union[Unset, str] = UNSET,
param_query: Union[Unset, None, str] = UNSET,
param_header: Union[Unset, str] = UNSET,
param_cookie: Union[Unset, str] = UNSET,
) -> Response[Any]:
Expand Down
Loading