-
-
Notifications
You must be signed in to change notification settings - Fork 209
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support multiple tags in each endpoint (#687)
Currently when an endpoint has multiple tags, the first tag is used and everything else is ignored. This PR modifies it so endpoints with multiple tags are added to each of the tags. Yes, this results in repeated code 😅, but works beautifully and functions can now be found anywhere we expect them to be. --------- Co-authored-by: Dylan Anthony <[email protected]> Co-authored-by: Dylan Anthony <[email protected]>
- Loading branch information
1 parent
7225f0e
commit 88b3be1
Showing
14 changed files
with
175 additions
and
120 deletions.
There are no files selected for viewing
This file contains 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,8 @@ | ||
--- | ||
default: minor | ||
--- | ||
|
||
# Add `generate_all_tags` config option | ||
|
||
You can now, optionally, generate **duplicate** endpoint functions/modules using _every_ tag for an endpoint, | ||
not just the first one, by setting `generate_all_tags: true` in your configuration file. |
This file contains 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 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 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 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 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 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
11 changes: 11 additions & 0 deletions
11
end_to_end_tests/custom-templates-golden-record/my_test_api_client/api/tag2/__init__.py
This file contains 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,11 @@ | ||
"""Contains methods for accessing the API Endpoints""" | ||
|
||
import types | ||
|
||
from . import get_tag_with_number | ||
|
||
|
||
class Tag2Endpoints: | ||
@classmethod | ||
def get_tag_with_number(cls) -> types.ModuleType: | ||
return get_tag_with_number |
14 changes: 14 additions & 0 deletions
14
end_to_end_tests/documents_with_errors/bad-status-code.yaml
This file contains 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,14 @@ | ||
openapi: "3.1.0" | ||
info: | ||
title: "There's something wrong with me" | ||
version: "0.1.0" | ||
paths: | ||
"/": | ||
get: | ||
responses: | ||
"abcdef": | ||
description: "Successful Response" | ||
content: | ||
"application/json": | ||
schema: | ||
const: "Why have a fixed response? I dunno" |
Empty file.
77 changes: 77 additions & 0 deletions
77
end_to_end_tests/golden-record/my_test_api_client/api/tag2/get_tag_with_number.py
This file contains 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,77 @@ | ||
from http import HTTPStatus | ||
from typing import Any, Optional, Union | ||
|
||
import httpx | ||
|
||
from ... import errors | ||
from ...client import AuthenticatedClient, Client | ||
from ...types import Response | ||
|
||
|
||
def _get_kwargs() -> dict[str, Any]: | ||
_kwargs: dict[str, Any] = { | ||
"method": "get", | ||
"url": "/tag_with_number", | ||
} | ||
|
||
return _kwargs | ||
|
||
|
||
def _parse_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Optional[Any]: | ||
if response.status_code == 200: | ||
return None | ||
if client.raise_on_unexpected_status: | ||
raise errors.UnexpectedStatus(response.status_code, response.content) | ||
else: | ||
return None | ||
|
||
|
||
def _build_response(*, client: Union[AuthenticatedClient, Client], response: httpx.Response) -> Response[Any]: | ||
return Response( | ||
status_code=HTTPStatus(response.status_code), | ||
content=response.content, | ||
headers=response.headers, | ||
parsed=_parse_response(client=client, response=response), | ||
) | ||
|
||
|
||
def sync_detailed( | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
) -> Response[Any]: | ||
""" | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
Response[Any] | ||
""" | ||
|
||
kwargs = _get_kwargs() | ||
|
||
response = client.get_httpx_client().request( | ||
**kwargs, | ||
) | ||
|
||
return _build_response(client=client, response=response) | ||
|
||
|
||
async def asyncio_detailed( | ||
*, | ||
client: Union[AuthenticatedClient, Client], | ||
) -> Response[Any]: | ||
""" | ||
Raises: | ||
errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True. | ||
httpx.TimeoutException: If the request takes longer than Client.timeout. | ||
Returns: | ||
Response[Any] | ||
""" | ||
|
||
kwargs = _get_kwargs() | ||
|
||
response = await client.get_async_httpx_client().request(**kwargs) | ||
|
||
return _build_response(client=client, response=response) |
This file contains 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 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.