[Python] deserialize enum json response (fix #17789) (#17791)

* deserialize enum json response (python)

* adapt python samples: adding enum deserialization

* add echo test for enum json response deserialization (python)

* update samples
This commit is contained in:
Jonathan
2024-02-08 03:52:43 +01:00
committed by GitHub
parent c71eb5dfe8
commit f323a3e788
65 changed files with 3572 additions and 0 deletions

View File

@@ -126,6 +126,7 @@ Class | Method | HTTP request | Description
*BodyApi* | [**TestEchoBodyFreeFormObjectResponseString**](docs/BodyApi.md#testechobodyfreeformobjectresponsestring) | **POST** /echo/body/FreeFormObject/response_string | Test free form object
*BodyApi* | [**TestEchoBodyPet**](docs/BodyApi.md#testechobodypet) | **POST** /echo/body/Pet | Test body parameter(s)
*BodyApi* | [**TestEchoBodyPetResponseString**](docs/BodyApi.md#testechobodypetresponsestring) | **POST** /echo/body/Pet/response_string | Test empty response body
*BodyApi* | [**TestEchoBodyStringEnum**](docs/BodyApi.md#testechobodystringenum) | **POST** /echo/body/string_enum | Test string enum response body
*BodyApi* | [**TestEchoBodyTagResponseString**](docs/BodyApi.md#testechobodytagresponsestring) | **POST** /echo/body/Tag/response_string | Test empty json (request body)
*FormApi* | [**TestFormIntegerBooleanString**](docs/FormApi.md#testformintegerbooleanstring) | **POST** /form/integer/boolean/string | Test form parameter(s)
*FormApi* | [**TestFormOneof**](docs/FormApi.md#testformoneof) | **POST** /form/oneof | Test form parameter(s) for oneOf schema

View File

@@ -519,6 +519,26 @@ paths:
summary: Test free form object
tags:
- body
/echo/body/string_enum:
post:
description: Test string enum response body
operationId: test/echo/body/string_enum
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/StringEnumRef'
description: String enum
responses:
"200":
content:
application/json:
schema:
$ref: '#/components/schemas/StringEnumRef'
description: Successful operation
summary: Test string enum response body
tags:
- body
/binary/gif:
post:
description: Test binary (gif) response body

View File

@@ -12,6 +12,7 @@ All URIs are relative to *http://localhost:3000*
| [**TestEchoBodyFreeFormObjectResponseString**](BodyApi.md#testechobodyfreeformobjectresponsestring) | **POST** /echo/body/FreeFormObject/response_string | Test free form object |
| [**TestEchoBodyPet**](BodyApi.md#testechobodypet) | **POST** /echo/body/Pet | Test body parameter(s) |
| [**TestEchoBodyPetResponseString**](BodyApi.md#testechobodypetresponsestring) | **POST** /echo/body/Pet/response_string | Test empty response body |
| [**TestEchoBodyStringEnum**](BodyApi.md#testechobodystringenum) | **POST** /echo/body/string_enum | Test string enum response body |
| [**TestEchoBodyTagResponseString**](BodyApi.md#testechobodytagresponsestring) | **POST** /echo/body/Tag/response_string | Test empty json (request body) |
<a id="testbinarygif"></a>
@@ -730,6 +731,97 @@ No authorization required
- **Accept**: text/plain
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|
| **200** | Successful operation | - |
[[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)
<a id="testechobodystringenum"></a>
# **TestEchoBodyStringEnum**
> StringEnumRef TestEchoBodyStringEnum (string? body = null)
Test string enum response body
Test string enum response body
### Example
```csharp
using System.Collections.Generic;
using System.Diagnostics;
using Org.OpenAPITools.Api;
using Org.OpenAPITools.Client;
using Org.OpenAPITools.Model;
namespace Example
{
public class TestEchoBodyStringEnumExample
{
public static void Main()
{
Configuration config = new Configuration();
config.BasePath = "http://localhost:3000";
var apiInstance = new BodyApi(config);
var body = null; // string? | String enum (optional)
try
{
// Test string enum response body
StringEnumRef result = apiInstance.TestEchoBodyStringEnum(body);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling BodyApi.TestEchoBodyStringEnum: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
}
}
}
```
#### Using the TestEchoBodyStringEnumWithHttpInfo variant
This returns an ApiResponse object which contains the response data, status code and headers.
```csharp
try
{
// Test string enum response body
ApiResponse<StringEnumRef> response = apiInstance.TestEchoBodyStringEnumWithHttpInfo(body);
Debug.Write("Status Code: " + response.StatusCode);
Debug.Write("Response Headers: " + response.Headers);
Debug.Write("Response Body: " + response.Data);
}
catch (ApiException e)
{
Debug.Print("Exception when calling BodyApi.TestEchoBodyStringEnumWithHttpInfo: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
```
### Parameters
| Name | Type | Description | Notes |
|------|------|-------------|-------|
| **body** | **string?** | String enum | [optional] |
### Return type
[**StringEnumRef**](StringEnumRef.md)
### Authorization
No authorization required
### HTTP request headers
- **Content-Type**: application/json
- **Accept**: application/json
### HTTP response details
| Status code | Description | Response headers |
|-------------|-------------|------------------|

View File

@@ -210,6 +210,29 @@ namespace Org.OpenAPITools.Api
/// <returns>ApiResponse of string</returns>
ApiResponse<string> TestEchoBodyPetResponseStringWithHttpInfo(Pet? pet = default(Pet?), int operationIndex = 0);
/// <summary>
/// Test string enum response body
/// </summary>
/// <remarks>
/// Test string enum response body
/// </remarks>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="body">String enum (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>StringEnumRef</returns>
StringEnumRef TestEchoBodyStringEnum(string? body = default(string?), int operationIndex = 0);
/// <summary>
/// Test string enum response body
/// </summary>
/// <remarks>
/// Test string enum response body
/// </remarks>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="body">String enum (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>ApiResponse of StringEnumRef</returns>
ApiResponse<StringEnumRef> TestEchoBodyStringEnumWithHttpInfo(string? body = default(string?), int operationIndex = 0);
/// <summary>
/// Test empty json (request body)
/// </summary>
/// <remarks>
@@ -440,6 +463,31 @@ namespace Org.OpenAPITools.Api
/// <returns>Task of ApiResponse (string)</returns>
System.Threading.Tasks.Task<ApiResponse<string>> TestEchoBodyPetResponseStringWithHttpInfoAsync(Pet? pet = default(Pet?), int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
/// <summary>
/// Test string enum response body
/// </summary>
/// <remarks>
/// Test string enum response body
/// </remarks>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="body">String enum (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of StringEnumRef</returns>
System.Threading.Tasks.Task<StringEnumRef> TestEchoBodyStringEnumAsync(string? body = default(string?), int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
/// <summary>
/// Test string enum response body
/// </summary>
/// <remarks>
/// Test string enum response body
/// </remarks>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="body">String enum (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of ApiResponse (StringEnumRef)</returns>
System.Threading.Tasks.Task<ApiResponse<StringEnumRef>> TestEchoBodyStringEnumWithHttpInfoAsync(string? body = default(string?), int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken));
/// <summary>
/// Test empty json (request body)
/// </summary>
/// <remarks>
@@ -1672,6 +1720,140 @@ namespace Org.OpenAPITools.Api
return localVarResponse;
}
/// <summary>
/// Test string enum response body Test string enum response body
/// </summary>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="body">String enum (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>StringEnumRef</returns>
public StringEnumRef TestEchoBodyStringEnum(string? body = default(string?), int operationIndex = 0)
{
Org.OpenAPITools.Client.ApiResponse<StringEnumRef> localVarResponse = TestEchoBodyStringEnumWithHttpInfo(body);
return localVarResponse.Data;
}
/// <summary>
/// Test string enum response body Test string enum response body
/// </summary>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="body">String enum (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <returns>ApiResponse of StringEnumRef</returns>
public Org.OpenAPITools.Client.ApiResponse<StringEnumRef> TestEchoBodyStringEnumWithHttpInfo(string? body = default(string?), int operationIndex = 0)
{
Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions();
string[] _contentTypes = new string[] {
"application/json"
};
// to determine the Accept header
string[] _accepts = new string[] {
"application/json"
};
var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes);
if (localVarContentType != null)
{
localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);
}
var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts);
if (localVarAccept != null)
{
localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
}
localVarRequestOptions.Data = body;
localVarRequestOptions.Operation = "BodyApi.TestEchoBodyStringEnum";
localVarRequestOptions.OperationIndex = operationIndex;
// make the HTTP request
var localVarResponse = this.Client.Post<StringEnumRef>("/echo/body/string_enum", localVarRequestOptions, this.Configuration);
if (this.ExceptionFactory != null)
{
Exception _exception = this.ExceptionFactory("TestEchoBodyStringEnum", localVarResponse);
if (_exception != null)
{
throw _exception;
}
}
return localVarResponse;
}
/// <summary>
/// Test string enum response body Test string enum response body
/// </summary>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="body">String enum (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of StringEnumRef</returns>
public async System.Threading.Tasks.Task<StringEnumRef> TestEchoBodyStringEnumAsync(string? body = default(string?), int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
Org.OpenAPITools.Client.ApiResponse<StringEnumRef> localVarResponse = await TestEchoBodyStringEnumWithHttpInfoAsync(body, operationIndex, cancellationToken).ConfigureAwait(false);
return localVarResponse.Data;
}
/// <summary>
/// Test string enum response body Test string enum response body
/// </summary>
/// <exception cref="Org.OpenAPITools.Client.ApiException">Thrown when fails to make API call</exception>
/// <param name="body">String enum (optional)</param>
/// <param name="operationIndex">Index associated with the operation.</param>
/// <param name="cancellationToken">Cancellation Token to cancel the request.</param>
/// <returns>Task of ApiResponse (StringEnumRef)</returns>
public async System.Threading.Tasks.Task<Org.OpenAPITools.Client.ApiResponse<StringEnumRef>> TestEchoBodyStringEnumWithHttpInfoAsync(string? body = default(string?), int operationIndex = 0, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken))
{
Org.OpenAPITools.Client.RequestOptions localVarRequestOptions = new Org.OpenAPITools.Client.RequestOptions();
string[] _contentTypes = new string[] {
"application/json"
};
// to determine the Accept header
string[] _accepts = new string[] {
"application/json"
};
var localVarContentType = Org.OpenAPITools.Client.ClientUtils.SelectHeaderContentType(_contentTypes);
if (localVarContentType != null)
{
localVarRequestOptions.HeaderParameters.Add("Content-Type", localVarContentType);
}
var localVarAccept = Org.OpenAPITools.Client.ClientUtils.SelectHeaderAccept(_accepts);
if (localVarAccept != null)
{
localVarRequestOptions.HeaderParameters.Add("Accept", localVarAccept);
}
localVarRequestOptions.Data = body;
localVarRequestOptions.Operation = "BodyApi.TestEchoBodyStringEnum";
localVarRequestOptions.OperationIndex = operationIndex;
// make the HTTP request
var localVarResponse = await this.AsynchronousClient.PostAsync<StringEnumRef>("/echo/body/string_enum", localVarRequestOptions, this.Configuration, cancellationToken).ConfigureAwait(false);
if (this.ExceptionFactory != null)
{
Exception _exception = this.ExceptionFactory("TestEchoBodyStringEnum", localVarResponse);
if (_exception != null)
{
throw _exception;
}
}
return localVarResponse;
}
/// <summary>
/// Test empty json (request body) Test empty json (request body)
/// </summary>