[python][Feat] Deserialize error responses (#17038)

* refactor: Clean up _response_types_map formatting

It matches black's behavior of having trailing commas now.

* test: Add test to reproduce #16967

* fix: deserialize responses even if no returnType

Closes #16967

* refactor: Simplify ApiException subclasses

* refactor: Move exception subtype choice to ApiException

* feat: Deserialize error responses and add to exceptions

* test: Add for error responses with model
This commit is contained in:
Robert Schweizer
2023-11-15 17:37:04 +01:00
committed by GitHub
parent 69fcfeff38
commit e47e7041f7
85 changed files with 4309 additions and 951 deletions

View File

@@ -84,6 +84,8 @@ docs/SpecialModelName.md
docs/SpecialName.md
docs/StoreApi.md
docs/Tag.md
docs/TestErrorResponsesWithModel400Response.md
docs/TestErrorResponsesWithModel404Response.md
docs/TestInlineFreeformAdditionalPropertiesRequest.md
docs/Tiger.md
docs/UnnamedDictWithAdditionalModelListProperties.md
@@ -181,6 +183,8 @@ petstore_api/models/special_character_enum.py
petstore_api/models/special_model_name.py
petstore_api/models/special_name.py
petstore_api/models/tag.py
petstore_api/models/test_error_responses_with_model400_response.py
petstore_api/models/test_error_responses_with_model404_response.py
petstore_api/models/test_inline_freeform_additional_properties_request.py
petstore_api/models/tiger.py
petstore_api/models/unnamed_dict_with_additional_model_list_properties.py

View File

@@ -103,7 +103,9 @@ Class | Method | HTTP request | Description
*FakeApi* | [**test_body_with_query_params**](docs/FakeApi.md#test_body_with_query_params) | **PUT** /fake/body-with-query-params |
*FakeApi* | [**test_client_model**](docs/FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model
*FakeApi* | [**test_date_time_query_parameter**](docs/FakeApi.md#test_date_time_query_parameter) | **PUT** /fake/date-time-query-params |
*FakeApi* | [**test_empty_and_non_empty_responses**](docs/FakeApi.md#test_empty_and_non_empty_responses) | **POST** /fake/empty_and_non_empty_responses | test empty and non-empty responses
*FakeApi* | [**test_endpoint_parameters**](docs/FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
*FakeApi* | [**test_error_responses_with_model**](docs/FakeApi.md#test_error_responses_with_model) | **POST** /fake/error_responses_with_model | test error responses with model
*FakeApi* | [**test_group_parameters**](docs/FakeApi.md#test_group_parameters) | **DELETE** /fake | Fake endpoint to test group parameters (optional)
*FakeApi* | [**test_inline_additional_properties**](docs/FakeApi.md#test_inline_additional_properties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
*FakeApi* | [**test_inline_freeform_additional_properties**](docs/FakeApi.md#test_inline_freeform_additional_properties) | **POST** /fake/inline-freeform-additionalProperties | test inline free-form additionalProperties
@@ -210,6 +212,8 @@ Class | Method | HTTP request | Description
- [SpecialModelName](docs/SpecialModelName.md)
- [SpecialName](docs/SpecialName.md)
- [Tag](docs/Tag.md)
- [TestErrorResponsesWithModel400Response](docs/TestErrorResponsesWithModel400Response.md)
- [TestErrorResponsesWithModel404Response](docs/TestErrorResponsesWithModel404Response.md)
- [TestInlineFreeformAdditionalPropertiesRequest](docs/TestInlineFreeformAdditionalPropertiesRequest.md)
- [Tiger](docs/Tiger.md)
- [UnnamedDictWithAdditionalModelListProperties](docs/UnnamedDictWithAdditionalModelListProperties.md)

View File

@@ -20,7 +20,9 @@ Method | HTTP request | Description
[**test_body_with_query_params**](FakeApi.md#test_body_with_query_params) | **PUT** /fake/body-with-query-params |
[**test_client_model**](FakeApi.md#test_client_model) | **PATCH** /fake | To test \"client\" model
[**test_date_time_query_parameter**](FakeApi.md#test_date_time_query_parameter) | **PUT** /fake/date-time-query-params |
[**test_empty_and_non_empty_responses**](FakeApi.md#test_empty_and_non_empty_responses) | **POST** /fake/empty_and_non_empty_responses | test empty and non-empty responses
[**test_endpoint_parameters**](FakeApi.md#test_endpoint_parameters) | **POST** /fake | Fake endpoint for testing various parameters 假端點 偽のエンドポイント 가짜 엔드 포인트
[**test_error_responses_with_model**](FakeApi.md#test_error_responses_with_model) | **POST** /fake/error_responses_with_model | test error responses with model
[**test_group_parameters**](FakeApi.md#test_group_parameters) | **DELETE** /fake | Fake endpoint to test group parameters (optional)
[**test_inline_additional_properties**](FakeApi.md#test_inline_additional_properties) | **POST** /fake/inline-additionalProperties | test inline additionalProperties
[**test_inline_freeform_additional_properties**](FakeApi.md#test_inline_freeform_additional_properties) | **POST** /fake/inline-freeform-additionalProperties | test inline free-form additionalProperties
@@ -1119,6 +1121,67 @@ No authorization required
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **test_empty_and_non_empty_responses**
> test_empty_and_non_empty_responses()
test empty and non-empty responses
### Example
```python
import time
import os
import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint
# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2
# See configuration.py for a list of all supported configuration parameters.
configuration = petstore_api.Configuration(
host = "http://petstore.swagger.io:80/v2"
)
# Enter a context with an instance of the API client
async with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
try:
# test empty and non-empty responses
await api_instance.test_empty_and_non_empty_responses()
except Exception as e:
print("Exception when calling FakeApi->test_empty_and_non_empty_responses: %s\n" % e)
```
### Parameters
This endpoint does not need any parameter.
### Return type
void (empty response body)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: text/plain
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
**204** | Success, but no response content | - |
**206** | Partial response content | - |
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **test_endpoint_parameters**
> test_endpoint_parameters(number, double, pattern_without_delimiter, byte, integer=integer, int32=int32, int64=int64, var_float=var_float, string=string, binary=binary, byte_with_max_length=byte_with_max_length, var_date=var_date, date_time=date_time, password=password, param_callback=param_callback)
@@ -1223,6 +1286,66 @@ void (empty response body)
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **test_error_responses_with_model**
> test_error_responses_with_model()
test error responses with model
### Example
```python
import time
import os
import petstore_api
from petstore_api.rest import ApiException
from pprint import pprint
# Defining the host is optional and defaults to http://petstore.swagger.io:80/v2
# See configuration.py for a list of all supported configuration parameters.
configuration = petstore_api.Configuration(
host = "http://petstore.swagger.io:80/v2"
)
# Enter a context with an instance of the API client
async with petstore_api.ApiClient(configuration) as api_client:
# Create an instance of the API class
api_instance = petstore_api.FakeApi(api_client)
try:
# test error responses with model
await api_instance.test_error_responses_with_model()
except Exception as e:
print("Exception when calling FakeApi->test_error_responses_with_model: %s\n" % e)
```
### Parameters
This endpoint does not need any parameter.
### Return type
void (empty response body)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: Not defined
- **Accept**: application/json
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
**204** | Success, but no response content | - |
**400** | | - |
**404** | | - |
[[Back to top]](#) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to Model list]](../README.md#documentation-for-models) [[Back to README]](../README.md)
# **test_group_parameters**
> test_group_parameters(required_string_group, required_boolean_group, required_int64_group, string_group=string_group, boolean_group=boolean_group, int64_group=int64_group)

View File

@@ -0,0 +1,28 @@
# TestErrorResponsesWithModel400Response
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**reason400** | **str** | | [optional]
## Example
```python
from petstore_api.models.test_error_responses_with_model400_response import TestErrorResponsesWithModel400Response
# TODO update the JSON string below
json = "{}"
# create an instance of TestErrorResponsesWithModel400Response from a JSON string
test_error_responses_with_model400_response_instance = TestErrorResponsesWithModel400Response.from_json(json)
# print the JSON string representation of the object
print TestErrorResponsesWithModel400Response.to_json()
# convert the object into a dict
test_error_responses_with_model400_response_dict = test_error_responses_with_model400_response_instance.to_dict()
# create an instance of TestErrorResponsesWithModel400Response from a dict
test_error_responses_with_model400_response_form_dict = test_error_responses_with_model400_response.from_dict(test_error_responses_with_model400_response_dict)
```
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -0,0 +1,28 @@
# TestErrorResponsesWithModel404Response
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**reason404** | **str** | | [optional]
## Example
```python
from petstore_api.models.test_error_responses_with_model404_response import TestErrorResponsesWithModel404Response
# TODO update the JSON string below
json = "{}"
# create an instance of TestErrorResponsesWithModel404Response from a JSON string
test_error_responses_with_model404_response_instance = TestErrorResponsesWithModel404Response.from_json(json)
# print the JSON string representation of the object
print TestErrorResponsesWithModel404Response.to_json()
# convert the object into a dict
test_error_responses_with_model404_response_dict = test_error_responses_with_model404_response_instance.to_dict()
# create an instance of TestErrorResponsesWithModel404Response from a dict
test_error_responses_with_model404_response_form_dict = test_error_responses_with_model404_response.from_dict(test_error_responses_with_model404_response_dict)
```
[[Back to Model list]](../README.md#documentation-for-models) [[Back to API list]](../README.md#documentation-for-api-endpoints) [[Back to README]](../README.md)

View File

@@ -113,6 +113,8 @@ from petstore_api.models.special_character_enum import SpecialCharacterEnum
from petstore_api.models.special_model_name import SpecialModelName
from petstore_api.models.special_name import SpecialName
from petstore_api.models.tag import Tag
from petstore_api.models.test_error_responses_with_model400_response import TestErrorResponsesWithModel400Response
from petstore_api.models.test_error_responses_with_model404_response import TestErrorResponsesWithModel404Response
from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest
from petstore_api.models.tiger import Tiger
from petstore_api.models.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties

View File

@@ -99,8 +99,7 @@ class AnotherFakeApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "Client"
'200': "Client",
}
response_data = await self.api_client.call_api(
*_param,
@@ -167,8 +166,7 @@ class AnotherFakeApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "Client"
'200': "Client",
}
response_data = await self.api_client.call_api(
*_param,
@@ -235,8 +233,7 @@ class AnotherFakeApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "Client"
'200': "Client",
}
response_data = await self.api_client.call_api(
*_param,

View File

@@ -92,8 +92,6 @@ class DefaultApi:
)
_response_types_map: Dict[str, Optional[str]] = {
}
response_data = await self.api_client.call_api(
*_param,
@@ -155,8 +153,6 @@ class DefaultApi:
)
_response_types_map: Dict[str, Optional[str]] = {
}
response_data = await self.api_client.call_api(
*_param,
@@ -218,8 +214,6 @@ class DefaultApi:
)
_response_types_map: Dict[str, Optional[str]] = {
}
response_data = await self.api_client.call_api(
*_param,

View File

@@ -99,8 +99,7 @@ class FakeClassnameTags123Api:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "Client"
'200': "Client",
}
response_data = await self.api_client.call_api(
*_param,
@@ -167,8 +166,7 @@ class FakeClassnameTags123Api:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "Client"
'200': "Client",
}
response_data = await self.api_client.call_api(
*_param,
@@ -235,8 +233,7 @@ class FakeClassnameTags123Api:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "Client"
'200': "Client",
}
response_data = await self.api_client.call_api(
*_param,

View File

@@ -104,7 +104,8 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': None,
'405': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -171,7 +172,8 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': None,
'405': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -238,7 +240,8 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': None,
'405': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -376,7 +379,8 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': None,
'400': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -447,7 +451,8 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': None,
'400': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -518,7 +523,8 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': None,
'400': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -641,8 +647,7 @@ class PetApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "List[Pet]",
'400': None
'400': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -710,8 +715,7 @@ class PetApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "List[Pet]",
'400': None
'400': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -779,8 +783,7 @@ class PetApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "List[Pet]",
'400': None
'400': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -912,8 +915,7 @@ class PetApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "List[Pet]",
'400': None
'400': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -982,8 +984,7 @@ class PetApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "List[Pet]",
'400': None
'400': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1052,8 +1053,7 @@ class PetApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "List[Pet]",
'400': None
'400': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1185,8 +1185,7 @@ class PetApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "Pet",
'400': None,
'404': None
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1255,8 +1254,7 @@ class PetApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "Pet",
'400': None,
'404': None
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1325,8 +1323,7 @@ class PetApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "Pet",
'400': None,
'404': None
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1452,7 +1449,10 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': None,
'400': None,
'404': None,
'405': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1519,7 +1519,10 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': None,
'400': None,
'404': None,
'405': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1586,7 +1589,10 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': None,
'400': None,
'404': None,
'405': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1728,7 +1734,8 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': None,
'405': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1803,7 +1810,8 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': None,
'405': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1878,7 +1886,8 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': None,
'405': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -2024,8 +2033,7 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "ApiResponse"
'200': "ApiResponse",
}
response_data = await self.api_client.call_api(
*_param,
@@ -2100,8 +2108,7 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "ApiResponse"
'200': "ApiResponse",
}
response_data = await self.api_client.call_api(
*_param,
@@ -2176,8 +2183,7 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "ApiResponse"
'200': "ApiResponse",
}
response_data = await self.api_client.call_api(
*_param,
@@ -2329,8 +2335,7 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "ApiResponse"
'200': "ApiResponse",
}
response_data = await self.api_client.call_api(
*_param,
@@ -2405,8 +2410,7 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "ApiResponse"
'200': "ApiResponse",
}
response_data = await self.api_client.call_api(
*_param,
@@ -2481,8 +2485,7 @@ class PetApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "ApiResponse"
'200': "ApiResponse",
}
response_data = await self.api_client.call_api(
*_param,

View File

@@ -103,7 +103,8 @@ class StoreApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'400': None,
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -170,7 +171,8 @@ class StoreApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'400': None,
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -237,7 +239,8 @@ class StoreApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'400': None,
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -351,8 +354,7 @@ class StoreApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "Dict[str, int]"
'200': "Dict[str, int]",
}
response_data = await self.api_client.call_api(
*_param,
@@ -415,8 +417,7 @@ class StoreApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "Dict[str, int]"
'200': "Dict[str, int]",
}
response_data = await self.api_client.call_api(
*_param,
@@ -479,8 +480,7 @@ class StoreApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'200': "Dict[str, int]"
'200': "Dict[str, int]",
}
response_data = await self.api_client.call_api(
*_param,
@@ -604,8 +604,7 @@ class StoreApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "Order",
'400': None,
'404': None
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -674,8 +673,7 @@ class StoreApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "Order",
'400': None,
'404': None
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -744,8 +742,7 @@ class StoreApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "Order",
'400': None,
'404': None
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -871,8 +868,7 @@ class StoreApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "Order",
'400': None
'400': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -940,8 +936,7 @@ class StoreApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "Order",
'400': None
'400': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1009,8 +1004,7 @@ class StoreApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "Order",
'400': None
'400': None,
}
response_data = await self.api_client.call_api(
*_param,

View File

@@ -103,7 +103,6 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
}
response_data = await self.api_client.call_api(
*_param,
@@ -170,7 +169,6 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
}
response_data = await self.api_client.call_api(
*_param,
@@ -237,7 +235,6 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
}
response_data = await self.api_client.call_api(
*_param,
@@ -373,7 +370,6 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
}
response_data = await self.api_client.call_api(
*_param,
@@ -440,7 +436,6 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
}
response_data = await self.api_client.call_api(
*_param,
@@ -507,7 +502,6 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
}
response_data = await self.api_client.call_api(
*_param,
@@ -639,7 +633,6 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
}
response_data = await self.api_client.call_api(
*_param,
@@ -706,7 +699,6 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
}
response_data = await self.api_client.call_api(
*_param,
@@ -773,7 +765,6 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
}
response_data = await self.api_client.call_api(
*_param,
@@ -905,7 +896,8 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'400': None,
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -972,7 +964,8 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'400': None,
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1039,7 +1032,8 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'400': None,
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1159,8 +1153,7 @@ class UserApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "User",
'400': None,
'404': None
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1229,8 +1222,7 @@ class UserApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "User",
'400': None,
'404': None
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1299,8 +1291,7 @@ class UserApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "User",
'400': None,
'404': None
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1430,8 +1421,7 @@ class UserApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
'400': None
'400': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1503,8 +1493,7 @@ class UserApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
'400': None
'400': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1576,8 +1565,7 @@ class UserApi:
_response_types_map: Dict[str, Optional[str]] = {
'200': "str",
'400': None
'400': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -1705,7 +1693,6 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
}
response_data = await self.api_client.call_api(
*_param,
@@ -1768,7 +1755,6 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
}
response_data = await self.api_client.call_api(
*_param,
@@ -1831,7 +1817,6 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
}
response_data = await self.api_client.call_api(
*_param,
@@ -1950,7 +1935,8 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'400': None,
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -2021,7 +2007,8 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'400': None,
'404': None,
}
response_data = await self.api_client.call_api(
*_param,
@@ -2092,7 +2079,8 @@ class UserApi:
)
_response_types_map: Dict[str, Optional[str]] = {
'400': None,
'404': None,
}
response_data = await self.api_client.call_api(
*_param,

View File

@@ -284,7 +284,7 @@ class ApiClient:
def response_deserialize(
self,
response_data=None,
response_data: rest.RESTResponse = None,
response_types_map=None
) -> ApiResponse:
"""Deserializes response into an object.
@@ -299,39 +299,29 @@ class ApiClient:
# if not found, look for '1XX', '2XX', etc.
response_type = response_types_map.get(str(response_data.status)[0] + "XX", None)
if not 200 <= response_data.status <= 299:
if response_data.status == 400:
raise BadRequestException(http_resp=response_data)
if response_data.status == 401:
raise UnauthorizedException(http_resp=response_data)
if response_data.status == 403:
raise ForbiddenException(http_resp=response_data)
if response_data.status == 404:
raise NotFoundException(http_resp=response_data)
if 500 <= response_data.status <= 599:
raise ServiceException(http_resp=response_data)
raise ApiException(http_resp=response_data)
# deserialize response data
if response_type == "bytearray":
return_data = response_data.data
elif response_type is None:
return_data = None
elif response_type == "file":
return_data = self.__deserialize_file(response_data)
else:
match = None
content_type = response_data.getheader('content-type')
if content_type is not None:
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
encoding = match.group(1) if match else "utf-8"
response_text = response_data.data.decode(encoding)
return_data = self.deserialize(response_text, response_type)
response_text = None
return_data = None
try:
if response_type == "bytearray":
return_data = response_data.data
elif response_type == "file":
return_data = self.__deserialize_file(response_data)
elif response_type is not None:
match = None
content_type = response_data.getheader('content-type')
if content_type is not None:
match = re.search(r"charset=([a-zA-Z\-\d]+)[\s;]?", content_type)
encoding = match.group(1) if match else "utf-8"
response_text = response_data.data.decode(encoding)
return_data = self.deserialize(response_text, response_type)
finally:
if not 200 <= response_data.status <= 299:
raise ApiException.from_response(
http_resp=response_data,
body=response_text,
data=return_data,
)
return ApiResponse(
status_code = response_data.status,

View File

@@ -11,6 +11,9 @@
Do not edit the class manually.
""" # noqa: E501
from typing import Any, Optional
from typing_extensions import Self
class OpenApiException(Exception):
"""The base exception class for all OpenAPIExceptions"""
@@ -101,17 +104,56 @@ class ApiKeyError(OpenApiException, KeyError):
class ApiException(OpenApiException):
def __init__(self, status=None, reason=None, http_resp=None) -> None:
def __init__(
self,
status=None,
reason=None,
http_resp=None,
*,
body: Optional[str] = None,
data: Optional[Any] = None,
) -> None:
self.status = status
self.reason = reason
self.body = body
self.data = data
self.headers = None
if http_resp:
self.status = http_resp.status
self.reason = http_resp.reason
self.body = http_resp.data.decode('utf-8')
if self.status is None:
self.status = http_resp.status
if self.reason is None:
self.reason = http_resp.reason
if self.body is None:
try:
self.body = http_resp.data.decode('utf-8')
except Exception:
pass
self.headers = http_resp.getheaders()
else:
self.status = status
self.reason = reason
self.body = None
self.headers = None
@classmethod
def from_response(
cls,
*,
http_resp,
body: Optional[str],
data: Optional[Any],
) -> Self:
if http_resp.status == 400:
raise BadRequestException(http_resp=http_resp, body=body, data=data)
if http_resp.status == 401:
raise UnauthorizedException(http_resp=http_resp, body=body, data=data)
if http_resp.status == 403:
raise ForbiddenException(http_resp=http_resp, body=body, data=data)
if http_resp.status == 404:
raise NotFoundException(http_resp=http_resp, body=body, data=data)
if 500 <= http_resp.status <= 599:
raise ServiceException(http_resp=http_resp, body=body, data=data)
raise ApiException(http_resp=http_resp, body=body, data=data)
def __str__(self):
"""Custom error messages for exception"""
@@ -121,38 +163,30 @@ class ApiException(OpenApiException):
error_message += "HTTP response headers: {0}\n".format(
self.headers)
if self.body:
error_message += "HTTP response body: {0}\n".format(self.body)
if self.data or self.body:
error_message += "HTTP response body: {0}\n".format(self.data or self.body)
return error_message
class BadRequestException(ApiException):
def __init__(self, status=None, reason=None, http_resp=None) -> None:
super(BadRequestException, self).__init__(status, reason, http_resp)
class BadRequestException(ApiException):
pass
class NotFoundException(ApiException):
def __init__(self, status=None, reason=None, http_resp=None) -> None:
super(NotFoundException, self).__init__(status, reason, http_resp)
pass
class UnauthorizedException(ApiException):
def __init__(self, status=None, reason=None, http_resp=None) -> None:
super(UnauthorizedException, self).__init__(status, reason, http_resp)
pass
class ForbiddenException(ApiException):
def __init__(self, status=None, reason=None, http_resp=None) -> None:
super(ForbiddenException, self).__init__(status, reason, http_resp)
pass
class ServiceException(ApiException):
def __init__(self, status=None, reason=None, http_resp=None) -> None:
super(ServiceException, self).__init__(status, reason, http_resp)
pass
def render_path(path_to_item):

View File

@@ -89,6 +89,8 @@ from petstore_api.models.special_character_enum import SpecialCharacterEnum
from petstore_api.models.special_model_name import SpecialModelName
from petstore_api.models.special_name import SpecialName
from petstore_api.models.tag import Tag
from petstore_api.models.test_error_responses_with_model400_response import TestErrorResponsesWithModel400Response
from petstore_api.models.test_error_responses_with_model404_response import TestErrorResponsesWithModel404Response
from petstore_api.models.test_inline_freeform_additional_properties_request import TestInlineFreeformAdditionalPropertiesRequest
from petstore_api.models.tiger import Tiger
from petstore_api.models.unnamed_dict_with_additional_model_list_properties import UnnamedDictWithAdditionalModelListProperties

View File

@@ -0,0 +1,87 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictStr
try:
from typing import Self
except ImportError:
from typing_extensions import Self
class TestErrorResponsesWithModel400Response(BaseModel):
"""
TestErrorResponsesWithModel400Response
""" # noqa: E501
reason400: Optional[StrictStr] = None
__properties: ClassVar[List[str]] = ["reason400"]
model_config = {
"populate_by_name": True,
"validate_assignment": True
}
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> Self:
"""Create an instance of TestErrorResponsesWithModel400Response from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:
* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
"""
_dict = self.model_dump(
by_alias=True,
exclude={
},
exclude_none=True,
)
return _dict
@classmethod
def from_dict(cls, obj: Dict) -> Self:
"""Create an instance of TestErrorResponsesWithModel400Response from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
_obj = cls.model_validate({
"reason400": obj.get("reason400")
})
return _obj

View File

@@ -0,0 +1,87 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
from __future__ import annotations
import pprint
import re # noqa: F401
import json
from typing import Any, ClassVar, Dict, List, Optional
from pydantic import BaseModel, StrictStr
try:
from typing import Self
except ImportError:
from typing_extensions import Self
class TestErrorResponsesWithModel404Response(BaseModel):
"""
TestErrorResponsesWithModel404Response
""" # noqa: E501
reason404: Optional[StrictStr] = None
__properties: ClassVar[List[str]] = ["reason404"]
model_config = {
"populate_by_name": True,
"validate_assignment": True
}
def to_str(self) -> str:
"""Returns the string representation of the model using alias"""
return pprint.pformat(self.model_dump(by_alias=True))
def to_json(self) -> str:
"""Returns the JSON representation of the model using alias"""
# TODO: pydantic v2: use .model_dump_json(by_alias=True, exclude_unset=True) instead
return json.dumps(self.to_dict())
@classmethod
def from_json(cls, json_str: str) -> Self:
"""Create an instance of TestErrorResponsesWithModel404Response from a JSON string"""
return cls.from_dict(json.loads(json_str))
def to_dict(self) -> Dict[str, Any]:
"""Return the dictionary representation of the model using alias.
This has the following differences from calling pydantic's
`self.model_dump(by_alias=True)`:
* `None` is only added to the output dict for nullable fields that
were set at model initialization. Other fields with value `None`
are ignored.
"""
_dict = self.model_dump(
by_alias=True,
exclude={
},
exclude_none=True,
)
return _dict
@classmethod
def from_dict(cls, obj: Dict) -> Self:
"""Create an instance of TestErrorResponsesWithModel404Response from a dict"""
if obj is None:
return None
if not isinstance(obj, dict):
return cls.model_validate(obj)
_obj = cls.model_validate({
"reason404": obj.get("reason404")
})
return _obj

View File

@@ -0,0 +1,52 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
import unittest
import datetime
from petstore_api.models.test_error_responses_with_model400_response import TestErrorResponsesWithModel400Response
class TestTestErrorResponsesWithModel400Response(unittest.TestCase):
"""TestErrorResponsesWithModel400Response unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional) -> TestErrorResponsesWithModel400Response:
"""Test TestErrorResponsesWithModel400Response
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
# uncomment below to create an instance of `TestErrorResponsesWithModel400Response`
"""
model = TestErrorResponsesWithModel400Response()
if include_optional:
return TestErrorResponsesWithModel400Response(
reason400 = ''
)
else:
return TestErrorResponsesWithModel400Response(
)
"""
def testTestErrorResponsesWithModel400Response(self):
"""Test TestErrorResponsesWithModel400Response"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()

View File

@@ -0,0 +1,52 @@
# coding: utf-8
"""
OpenAPI Petstore
This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \" \\
The version of the OpenAPI document: 1.0.0
Generated by OpenAPI Generator (https://openapi-generator.tech)
Do not edit the class manually.
""" # noqa: E501
import unittest
import datetime
from petstore_api.models.test_error_responses_with_model404_response import TestErrorResponsesWithModel404Response
class TestTestErrorResponsesWithModel404Response(unittest.TestCase):
"""TestErrorResponsesWithModel404Response unit test stubs"""
def setUp(self):
pass
def tearDown(self):
pass
def make_instance(self, include_optional) -> TestErrorResponsesWithModel404Response:
"""Test TestErrorResponsesWithModel404Response
include_option is a boolean, when False only required
params are included, when True both required and
optional params are included """
# uncomment below to create an instance of `TestErrorResponsesWithModel404Response`
"""
model = TestErrorResponsesWithModel404Response()
if include_optional:
return TestErrorResponsesWithModel404Response(
reason404 = ''
)
else:
return TestErrorResponsesWithModel404Response(
)
"""
def testTestErrorResponsesWithModel404Response(self):
"""Test TestErrorResponsesWithModel404Response"""
# inst_req_only = self.make_instance(include_optional=False)
# inst_req_and_optional = self.make_instance(include_optional=True)
if __name__ == '__main__':
unittest.main()