From 75ed52f8756f8794d36541206e98144fae22ca55 Mon Sep 17 00:00:00 2001 From: Paul Hallett Date: Thu, 26 Oct 2023 10:46:53 +1300 Subject: [PATCH] Correct serialziation alias --- CHANGELOG.md | 1 + clientele/generators/standard/generators/schemas.py | 2 +- docs/CHANGELOG.md | 1 + docs/examples.md | 2 +- tests/test_generated_client.py | 5 ++++- 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3d6809c..f6a2802 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - Improved support for Async clients which prevents a weird bug when running more than one event loop. Based on the suggestions from [this httpx issue](https://github.com/encode/httpcore/discussions/659). - We now use [`ruff format`](https://astral.sh/blog/the-ruff-formatter) for coding formatting (not the client output). - `Decimal` support now extends to Decimal input values. +- Input and Output schemas will now have properties that directly match those provided by the OpenAPI schema. This fixes a bug where previously, the snake-case formatting did not match up with what the API expected to send or receive. ## 0.7.1 diff --git a/clientele/generators/standard/generators/schemas.py b/clientele/generators/standard/generators/schemas.py index e7ed153..edb853f 100644 --- a/clientele/generators/standard/generators/schemas.py +++ b/clientele/generators/standard/generators/schemas.py @@ -63,7 +63,7 @@ def generate_class_properties(self, properties: dict, required: Optional[list] = arg_type = utils.get_type(arg_details) is_optional = required and arg not in required type_string = is_optional and f"typing.Optional[{arg_type}]" or arg_type - content = content + f""" {utils.snake_case_prop(arg)}: {type_string}\n""" + content = content + f""" {arg}: {type_string}\n""" return content def generate_input_class(self, schema: dict) -> None: diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 3d6809c..f6a2802 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -5,6 +5,7 @@ - Improved support for Async clients which prevents a weird bug when running more than one event loop. Based on the suggestions from [this httpx issue](https://github.com/encode/httpcore/discussions/659). - We now use [`ruff format`](https://astral.sh/blog/the-ruff-formatter) for coding formatting (not the client output). - `Decimal` support now extends to Decimal input values. +- Input and Output schemas will now have properties that directly match those provided by the OpenAPI schema. This fixes a bug where previously, the snake-case formatting did not match up with what the API expected to send or receive. ## 0.7.1 diff --git a/docs/examples.md b/docs/examples.md index 83cc68b..737f90d 100644 --- a/docs/examples.md +++ b/docs/examples.md @@ -145,7 +145,7 @@ The `response` object will be attached to this exception class for your own debu ## Schemas -The `schemas.py` file has all the possible schemas, request and response, and even Enums, for the API. These are taken from OpenAPI's schemas objects and turned into Python classes. They are all subclassed from pydantic's `BaseModel`. +The `schemas.py` file has all the possible schemas, request and response, and even Enums, for the API. These are taken from OpenAPI's schemas objects and turned into Python classes. They are all subclassed from pydantic's `BaseModel`. Here are a few examples: diff --git a/tests/test_generated_client.py b/tests/test_generated_client.py index c954448..2999dd2 100644 --- a/tests/test_generated_client.py +++ b/tests/test_generated_client.py @@ -152,7 +152,10 @@ def test_request_data_request_data_post(respx_mock: MockRouter): mock_path = "/request-data" respx_mock.post(mock_path).mock(return_value=Response(json=mocked_response, status_code=200)) # When - data = schemas.RequestDataRequest(my_input="test", my_decimal_input=Decimal(0.1)) + data = schemas.RequestDataRequest( + my_input="test", + my_decimal_input=Decimal(0.1), + ) response = client.request_data_request_data_post(data=data) # Then assert isinstance(response, schemas.RequestDataResponse)