-
-
Notifications
You must be signed in to change notification settings - Fork 229
Path parameters as function positional arguments #429
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
Changes from 1 commit
fd5629f
b9e8057
432188a
a5b6e5f
dbd3f1b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
from typing import Any, Dict | ||
|
||
import httpx | ||
|
||
from ...client import Client | ||
from ...types import Response | ||
|
||
|
||
def _get_kwargs( | ||
param_1: str, | ||
param_2: int, | ||
*, | ||
client: Client, | ||
) -> Dict[str, Any]: | ||
url = "{}/multiple-path-parameters/{param1}/{param2}".format(client.base_url, param1=param_1, param2=param_2) | ||
|
||
headers: Dict[str, Any] = client.get_headers() | ||
cookies: Dict[str, Any] = client.get_cookies() | ||
|
||
return { | ||
"url": url, | ||
"headers": headers, | ||
"cookies": cookies, | ||
"timeout": client.get_timeout(), | ||
} | ||
|
||
|
||
def _build_response(*, response: httpx.Response) -> Response[None]: | ||
return Response( | ||
status_code=response.status_code, | ||
content=response.content, | ||
headers=response.headers, | ||
parsed=None, | ||
) | ||
|
||
|
||
def sync_detailed( | ||
param_1: str, | ||
param_2: int, | ||
*, | ||
client: Client, | ||
) -> Response[None]: | ||
kwargs = _get_kwargs( | ||
param_1=param_1, | ||
param_2=param_2, | ||
client=client, | ||
) | ||
|
||
response = httpx.get( | ||
**kwargs, | ||
) | ||
|
||
return _build_response(response=response) | ||
|
||
|
||
async def asyncio_detailed( | ||
param_1: str, | ||
param_2: int, | ||
*, | ||
client: Client, | ||
) -> Response[None]: | ||
kwargs = _get_kwargs( | ||
param_1=param_1, | ||
param_2=param_2, | ||
client=client, | ||
) | ||
|
||
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 |
---|---|---|
|
@@ -73,17 +73,17 @@ params = {k: v for k, v in params.items() if v is not UNSET and v is not None} | |
|
||
{# The all the kwargs passed into an endpoint (and variants thereof)) #} | ||
{% macro arguments(endpoint) %} | ||
{# path parameters #} | ||
{% for parameter in endpoint.path_parameters %} | ||
{{ parameter.to_string() }}, | ||
{% endfor %} | ||
Comment on lines
+76
to
+79
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. Only problem with this is that the order of If we want to allow positional args, we'll have to guarantee the order for them. For Path params we could use the order in which they appear in the path, which seems the most logical solution to me. It's going to require a bit more up front parsing work though. 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. Thanks for the review! I will work on sort them in the order they appear in the path. 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. Done in b9e8057 |
||
*, | ||
{# Proper client based on whether or not the endpoint requires authentication #} | ||
{% if endpoint.requires_security %} | ||
client: AuthenticatedClient, | ||
{% else %} | ||
client: Client, | ||
{% endif %} | ||
{# path parameters #} | ||
{% for parameter in endpoint.path_parameters %} | ||
{{ parameter.to_string() }}, | ||
{% endfor %} | ||
{# Form data if any #} | ||
{% if endpoint.form_body_class %} | ||
form_data: {{ endpoint.form_body_class.name }}, | ||
|
@@ -111,10 +111,10 @@ json_body: {{ endpoint.json_body.get_type_string() }}, | |
|
||
{# Just lists all kwargs to endpoints as name=name for passing to other functions #} | ||
{% macro kwargs(endpoint) %} | ||
client=client, | ||
{% for parameter in endpoint.path_parameters %} | ||
{{ parameter.python_name }}={{ parameter.python_name }}, | ||
{% endfor %} | ||
client=client, | ||
{% if endpoint.form_body_class %} | ||
form_data=form_data, | ||
{% endif %} | ||
|
Uh oh!
There was an error while loading. Please reload this page.