[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

@@ -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)