From c7a9a70c6930fb9eb6ecf5336d515b6c704c5a44 Mon Sep 17 00:00:00 2001 From: Ethan Mann Date: Mon, 10 Aug 2020 18:51:44 -0400 Subject: [PATCH 1/3] Added support for Header parameters (#117) --- end_to_end_tests/fastapi_app/__init__.py | 4 ++-- end_to_end_tests/fastapi_app/openapi.json | 11 ++++++++++ .../my_test_api_client/api/default.py | 4 +++- .../my_test_api_client/api/tests.py | 12 ++++++++--- .../my_test_api_client/async_api/default.py | 4 +++- .../my_test_api_client/async_api/tests.py | 12 ++++++++--- openapi_python_client/__init__.py | 2 +- openapi_python_client/parser/openapi.py | 4 ++++ .../templates/async_endpoint_module.pyi | 10 ++++++++-- .../templates/endpoint_macros.pyi | 13 ++++++++++++ .../templates/endpoint_module.pyi | 10 ++++++++-- openapi_python_client/utils.py | 4 ++++ tests/test_openapi_parser/test_openapi.py | 20 +++++++++++++------ tests/test_templates/async_endpoint_module.py | 15 ++++++++++++-- tests/test_templates/conftest.py | 2 +- .../test_async_endpoint_module.py | 4 ++++ tests/test_utils.py | 4 ++++ 17 files changed, 111 insertions(+), 24 deletions(-) diff --git a/end_to_end_tests/fastapi_app/__init__.py b/end_to_end_tests/fastapi_app/__init__.py index 8bccdeec2..d21ffa11c 100644 --- a/end_to_end_tests/fastapi_app/__init__.py +++ b/end_to_end_tests/fastapi_app/__init__.py @@ -5,7 +5,7 @@ from pathlib import Path from typing import Any, Dict, List, Union -from fastapi import APIRouter, FastAPI, File, Query, UploadFile +from fastapi import APIRouter, FastAPI, File, Header, Query, UploadFile from pydantic import BaseModel app = FastAPI(title="My Test API", description="An API for testing openapi-python-client",) @@ -55,7 +55,7 @@ def get_list(an_enum_value: List[AnEnum] = Query(...), some_date: Union[date, da @test_router.post("/upload") -async def upload_file(some_file: UploadFile = File(...)): +async def upload_file(some_file: UploadFile = File(...), keep_alive: bool = Header(None)): """ Upload a file """ data = await some_file.read() return (some_file.filename, some_file.content_type, data) diff --git a/end_to_end_tests/fastapi_app/openapi.json b/end_to_end_tests/fastapi_app/openapi.json index 4c3a796ff..cbea33f25 100644 --- a/end_to_end_tests/fastapi_app/openapi.json +++ b/end_to_end_tests/fastapi_app/openapi.json @@ -102,6 +102,17 @@ "summary": "Upload File", "description": "Upload a file ", "operationId": "upload_file_tests_upload_post", + "parameters": [ + { + "required": false, + "schema": { + "title": "Keep-Alive", + "type": "boolean" + }, + "name": "keep-alive", + "in": "header" + } + ], "requestBody": { "content": { "multipart/form-data": { diff --git a/end_to_end_tests/golden-master/my_test_api_client/api/default.py b/end_to_end_tests/golden-master/my_test_api_client/api/default.py index 0fcd73d77..7f2e8be4a 100644 --- a/end_to_end_tests/golden-master/my_test_api_client/api/default.py +++ b/end_to_end_tests/golden-master/my_test_api_client/api/default.py @@ -12,7 +12,9 @@ def ping_ping_get(*, client: Client,) -> bool: """ A quick check to see if the system is running """ url = "{}/ping".format(client.base_url) - response = httpx.get(url=url, headers=client.get_headers(),) + headers = client.get_headers() + + response = httpx.get(url=url, headers=headers,) if response.status_code == 200: return bool(response.text) diff --git a/end_to_end_tests/golden-master/my_test_api_client/api/tests.py b/end_to_end_tests/golden-master/my_test_api_client/api/tests.py index 68d7d087d..cb386f505 100644 --- a/end_to_end_tests/golden-master/my_test_api_client/api/tests.py +++ b/end_to_end_tests/golden-master/my_test_api_client/api/tests.py @@ -21,6 +21,8 @@ def get_user_list( """ Get a list of things """ url = "{}/tests/".format(client.base_url) + headers = client.get_headers() + json_an_enum_value = [] for an_enum_value_item_data in an_enum_value: an_enum_value_item = an_enum_value_item_data.value @@ -38,7 +40,7 @@ def get_user_list( "some_date": json_some_date, } - response = httpx.get(url=url, headers=client.get_headers(), params=params,) + response = httpx.get(url=url, headers=headers, params=params,) if response.status_code == 200: return [AModel.from_dict(item) for item in cast(List[Dict[str, Any]], response.json())] @@ -49,7 +51,7 @@ def get_user_list( def upload_file_tests_upload_post( - *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, + *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, keep_alive: Optional[bool] = None, ) -> Union[ None, HTTPValidationError, ]: @@ -57,7 +59,11 @@ def upload_file_tests_upload_post( """ Upload a file """ url = "{}/tests/upload".format(client.base_url) - response = httpx.post(url=url, headers=client.get_headers(), files=multipart_data.to_dict(),) + headers = client.get_headers() + if keep_alive is not None: + headers["keep-alive"] = keep_alive + + response = httpx.post(url=url, headers=headers, files=multipart_data.to_dict(),) if response.status_code == 200: return None diff --git a/end_to_end_tests/golden-master/my_test_api_client/async_api/default.py b/end_to_end_tests/golden-master/my_test_api_client/async_api/default.py index 30f61ecc5..591ca262d 100644 --- a/end_to_end_tests/golden-master/my_test_api_client/async_api/default.py +++ b/end_to_end_tests/golden-master/my_test_api_client/async_api/default.py @@ -12,8 +12,10 @@ async def ping_ping_get(*, client: Client,) -> bool: """ A quick check to see if the system is running """ url = "{}/ping".format(client.base_url,) + headers = client.get_headers() + async with httpx.AsyncClient() as _client: - response = await _client.get(url=url, headers=client.get_headers(),) + response = await _client.get(url=url, headers=headers,) if response.status_code == 200: return bool(response.text) diff --git a/end_to_end_tests/golden-master/my_test_api_client/async_api/tests.py b/end_to_end_tests/golden-master/my_test_api_client/async_api/tests.py index 19dfb3f8c..c0e738c7d 100644 --- a/end_to_end_tests/golden-master/my_test_api_client/async_api/tests.py +++ b/end_to_end_tests/golden-master/my_test_api_client/async_api/tests.py @@ -21,6 +21,8 @@ async def get_user_list( """ Get a list of things """ url = "{}/tests/".format(client.base_url,) + headers = client.get_headers() + json_an_enum_value = [] for an_enum_value_item_data in an_enum_value: an_enum_value_item = an_enum_value_item_data.value @@ -39,7 +41,7 @@ async def get_user_list( } async with httpx.AsyncClient() as _client: - response = await _client.get(url=url, headers=client.get_headers(), params=params,) + response = await _client.get(url=url, headers=headers, params=params,) if response.status_code == 200: return [AModel.from_dict(item) for item in cast(List[Dict[str, Any]], response.json())] @@ -50,7 +52,7 @@ async def get_user_list( async def upload_file_tests_upload_post( - *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, + *, client: Client, multipart_data: BodyUploadFileTestsUploadPost, keep_alive: Optional[bool] = None, ) -> Union[ None, HTTPValidationError, ]: @@ -58,8 +60,12 @@ async def upload_file_tests_upload_post( """ Upload a file """ url = "{}/tests/upload".format(client.base_url,) + headers = client.get_headers() + if keep_alive is not None: + headers["keep-alive"] = keep_alive + async with httpx.AsyncClient() as _client: - response = await _client.post(url=url, headers=client.get_headers(), files=multipart_data.to_dict(),) + response = await _client.post(url=url, headers=headers, files=multipart_data.to_dict(),) if response.status_code == 200: return None diff --git a/openapi_python_client/__init__.py b/openapi_python_client/__init__.py index c4ed2d7ef..8c3c65f08 100644 --- a/openapi_python_client/__init__.py +++ b/openapi_python_client/__init__.py @@ -83,7 +83,7 @@ def _get_document(*, url: Optional[str], path: Optional[Path]) -> Union[Dict[str class Project: - TEMPLATE_FILTERS = {"snakecase": utils.snake_case} + TEMPLATE_FILTERS = {"snakecase": utils.snake_case, "spinalcase": utils.spinal_case} project_name_override: Optional[str] = None package_name_override: Optional[str] = None diff --git a/openapi_python_client/parser/openapi.py b/openapi_python_client/parser/openapi.py index c4a6e1b67..9f100d3b2 100644 --- a/openapi_python_client/parser/openapi.py +++ b/openapi_python_client/parser/openapi.py @@ -19,6 +19,7 @@ class ParameterLocation(str, Enum): QUERY = "query" PATH = "path" + HEADER = "header" def import_string_from_reference(reference: Reference, prefix: str = "") -> str: @@ -78,6 +79,7 @@ class Endpoint: relative_imports: Set[str] = field(default_factory=set) query_parameters: List[Property] = field(default_factory=list) path_parameters: List[Property] = field(default_factory=list) + header_parameters: List[Property] = field(default_factory=list) responses: List[Response] = field(default_factory=list) form_body_reference: Optional[Reference] = None json_body: Optional[Property] = None @@ -164,6 +166,8 @@ def _add_parameters(endpoint: Endpoint, data: oai.Operation) -> Union[Endpoint, endpoint.query_parameters.append(prop) elif param.param_in == ParameterLocation.PATH: endpoint.path_parameters.append(prop) + elif param.param_in == ParameterLocation.HEADER: + endpoint.header_parameters.append(prop) else: return ParseError(data=param, detail="Parameter must be declared in path or query") return endpoint diff --git a/openapi_python_client/templates/async_endpoint_module.pyi b/openapi_python_client/templates/async_endpoint_module.pyi index 4119f0651..0834a88d6 100644 --- a/openapi_python_client/templates/async_endpoint_module.pyi +++ b/openapi_python_client/templates/async_endpoint_module.pyi @@ -11,7 +11,7 @@ from ..errors import ApiResponseError {% endfor %} {% for endpoint in collection.endpoints %} -{% from "endpoint_macros.pyi" import query_params, json_body, return_type %} +{% from "endpoint_macros.pyi" import header_params, query_params, json_body, return_type %} async def {{ endpoint.name | snakecase }}( *, @@ -41,6 +41,9 @@ async def {{ endpoint.name | snakecase }}( {% for parameter in endpoint.query_parameters %} {{ parameter.to_string() }}, {% endfor %} + {% for parameter in endpoint.header_parameters %} + {{ parameter.to_string() }}, + {% endfor %} {{ return_type(endpoint) }} """ {{ endpoint.description }} """ url = "{}{{ endpoint.path }}".format( @@ -50,13 +53,16 @@ async def {{ endpoint.name | snakecase }}( {% endfor %} ) + headers = client.get_headers() + {{ header_params(endpoint) | indent(4) }} + {{ query_params(endpoint) | indent(4) }} {{ json_body(endpoint) | indent(4) }} async with httpx.AsyncClient() as _client: response = await _client.{{ endpoint.method }}( url=url, - headers=client.get_headers(), + headers=headers, {% if endpoint.form_body_reference %} data=asdict(form_data), {% endif %} diff --git a/openapi_python_client/templates/endpoint_macros.pyi b/openapi_python_client/templates/endpoint_macros.pyi index 968bcfbf9..555968e41 100644 --- a/openapi_python_client/templates/endpoint_macros.pyi +++ b/openapi_python_client/templates/endpoint_macros.pyi @@ -1,3 +1,16 @@ +{% macro header_params(endpoint) %} +{% if endpoint.header_parameters %} + {% for parameter in endpoint.header_parameters %} + {% if parameter.required %} +headers["{{ parameter.python_name | spinalcase}}"] = {{ parameter.python_name }} + {% else %} +if {{ parameter.python_name }} is not None: + headers["{{ parameter.python_name | spinalcase}}"] = {{ parameter.python_name }} + {% endif %} + {% endfor %} +{% endif %} +{% endmacro %} + {% macro query_params(endpoint) %} {% if endpoint.query_parameters %} {% for property in endpoint.query_parameters %} diff --git a/openapi_python_client/templates/endpoint_module.pyi b/openapi_python_client/templates/endpoint_module.pyi index a61d51495..515fb0673 100644 --- a/openapi_python_client/templates/endpoint_module.pyi +++ b/openapi_python_client/templates/endpoint_module.pyi @@ -11,7 +11,7 @@ from ..errors import ApiResponseError {% endfor %} {% for endpoint in collection.endpoints %} -{% from "endpoint_macros.pyi" import query_params, json_body, return_type %} +{% from "endpoint_macros.pyi" import header_params, query_params, json_body, return_type %} def {{ endpoint.name | snakecase }}( *, @@ -41,6 +41,9 @@ def {{ endpoint.name | snakecase }}( {% for parameter in endpoint.query_parameters %} {{ parameter.to_string() }}, {% endfor %} + {% for parameter in endpoint.header_parameters %} + {{ parameter.to_string() }}, + {% endfor %} {{ return_type(endpoint) }} """ {{ endpoint.description }} """ url = "{}{{ endpoint.path }}".format( @@ -50,6 +53,9 @@ def {{ endpoint.name | snakecase }}( {%- endfor -%} ) + headers = client.get_headers() + {{ header_params(endpoint) | indent(4) }} + {{ query_params(endpoint) | indent(4) }} {{ json_body(endpoint) | indent(4) }} @@ -57,7 +63,7 @@ def {{ endpoint.name | snakecase }}( response = httpx.{{ endpoint.method }}( url=url, - headers=client.get_headers(), + headers=headers, {% if endpoint.form_body_reference %} data=asdict(form_data), {% endif %} diff --git a/openapi_python_client/utils.py b/openapi_python_client/utils.py index bce831deb..09ab12e02 100644 --- a/openapi_python_client/utils.py +++ b/openapi_python_client/utils.py @@ -11,3 +11,7 @@ def snake_case(value: str) -> str: def pascal_case(value: str) -> str: return stringcase.pascalcase(value) + + +def spinal_case(value: str) -> str: + return stringcase.spinalcase(value) diff --git a/tests/test_openapi_parser/test_openapi.py b/tests/test_openapi_parser/test_openapi.py index e1543e7fe..b025e7391 100644 --- a/tests/test_openapi_parser/test_openapi.py +++ b/tests/test_openapi_parser/test_openapi.py @@ -452,9 +452,15 @@ def test__add_parameters_happy(self, mocker): query_prop = mocker.MagicMock(autospec=Property) query_prop_import = mocker.MagicMock() query_prop.get_imports = mocker.MagicMock(return_value={query_prop_import}) - property_from_data = mocker.patch(f"{MODULE_NAME}.property_from_data", side_effect=[path_prop, query_prop]) + header_prop = mocker.MagicMock(autospec=Property) + header_prop_import = mocker.MagicMock() + header_prop.get_imports = mocker.MagicMock(return_value={header_prop_import}) + property_from_data = mocker.patch( + f"{MODULE_NAME}.property_from_data", side_effect=[path_prop, query_prop, header_prop] + ) path_schema = mocker.MagicMock() query_schema = mocker.MagicMock() + header_schema = mocker.MagicMock() data = oai.Operation.construct( parameters=[ oai.Parameter.construct( @@ -463,6 +469,9 @@ def test__add_parameters_happy(self, mocker): oai.Parameter.construct( name="query_prop_name", required=False, param_schema=query_schema, param_in="query" ), + oai.Parameter.construct( + name="header_prop_name", required=False, param_schema=header_schema, param_in="header" + ), oai.Reference.construct(), # Should be ignored oai.Parameter.construct(), # Should be ignored ] @@ -474,17 +483,16 @@ def test__add_parameters_happy(self, mocker): [ mocker.call(name="path_prop_name", required=True, data=path_schema), mocker.call(name="query_prop_name", required=False, data=query_schema), + mocker.call(name="header_prop_name", required=False, data=header_schema), ] ) path_prop.get_imports.assert_called_once_with(prefix="..models") query_prop.get_imports.assert_called_once_with(prefix="..models") - assert endpoint.relative_imports == { - "import_3", - path_prop_import, - query_prop_import, - } + header_prop.get_imports.assert_called_once_with(prefix="..models") + assert endpoint.relative_imports == {"import_3", path_prop_import, query_prop_import, header_prop_import} assert endpoint.path_parameters == [path_prop] assert endpoint.query_parameters == [query_prop] + assert endpoint.header_parameters == [header_prop] def test_from_data_bad_params(self, mocker): from openapi_python_client.parser.openapi import Endpoint diff --git a/tests/test_templates/async_endpoint_module.py b/tests/test_templates/async_endpoint_module.py index 106fdfb7d..ead88c229 100644 --- a/tests/test_templates/async_endpoint_module.py +++ b/tests/test_templates/async_endpoint_module.py @@ -15,6 +15,7 @@ async def pascal_case( client: Client, path_param_1: str, query_param_1: str, + header_param_1: str, ) -> str: """ GET endpoint """ @@ -23,13 +24,17 @@ async def pascal_case( pathParam1=path_param_1, ) + headers = client.get_headers() + headers["header-param-1"] = header_param_1 + + params: Dict[str, Any] = { "queryParam": query_param_1, } async with httpx.AsyncClient() as _client: response = await _client.get( url=url, - headers=client.get_headers(), + headers=headers, params=params, ) @@ -55,10 +60,16 @@ async def camel_case( client.base_url, ) + headers = client.get_headers() + + + + + async with httpx.AsyncClient() as _client: response = await _client.post( url=url, - headers=client.get_headers(), + headers=headers, data=asdict(form_data), files=multipart_data.to_dict(), json=json_json_body, diff --git a/tests/test_templates/conftest.py b/tests/test_templates/conftest.py index 14e828d6c..a11db3cd1 100644 --- a/tests/test_templates/conftest.py +++ b/tests/test_templates/conftest.py @@ -6,7 +6,7 @@ def env() -> Environment: from openapi_python_client import utils - TEMPLATE_FILTERS = {"snakecase": utils.snake_case} + TEMPLATE_FILTERS = {"snakecase": utils.snake_case, "spinalcase": utils.spinal_case} env = Environment(loader=PackageLoader("openapi_python_client"), trim_blocks=True, lstrip_blocks=True) env.filters.update(TEMPLATE_FILTERS) return env diff --git a/tests/test_templates/test_async_endpoint_module.py b/tests/test_templates/test_async_endpoint_module.py index 5318b713e..f123bf4e0 100644 --- a/tests/test_templates/test_async_endpoint_module.py +++ b/tests/test_templates/test_async_endpoint_module.py @@ -16,6 +16,9 @@ def test_async_endpoint_module(template, mocker): query_param = mocker.MagicMock(template=None, python_name="query_param_1") query_param.name = "queryParam" query_param.to_string.return_value = "query_param_1: str" + header_param = mocker.MagicMock(template=None, python_name="header_param_1") + header_param.name = "headerParam" + header_param.to_string.return_value = "header_param_1: str" get_response = mocker.MagicMock(status_code=200) get_response.return_string.return_value = "str" get_response.constructor.return_value = "str(response.text)" @@ -23,6 +26,7 @@ def test_async_endpoint_module(template, mocker): requires_security=False, path_parameters=[path_param], query_parameters=[query_param], + header_parameters=[header_param], form_body_reference=None, multipart_body_reference=None, json_body=None, diff --git a/tests/test_utils.py b/tests/test_utils.py index e7effdc77..a7aa0942f 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -18,3 +18,7 @@ def test_snake_case_from_pascal(): def test_snake_case_from_camel(): assert utils.snake_case("httpResponseLowerCamel") == "http_response_lower_camel" + + +def test_spinal_case(): + assert utils.spinal_case("keep_alive") == "keep-alive" From 13a3556938485f6855f4f107dd1a640ffacad0ff Mon Sep 17 00:00:00 2001 From: Ethan Mann Date: Mon, 10 Aug 2020 19:03:34 -0400 Subject: [PATCH 2/3] Fixed header dict typing in templates + updated changelog --- CHANGELOG.md | 3 +++ .../golden-master/my_test_api_client/api/default.py | 2 +- .../golden-master/my_test_api_client/api/tests.py | 8 +++++--- .../golden-master/my_test_api_client/async_api/default.py | 2 +- .../golden-master/my_test_api_client/async_api/tests.py | 8 +++++--- openapi_python_client/templates/async_endpoint_module.pyi | 2 +- openapi_python_client/templates/endpoint_module.pyi | 2 +- pyproject.toml | 5 +++++ tests/test_templates/async_endpoint_module.py | 4 ++-- 9 files changed, 24 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 27341ec60..216abaf9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 0.5.3 - Unrelease +### Additions +- Added support for header parameters (#117) + ### Fixes - JSON bodies will now be assigned correctly in generated clients(#139 & #147). Thanks @pawamoy! diff --git a/end_to_end_tests/golden-master/my_test_api_client/api/default.py b/end_to_end_tests/golden-master/my_test_api_client/api/default.py index 7f2e8be4a..b79ce6cfd 100644 --- a/end_to_end_tests/golden-master/my_test_api_client/api/default.py +++ b/end_to_end_tests/golden-master/my_test_api_client/api/default.py @@ -12,7 +12,7 @@ def ping_ping_get(*, client: Client,) -> bool: """ A quick check to see if the system is running """ url = "{}/ping".format(client.base_url) - headers = client.get_headers() + headers: Dict[str, Any] = client.get_headers() response = httpx.get(url=url, headers=headers,) diff --git a/end_to_end_tests/golden-master/my_test_api_client/api/tests.py b/end_to_end_tests/golden-master/my_test_api_client/api/tests.py index cb386f505..3f7d094b4 100644 --- a/end_to_end_tests/golden-master/my_test_api_client/api/tests.py +++ b/end_to_end_tests/golden-master/my_test_api_client/api/tests.py @@ -21,7 +21,7 @@ def get_user_list( """ Get a list of things """ url = "{}/tests/".format(client.base_url) - headers = client.get_headers() + headers: Dict[str, Any] = client.get_headers() json_an_enum_value = [] for an_enum_value_item_data in an_enum_value: @@ -59,7 +59,7 @@ def upload_file_tests_upload_post( """ Upload a file """ url = "{}/tests/upload".format(client.base_url) - headers = client.get_headers() + headers: Dict[str, Any] = client.get_headers() if keep_alive is not None: headers["keep-alive"] = keep_alive @@ -82,9 +82,11 @@ def json_body_tests_json_body_post( """ Try sending a JSON body """ url = "{}/tests/json_body".format(client.base_url) + headers: Dict[str, Any] = client.get_headers() + json_json_body = json_body.to_dict() - response = httpx.post(url=url, headers=client.get_headers(), json=json_json_body,) + response = httpx.post(url=url, headers=headers, json=json_json_body,) if response.status_code == 200: return None diff --git a/end_to_end_tests/golden-master/my_test_api_client/async_api/default.py b/end_to_end_tests/golden-master/my_test_api_client/async_api/default.py index 591ca262d..33930bd68 100644 --- a/end_to_end_tests/golden-master/my_test_api_client/async_api/default.py +++ b/end_to_end_tests/golden-master/my_test_api_client/async_api/default.py @@ -12,7 +12,7 @@ async def ping_ping_get(*, client: Client,) -> bool: """ A quick check to see if the system is running """ url = "{}/ping".format(client.base_url,) - headers = client.get_headers() + headers: Dict[str, Any] = client.get_headers() async with httpx.AsyncClient() as _client: response = await _client.get(url=url, headers=headers,) diff --git a/end_to_end_tests/golden-master/my_test_api_client/async_api/tests.py b/end_to_end_tests/golden-master/my_test_api_client/async_api/tests.py index c0e738c7d..11bb66085 100644 --- a/end_to_end_tests/golden-master/my_test_api_client/async_api/tests.py +++ b/end_to_end_tests/golden-master/my_test_api_client/async_api/tests.py @@ -21,7 +21,7 @@ async def get_user_list( """ Get a list of things """ url = "{}/tests/".format(client.base_url,) - headers = client.get_headers() + headers: Dict[str, Any] = client.get_headers() json_an_enum_value = [] for an_enum_value_item_data in an_enum_value: @@ -60,7 +60,7 @@ async def upload_file_tests_upload_post( """ Upload a file """ url = "{}/tests/upload".format(client.base_url,) - headers = client.get_headers() + headers: Dict[str, Any] = client.get_headers() if keep_alive is not None: headers["keep-alive"] = keep_alive @@ -84,10 +84,12 @@ async def json_body_tests_json_body_post( """ Try sending a JSON body """ url = "{}/tests/json_body".format(client.base_url,) + headers: Dict[str, Any] = client.get_headers() + json_json_body = json_body.to_dict() async with httpx.AsyncClient() as _client: - response = await _client.post(url=url, headers=client.get_headers(), json=json_json_body,) + response = await _client.post(url=url, headers=headers, json=json_json_body,) if response.status_code == 200: return None diff --git a/openapi_python_client/templates/async_endpoint_module.pyi b/openapi_python_client/templates/async_endpoint_module.pyi index 0834a88d6..38836ec07 100644 --- a/openapi_python_client/templates/async_endpoint_module.pyi +++ b/openapi_python_client/templates/async_endpoint_module.pyi @@ -53,7 +53,7 @@ async def {{ endpoint.name | snakecase }}( {% endfor %} ) - headers = client.get_headers() + headers: Dict[str, Any] = client.get_headers() {{ header_params(endpoint) | indent(4) }} {{ query_params(endpoint) | indent(4) }} diff --git a/openapi_python_client/templates/endpoint_module.pyi b/openapi_python_client/templates/endpoint_module.pyi index 515fb0673..ba913f647 100644 --- a/openapi_python_client/templates/endpoint_module.pyi +++ b/openapi_python_client/templates/endpoint_module.pyi @@ -53,7 +53,7 @@ def {{ endpoint.name | snakecase }}( {%- endfor -%} ) - headers = client.get_headers() + headers: Dict[str, Any] = client.get_headers() {{ header_params(endpoint) | indent(4) }} {{ query_params(endpoint) | indent(4) }} diff --git a/pyproject.toml b/pyproject.toml index 4d2a3c383..fb2860381 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -58,6 +58,11 @@ isort .\ openapi = "python -m end_to_end_tests.fastapi_app" gm = "python -m end_to_end_tests.regen_golden_master" e2e = "pytest openapi_python_client end_to_end_tests" +oge = """ +python -m end_to_end_tests.fastapi_app\ +&& python -m end_to_end_tests.regen_golden_master\ +&& pytest openapi_python_client end_to_end_tests\ +""" [tool.black] line-length = 120 diff --git a/tests/test_templates/async_endpoint_module.py b/tests/test_templates/async_endpoint_module.py index ead88c229..793a7b349 100644 --- a/tests/test_templates/async_endpoint_module.py +++ b/tests/test_templates/async_endpoint_module.py @@ -24,7 +24,7 @@ async def pascal_case( pathParam1=path_param_1, ) - headers = client.get_headers() + headers: Dict[str, Any] = client.get_headers() headers["header-param-1"] = header_param_1 @@ -60,7 +60,7 @@ async def camel_case( client.base_url, ) - headers = client.get_headers() + headers: Dict[str, Any] = client.get_headers() From 58677474360c092c5c0708f29e28dc1827b42d18 Mon Sep 17 00:00:00 2001 From: Ethan Mann Date: Tue, 11 Aug 2020 09:18:47 -0400 Subject: [PATCH 3/3] task oge now uses the other tasks instead of copying their commands --- pyproject.toml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index fb2860381..f19f3dcac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -59,9 +59,9 @@ openapi = "python -m end_to_end_tests.fastapi_app" gm = "python -m end_to_end_tests.regen_golden_master" e2e = "pytest openapi_python_client end_to_end_tests" oge = """ -python -m end_to_end_tests.fastapi_app\ -&& python -m end_to_end_tests.regen_golden_master\ -&& pytest openapi_python_client end_to_end_tests\ +task openapi\ +&& task gm\ +&& task e2e\ """ [tool.black]