[python] Add tests and fix enum path parameters (#16769)

* test: Tests for enum params in path, query and header

* fix: Get enum ref values correctly in path parameters

Closes #16688

* fix java tests failure

---------

Co-authored-by: William Cheng <wing328hk@gmail.com>
This commit is contained in:
Robert Schweizer
2023-10-10 11:10:30 +02:00
committed by GitHub
parent 7bb75f4bb4
commit 9e07f85eb5
88 changed files with 1549 additions and 538 deletions

View File

@@ -120,8 +120,8 @@ Class | Method | HTTP request | Description
*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
*HeaderApi* | [**testHeaderIntegerBooleanString**](docs/HeaderApi.md#testHeaderIntegerBooleanString) | **GET** /header/integer/boolean/string | Test header parameter(s)
*PathApi* | [**testsPathStringPathStringIntegerPathInteger**](docs/PathApi.md#testsPathStringPathStringIntegerPathInteger) | **GET** /path/string/{path_string}/integer/{path_integer} | Test path parameter(s)
*HeaderApi* | [**testHeaderIntegerBooleanStringEnums**](docs/HeaderApi.md#testHeaderIntegerBooleanStringEnums) | **GET** /header/integer/boolean/string/enums | Test header parameter(s)
*PathApi* | [**testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath**](docs/PathApi.md#testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath) | **GET** /path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path} | Test path parameter(s)
*QueryApi* | [**testEnumRefString**](docs/QueryApi.md#testEnumRefString) | **GET** /query/enum_ref_string | Test query parameter(s)
*QueryApi* | [**testQueryDatetimeDateString**](docs/QueryApi.md#testQueryDatetimeDateString) | **GET** /query/datetime/date/string | Test query parameter(s)
*QueryApi* | [**testQueryIntegerBooleanString**](docs/QueryApi.md#testQueryIntegerBooleanString) | **GET** /query/integer/boolean/string | Test query parameter(s)

View File

@@ -11,10 +11,10 @@ info:
servers:
- url: http://localhost:3000/
paths:
/path/string/{path_string}/integer/{path_integer}:
/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}:
get:
description: Test path parameter(s)
operationId: "tests/path/string/{path_string}/integer/{path_integer}"
operationId: "tests/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}"
parameters:
- explode: false
in: path
@@ -30,6 +30,24 @@ paths:
schema:
type: integer
style: simple
- explode: false
in: path
name: enum_nonref_string_path
required: true
schema:
enum:
- success
- failure
- unclassified
type: string
style: simple
- explode: false
in: path
name: enum_ref_string_path
required: true
schema:
$ref: '#/components/schemas/StringEnumRef'
style: simple
responses:
"200":
content:
@@ -83,10 +101,10 @@ paths:
- form
x-content-type: application/x-www-form-urlencoded
x-accepts: text/plain
/header/integer/boolean/string:
/header/integer/boolean/string/enums:
get:
description: Test header parameter(s)
operationId: test/header/integer/boolean/string
operationId: test/header/integer/boolean/string/enums
parameters:
- explode: true
in: header
@@ -109,6 +127,24 @@ paths:
schema:
type: string
style: form
- explode: true
in: header
name: enum_nonref_string_header
required: false
schema:
enum:
- success
- failure
- unclassified
type: string
style: form
- explode: true
in: header
name: enum_ref_string_header
required: false
schema:
$ref: '#/components/schemas/StringEnumRef'
style: form
responses:
"200":
content:
@@ -125,6 +161,17 @@ paths:
description: Test query parameter(s)
operationId: test/enum_ref_string
parameters:
- explode: true
in: query
name: enum_nonref_string_query
required: false
schema:
enum:
- success
- failure
- unclassified
type: string
style: form
- explode: true
in: query
name: enum_ref_string_query

View File

@@ -4,13 +4,13 @@ All URIs are relative to *http://localhost:3000*
| Method | HTTP request | Description |
|------------- | ------------- | -------------|
| [**testHeaderIntegerBooleanString**](HeaderApi.md#testHeaderIntegerBooleanString) | **GET** /header/integer/boolean/string | Test header parameter(s) |
| [**testHeaderIntegerBooleanStringEnums**](HeaderApi.md#testHeaderIntegerBooleanStringEnums) | **GET** /header/integer/boolean/string/enums | Test header parameter(s) |
## testHeaderIntegerBooleanString
## testHeaderIntegerBooleanStringEnums
> String testHeaderIntegerBooleanString(integerHeader, booleanHeader, stringHeader)
> String testHeaderIntegerBooleanStringEnums(integerHeader, booleanHeader, stringHeader, enumNonrefStringHeader, enumRefStringHeader)
Test header parameter(s)
@@ -35,11 +35,13 @@ public class Example {
Integer integerHeader = 56; // Integer |
Boolean booleanHeader = true; // Boolean |
String stringHeader = "stringHeader_example"; // String |
String enumNonrefStringHeader = "success"; // String |
StringEnumRef enumRefStringHeader = StringEnumRef.fromValue("success"); // StringEnumRef |
try {
String result = apiInstance.testHeaderIntegerBooleanString(integerHeader, booleanHeader, stringHeader);
String result = apiInstance.testHeaderIntegerBooleanStringEnums(integerHeader, booleanHeader, stringHeader, enumNonrefStringHeader, enumRefStringHeader);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling HeaderApi#testHeaderIntegerBooleanString");
System.err.println("Exception when calling HeaderApi#testHeaderIntegerBooleanStringEnums");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
@@ -57,6 +59,8 @@ public class Example {
| **integerHeader** | **Integer**| | [optional] |
| **booleanHeader** | **Boolean**| | [optional] |
| **stringHeader** | **String**| | [optional] |
| **enumNonrefStringHeader** | **String**| | [optional] [enum: success, failure, unclassified] |
| **enumRefStringHeader** | [**StringEnumRef**](.md)| | [optional] [enum: success, failure, unclassified] |
### Return type

View File

@@ -4,13 +4,13 @@ All URIs are relative to *http://localhost:3000*
| Method | HTTP request | Description |
|------------- | ------------- | -------------|
| [**testsPathStringPathStringIntegerPathInteger**](PathApi.md#testsPathStringPathStringIntegerPathInteger) | **GET** /path/string/{path_string}/integer/{path_integer} | Test path parameter(s) |
| [**testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath**](PathApi.md#testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath) | **GET** /path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path} | Test path parameter(s) |
## testsPathStringPathStringIntegerPathInteger
## testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath
> String testsPathStringPathStringIntegerPathInteger(pathString, pathInteger)
> String testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath(pathString, pathInteger, enumNonrefStringPath, enumRefStringPath)
Test path parameter(s)
@@ -34,11 +34,13 @@ public class Example {
PathApi apiInstance = new PathApi(defaultClient);
String pathString = "pathString_example"; // String |
Integer pathInteger = 56; // Integer |
String enumNonrefStringPath = "success"; // String |
StringEnumRef enumRefStringPath = StringEnumRef.fromValue("success"); // StringEnumRef |
try {
String result = apiInstance.testsPathStringPathStringIntegerPathInteger(pathString, pathInteger);
String result = apiInstance.testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath(pathString, pathInteger, enumNonrefStringPath, enumRefStringPath);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling PathApi#testsPathStringPathStringIntegerPathInteger");
System.err.println("Exception when calling PathApi#testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath");
System.err.println("Status code: " + e.getCode());
System.err.println("Reason: " + e.getResponseBody());
System.err.println("Response headers: " + e.getResponseHeaders());
@@ -55,6 +57,8 @@ public class Example {
|------------- | ------------- | ------------- | -------------|
| **pathString** | **String**| | |
| **pathInteger** | **Integer**| | |
| **enumNonrefStringPath** | **String**| | [enum: success, failure, unclassified] |
| **enumRefStringPath** | [**StringEnumRef**](.md)| | [enum: success, failure, unclassified] |
### Return type

View File

@@ -17,7 +17,7 @@ All URIs are relative to *http://localhost:3000*
## testEnumRefString
> String testEnumRefString(enumRefStringQuery)
> String testEnumRefString(enumNonrefStringQuery, enumRefStringQuery)
Test query parameter(s)
@@ -39,9 +39,10 @@ public class Example {
defaultClient.setBasePath("http://localhost:3000");
QueryApi apiInstance = new QueryApi(defaultClient);
String enumNonrefStringQuery = "success"; // String |
StringEnumRef enumRefStringQuery = StringEnumRef.fromValue("success"); // StringEnumRef |
try {
String result = apiInstance.testEnumRefString(enumRefStringQuery);
String result = apiInstance.testEnumRefString(enumNonrefStringQuery, enumRefStringQuery);
System.out.println(result);
} catch (ApiException e) {
System.err.println("Exception when calling QueryApi#testEnumRefString");
@@ -59,6 +60,7 @@ public class Example {
| Name | Type | Description | Notes |
|------------- | ------------- | ------------- | -------------|
| **enumNonrefStringQuery** | **String**| | [optional] [enum: success, failure, unclassified] |
| **enumRefStringQuery** | [**StringEnumRef**](.md)| | [optional] [enum: success, failure, unclassified] |
### Return type

View File

@@ -19,6 +19,7 @@ import org.openapitools.client.ApiClient;
import org.openapitools.client.Configuration;
import org.openapitools.client.Pair;
import org.openapitools.client.model.StringEnumRef;
import java.util.ArrayList;
@@ -56,11 +57,13 @@ public class HeaderApi {
* @param integerHeader (optional)
* @param booleanHeader (optional)
* @param stringHeader (optional)
* @param enumNonrefStringHeader (optional)
* @param enumRefStringHeader (optional)
* @return String
* @throws ApiException if fails to make API call
*/
public String testHeaderIntegerBooleanString(Integer integerHeader, Boolean booleanHeader, String stringHeader) throws ApiException {
return this.testHeaderIntegerBooleanString(integerHeader, booleanHeader, stringHeader, Collections.emptyMap());
public String testHeaderIntegerBooleanStringEnums(Integer integerHeader, Boolean booleanHeader, String stringHeader, String enumNonrefStringHeader, StringEnumRef enumRefStringHeader) throws ApiException {
return this.testHeaderIntegerBooleanStringEnums(integerHeader, booleanHeader, stringHeader, enumNonrefStringHeader, enumRefStringHeader, Collections.emptyMap());
}
@@ -70,15 +73,17 @@ public class HeaderApi {
* @param integerHeader (optional)
* @param booleanHeader (optional)
* @param stringHeader (optional)
* @param enumNonrefStringHeader (optional)
* @param enumRefStringHeader (optional)
* @param additionalHeaders additionalHeaders for this call
* @return String
* @throws ApiException if fails to make API call
*/
public String testHeaderIntegerBooleanString(Integer integerHeader, Boolean booleanHeader, String stringHeader, Map<String, String> additionalHeaders) throws ApiException {
public String testHeaderIntegerBooleanStringEnums(Integer integerHeader, Boolean booleanHeader, String stringHeader, String enumNonrefStringHeader, StringEnumRef enumRefStringHeader, Map<String, String> additionalHeaders) throws ApiException {
Object localVarPostBody = null;
// create path and map variables
String localVarPath = "/header/integer/boolean/string";
String localVarPath = "/header/integer/boolean/string/enums";
StringJoiner localVarQueryStringJoiner = new StringJoiner("&");
String localVarQueryParameterBaseName;
@@ -94,6 +99,10 @@ if (booleanHeader != null)
localVarHeaderParams.put("boolean_header", apiClient.parameterToString(booleanHeader));
if (stringHeader != null)
localVarHeaderParams.put("string_header", apiClient.parameterToString(stringHeader));
if (enumNonrefStringHeader != null)
localVarHeaderParams.put("enum_nonref_string_header", apiClient.parameterToString(enumNonrefStringHeader));
if (enumRefStringHeader != null)
localVarHeaderParams.put("enum_ref_string_header", apiClient.parameterToString(enumRefStringHeader));
localVarHeaderParams.putAll(additionalHeaders);

View File

@@ -19,6 +19,7 @@ import org.openapitools.client.ApiClient;
import org.openapitools.client.Configuration;
import org.openapitools.client.Pair;
import org.openapitools.client.model.StringEnumRef;
import java.util.ArrayList;
@@ -55,11 +56,13 @@ public class PathApi {
* Test path parameter(s)
* @param pathString (required)
* @param pathInteger (required)
* @param enumNonrefStringPath (required)
* @param enumRefStringPath (required)
* @return String
* @throws ApiException if fails to make API call
*/
public String testsPathStringPathStringIntegerPathInteger(String pathString, Integer pathInteger) throws ApiException {
return this.testsPathStringPathStringIntegerPathInteger(pathString, pathInteger, Collections.emptyMap());
public String testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath(String pathString, Integer pathInteger, String enumNonrefStringPath, StringEnumRef enumRefStringPath) throws ApiException {
return this.testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath(pathString, pathInteger, enumNonrefStringPath, enumRefStringPath, Collections.emptyMap());
}
@@ -68,27 +71,41 @@ public class PathApi {
* Test path parameter(s)
* @param pathString (required)
* @param pathInteger (required)
* @param enumNonrefStringPath (required)
* @param enumRefStringPath (required)
* @param additionalHeaders additionalHeaders for this call
* @return String
* @throws ApiException if fails to make API call
*/
public String testsPathStringPathStringIntegerPathInteger(String pathString, Integer pathInteger, Map<String, String> additionalHeaders) throws ApiException {
public String testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath(String pathString, Integer pathInteger, String enumNonrefStringPath, StringEnumRef enumRefStringPath, Map<String, String> additionalHeaders) throws ApiException {
Object localVarPostBody = null;
// verify the required parameter 'pathString' is set
if (pathString == null) {
throw new ApiException(400, "Missing the required parameter 'pathString' when calling testsPathStringPathStringIntegerPathInteger");
throw new ApiException(400, "Missing the required parameter 'pathString' when calling testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath");
}
// verify the required parameter 'pathInteger' is set
if (pathInteger == null) {
throw new ApiException(400, "Missing the required parameter 'pathInteger' when calling testsPathStringPathStringIntegerPathInteger");
throw new ApiException(400, "Missing the required parameter 'pathInteger' when calling testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath");
}
// verify the required parameter 'enumNonrefStringPath' is set
if (enumNonrefStringPath == null) {
throw new ApiException(400, "Missing the required parameter 'enumNonrefStringPath' when calling testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath");
}
// verify the required parameter 'enumRefStringPath' is set
if (enumRefStringPath == null) {
throw new ApiException(400, "Missing the required parameter 'enumRefStringPath' when calling testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath");
}
// create path and map variables
String localVarPath = "/path/string/{path_string}/integer/{path_integer}"
String localVarPath = "/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}"
.replaceAll("\\{" + "path_string" + "\\}", apiClient.escapeString(pathString.toString()))
.replaceAll("\\{" + "path_integer" + "\\}", apiClient.escapeString(pathInteger.toString()));
.replaceAll("\\{" + "path_integer" + "\\}", apiClient.escapeString(pathInteger.toString()))
.replaceAll("\\{" + "enum_nonref_string_path" + "\\}", apiClient.escapeString(enumNonrefStringPath.toString()))
.replaceAll("\\{" + "enum_ref_string_path" + "\\}", apiClient.escapeString(enumRefStringPath.toString()));
StringJoiner localVarQueryStringJoiner = new StringJoiner("&");
String localVarQueryParameterBaseName;

View File

@@ -60,24 +60,26 @@ public class QueryApi {
/**
* Test query parameter(s)
* Test query parameter(s)
* @param enumNonrefStringQuery (optional)
* @param enumRefStringQuery (optional)
* @return String
* @throws ApiException if fails to make API call
*/
public String testEnumRefString(StringEnumRef enumRefStringQuery) throws ApiException {
return this.testEnumRefString(enumRefStringQuery, Collections.emptyMap());
public String testEnumRefString(String enumNonrefStringQuery, StringEnumRef enumRefStringQuery) throws ApiException {
return this.testEnumRefString(enumNonrefStringQuery, enumRefStringQuery, Collections.emptyMap());
}
/**
* Test query parameter(s)
* Test query parameter(s)
* @param enumNonrefStringQuery (optional)
* @param enumRefStringQuery (optional)
* @param additionalHeaders additionalHeaders for this call
* @return String
* @throws ApiException if fails to make API call
*/
public String testEnumRefString(StringEnumRef enumRefStringQuery, Map<String, String> additionalHeaders) throws ApiException {
public String testEnumRefString(String enumNonrefStringQuery, StringEnumRef enumRefStringQuery, Map<String, String> additionalHeaders) throws ApiException {
Object localVarPostBody = null;
// create path and map variables
@@ -91,6 +93,7 @@ public class QueryApi {
Map<String, String> localVarCookieParams = new HashMap<String, String>();
Map<String, Object> localVarFormParams = new HashMap<String, Object>();
localVarQueryParams.addAll(apiClient.parameterToPair("enum_nonref_string_query", enumNonrefStringQuery));
localVarQueryParams.addAll(apiClient.parameterToPair("enum_ref_string_query", enumRefStringQuery));
localVarHeaderParams.putAll(additionalHeaders);

View File

@@ -14,6 +14,7 @@
package org.openapitools.client.api;
import org.openapitools.client.ApiException;
import org.openapitools.client.model.StringEnumRef;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Assert;
@@ -42,11 +43,13 @@ public class HeaderApiTest {
* if the Api call fails
*/
@Test
public void testHeaderIntegerBooleanStringTest() throws ApiException {
public void testHeaderIntegerBooleanStringEnumsTest() throws ApiException {
Integer integerHeader = null;
Boolean booleanHeader = null;
String stringHeader = null;
String response = api.testHeaderIntegerBooleanString(integerHeader, booleanHeader, stringHeader);
String enumNonrefStringHeader = null;
StringEnumRef enumRefStringHeader = null;
String response = api.testHeaderIntegerBooleanStringEnums(integerHeader, booleanHeader, stringHeader, enumNonrefStringHeader, enumRefStringHeader);
// TODO: test validations
}

View File

@@ -14,6 +14,7 @@
package org.openapitools.client.api;
import org.openapitools.client.ApiException;
import org.openapitools.client.model.StringEnumRef;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.Assert;
@@ -42,10 +43,12 @@ public class PathApiTest {
* if the Api call fails
*/
@Test
public void testsPathStringPathStringIntegerPathIntegerTest() throws ApiException {
public void testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathTest() throws ApiException {
String pathString = null;
Integer pathInteger = null;
String response = api.testsPathStringPathStringIntegerPathInteger(pathString, pathInteger);
String enumNonrefStringPath = null;
StringEnumRef enumRefStringPath = null;
String response = api.testsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath(pathString, pathInteger, enumNonrefStringPath, enumRefStringPath);
// TODO: test validations
}