Skip to content

Commit 6f87a3c

Browse files
committed
Add support for more basic response types
- Closes #43 - Adds support for int, float, and bool response types from endpoints.
1 parent 7de3a02 commit 6f87a3c

File tree

16 files changed

+84
-101
lines changed

16 files changed

+84
-101
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1818
- Support for multipart/form bodies
1919
- Support for any supported property within a list (array), including other lists.
2020
- Support for Union types ("anyOf" in OpenAPI document)
21+
- Support for more basic response types (integer, number, boolean)
2122
- Better error messages when failing to parse an OpenAPI document
2223

2324
### Changes

end_to_end_tests/fastapi_app/__init__.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,10 @@
1111
app = FastAPI(title="My Test API", description="An API for testing openapi-python-client",)
1212

1313

14-
class _ABCResponse(BaseModel):
15-
success: bool
16-
17-
18-
@app.get("/ping", response_model=_ABCResponse)
14+
@app.get("/ping", response_model=bool)
1915
async def ping():
2016
""" A quick check to see if the system is running """
21-
return {"success": True}
17+
return True
2218

2319

2420
test_router = APIRouter()

end_to_end_tests/fastapi_app/openapi.json

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@
1717
"content": {
1818
"application/json": {
1919
"schema": {
20-
"$ref": "#/components/schemas/_ABCResponse"
20+
"title": "Response Ping Ping Get",
21+
"type": "boolean"
2122
}
2223
}
2324
}
@@ -242,19 +243,6 @@
242243
"type": "string"
243244
}
244245
}
245-
},
246-
"_ABCResponse": {
247-
"title": "_ABCResponse",
248-
"required": [
249-
"success"
250-
],
251-
"type": "object",
252-
"properties": {
253-
"success": {
254-
"title": "Success",
255-
"type": "boolean"
256-
}
257-
}
258246
}
259247
}
260248
}

end_to_end_tests/golden-master/my_test_api_client/api/default.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,16 @@
55

66
from ..client import AuthenticatedClient, Client
77
from ..errors import ApiResponseError
8-
from ..models.abc_response import ABCResponse
98

109

11-
def ping_ping_get(
12-
*, client: Client,
13-
) -> Union[
14-
ABCResponse,
15-
]:
10+
def ping_ping_get(*, client: Client,) -> bool:
11+
1612
""" A quick check to see if the system is running """
1713
url = "{}/ping".format(client.base_url)
1814

1915
response = httpx.get(url=url, headers=client.get_headers(),)
2016

2117
if response.status_code == 200:
22-
return ABCResponse.from_dict(cast(Dict[str, Any], response.json()))
18+
return bool(response.text)
2319
else:
2420
raise ApiResponseError(response=response)

end_to_end_tests/golden-master/my_test_api_client/api/users.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def get_user_list(
1717
) -> Union[
1818
List[AModel], HTTPValidationError,
1919
]:
20+
2021
""" Get a list of things """
2122
url = "{}/tests/".format(client.base_url)
2223

@@ -52,6 +53,7 @@ def upload_file_tests_upload_post(
5253
) -> Union[
5354
None, HTTPValidationError,
5455
]:
56+
5557
""" Upload a file """
5658
url = "{}/tests/upload".format(client.base_url)
5759

end_to_end_tests/golden-master/my_test_api_client/async_api/default.py

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,21 +5,17 @@
55

66
from ..client import AuthenticatedClient, Client
77
from ..errors import ApiResponseError
8-
from ..models.abc_response import ABCResponse
98

109

11-
async def ping_ping_get(
12-
*, client: Client,
13-
) -> Union[
14-
ABCResponse,
15-
]:
10+
async def ping_ping_get(*, client: Client,) -> bool:
11+
1612
""" A quick check to see if the system is running """
1713
url = "{}/ping".format(client.base_url)
1814

1915
async with httpx.AsyncClient() as _client:
2016
response = await _client.get(url=url, headers=client.get_headers(),)
2117

2218
if response.status_code == 200:
23-
return ABCResponse.from_dict(cast(Dict[str, Any], response.json()))
19+
return bool(response.text)
2420
else:
2521
raise ApiResponseError(response=response)

end_to_end_tests/golden-master/my_test_api_client/async_api/users.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ async def get_user_list(
1717
) -> Union[
1818
List[AModel], HTTPValidationError,
1919
]:
20+
2021
""" Get a list of things """
2122
url = "{}/tests/".format(client.base_url)
2223

@@ -53,6 +54,7 @@ async def upload_file_tests_upload_post(
5354
) -> Union[
5455
None, HTTPValidationError,
5556
]:
57+
5658
""" Upload a file """
5759
url = "{}/tests/upload".format(client.base_url)
5860

end_to_end_tests/golden-master/my_test_api_client/models/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
""" Contains all the data models used in inputs/outputs """
22

33
from .a_model import AModel
4-
from .abc_response import ABCResponse
54
from .an_enum_value import AnEnumValue
65
from .an_enum_value_item import AnEnumValueItem
76
from .body_upload_file_tests_upload_post import BodyUploadFileTestsUploadPost

end_to_end_tests/golden-master/my_test_api_client/models/abc_response.py

Lines changed: 0 additions & 24 deletions
This file was deleted.

end_to_end_tests/regen_golden_master.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
config_path = Path(__file__).parent / "config.yml"
2020

2121
result = runner.invoke(app, [f"--config={config_path}", "generate", f"--path={openapi_path}"])
22+
if result.stdout:
23+
print(result.stdout)
2224
if result.exception:
2325
raise result.exception
2426
output_path.rename(gm_path)

0 commit comments

Comments
 (0)