Skip to content

Commit

Permalink
[python] Add tests and fix enum path parameters (#16769)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
robertschweizer and wing328 authored Oct 10, 2023
1 parent 7bb75f4 commit 9e07f85
Show file tree
Hide file tree
Showing 88 changed files with 1,548 additions and 537 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class {{classname}}:
_path_params: Dict[str, str] = {}
{{#pathParams}}
if _params['{{paramName}}'] is not None:
_path_params['{{baseName}}'] = _params['{{paramName}}']
_path_params['{{baseName}}'] = _params['{{paramName}}']{{#isEnumRef}}.value{{/isEnumRef}}
{{#isArray}}
_collection_formats['{{baseName}}'] = '{{collectionFormat}}'
{{/isArray}}
Expand Down
48 changes: 44 additions & 4 deletions modules/openapi-generator/src/test/resources/3_0/echo_api.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ paths:
# will response with the same body in the HTTP request.
#
# path parameter tests
/path/string/{path_string}/integer/{path_integer}:
/path/string/{path_string}/integer/{path_integer}/{enum_nonref_string_path}/{enum_ref_string_path}:
get:
tags:
- path
summary: Test path parameter(s)
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:
- in: path
name: path_string
Expand All @@ -49,6 +49,20 @@ paths:
required: true
schema:
type: integer
- in: path
name: enum_nonref_string_path
required: true
schema:
type: string
enum:
- success
- failure
- unclassified
- in: path
name: enum_ref_string_path
required: true
schema:
$ref: '#/components/schemas/StringEnumRef'
responses:
'200':
description: Successful operation
Expand Down Expand Up @@ -118,13 +132,13 @@ paths:
schema:
type: string
# header parameter tests
/header/integer/boolean/string:
/header/integer/boolean/string/enums:
get:
tags:
- header
summary: Test header parameter(s)
description: Test header parameter(s)
operationId: test/header/integer/boolean/string
operationId: test/header/integer/boolean/string/enums
parameters:
- in: header
name: integer_header
Expand All @@ -144,6 +158,22 @@ paths:
explode: true #default
schema:
type: string
- in: header
name: enum_nonref_string_header
style: form #default
explode: true #default
schema:
type: string
enum:
- success
- failure
- unclassified
- in: header
name: enum_ref_string_header
style: form #default
explode: true #default
schema:
$ref: '#/components/schemas/StringEnumRef'
responses:
'200':
description: Successful operation
Expand All @@ -160,6 +190,16 @@ paths:
description: Test query parameter(s)
operationId: test/enum_ref_string
parameters:
- in: query
name: enum_nonref_string_query
style: form #default
explode: true #default
schema:
type: string
enum:
- success
- failure
- unclassified
- in: query
name: enum_ref_string_query
style: form #default
Expand Down
4 changes: 2 additions & 2 deletions samples/client/echo_api/csharp-restsharp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,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)
Expand Down
55 changes: 51 additions & 4 deletions samples/client/echo_api/csharp-restsharp/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down Expand Up @@ -78,10 +96,10 @@ paths:
summary: Test form parameter(s) for oneOf schema
tags:
- form
/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
Expand All @@ -104,6 +122,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:
Expand All @@ -119,6 +155,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
Expand Down
24 changes: 14 additions & 10 deletions samples/client/echo_api/csharp-restsharp/docs/HeaderApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ 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) |

<a id="testheaderintegerbooleanstring"></a>
# **TestHeaderIntegerBooleanString**
> string TestHeaderIntegerBooleanString (int? integerHeader = null, bool? booleanHeader = null, string? stringHeader = null)
<a id="testheaderintegerbooleanstringenums"></a>
# **TestHeaderIntegerBooleanStringEnums**
> string TestHeaderIntegerBooleanStringEnums (int? integerHeader = null, bool? booleanHeader = null, string? stringHeader = null, string? enumNonrefStringHeader = null, StringEnumRef? enumRefStringHeader = null)
Test header parameter(s)

Expand All @@ -24,7 +24,7 @@ using Org.OpenAPITools.Model;

namespace Example
{
public class TestHeaderIntegerBooleanStringExample
public class TestHeaderIntegerBooleanStringEnumsExample
{
public static void Main()
{
Expand All @@ -34,16 +34,18 @@ namespace Example
var integerHeader = 56; // int? | (optional)
var booleanHeader = true; // bool? | (optional)
var stringHeader = "stringHeader_example"; // string? | (optional)
var enumNonrefStringHeader = "success"; // string? | (optional)
var enumRefStringHeader = new StringEnumRef?(); // StringEnumRef? | (optional)
try
{
// Test header parameter(s)
string result = apiInstance.TestHeaderIntegerBooleanString(integerHeader, booleanHeader, stringHeader);
string result = apiInstance.TestHeaderIntegerBooleanStringEnums(integerHeader, booleanHeader, stringHeader, enumNonrefStringHeader, enumRefStringHeader);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling HeaderApi.TestHeaderIntegerBooleanString: " + e.Message);
Debug.Print("Exception when calling HeaderApi.TestHeaderIntegerBooleanStringEnums: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
Expand All @@ -52,21 +54,21 @@ namespace Example
}
```

#### Using the TestHeaderIntegerBooleanStringWithHttpInfo variant
#### Using the TestHeaderIntegerBooleanStringEnumsWithHttpInfo variant
This returns an ApiResponse object which contains the response data, status code and headers.

```csharp
try
{
// Test header parameter(s)
ApiResponse<string> response = apiInstance.TestHeaderIntegerBooleanStringWithHttpInfo(integerHeader, booleanHeader, stringHeader);
ApiResponse<string> response = apiInstance.TestHeaderIntegerBooleanStringEnumsWithHttpInfo(integerHeader, booleanHeader, stringHeader, enumNonrefStringHeader, enumRefStringHeader);
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 HeaderApi.TestHeaderIntegerBooleanStringWithHttpInfo: " + e.Message);
Debug.Print("Exception when calling HeaderApi.TestHeaderIntegerBooleanStringEnumsWithHttpInfo: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
Expand All @@ -79,6 +81,8 @@ catch (ApiException e)
| **integerHeader** | **int?** | | [optional] |
| **booleanHeader** | **bool?** | | [optional] |
| **stringHeader** | **string?** | | [optional] |
| **enumNonrefStringHeader** | **string?** | | [optional] |
| **enumRefStringHeader** | [**StringEnumRef?**](StringEnumRef?.md) | | [optional] |

### Return type

Expand Down
24 changes: 14 additions & 10 deletions samples/client/echo_api/csharp-restsharp/docs/PathApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ 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) |

<a id="testspathstringpathstringintegerpathinteger"></a>
# **TestsPathStringPathStringIntegerPathInteger**
> string TestsPathStringPathStringIntegerPathInteger (string pathString, int pathInteger)
<a id="testspathstringpathstringintegerpathintegerenumnonrefstringpathenumrefstringpath"></a>
# **TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath**
> string TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath (string pathString, int pathInteger, string enumNonrefStringPath, StringEnumRef enumRefStringPath)
Test path parameter(s)

Expand All @@ -24,7 +24,7 @@ using Org.OpenAPITools.Model;

namespace Example
{
public class TestsPathStringPathStringIntegerPathIntegerExample
public class TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathExample
{
public static void Main()
{
Expand All @@ -33,16 +33,18 @@ namespace Example
var apiInstance = new PathApi(config);
var pathString = "pathString_example"; // string |
var pathInteger = 56; // int |
var enumNonrefStringPath = "success"; // string |
var enumRefStringPath = new StringEnumRef(); // StringEnumRef |
try
{
// Test path parameter(s)
string result = apiInstance.TestsPathStringPathStringIntegerPathInteger(pathString, pathInteger);
string result = apiInstance.TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath(pathString, pathInteger, enumNonrefStringPath, enumRefStringPath);
Debug.WriteLine(result);
}
catch (ApiException e)
{
Debug.Print("Exception when calling PathApi.TestsPathStringPathStringIntegerPathInteger: " + e.Message);
Debug.Print("Exception when calling PathApi.TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPath: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
Expand All @@ -51,21 +53,21 @@ namespace Example
}
```

#### Using the TestsPathStringPathStringIntegerPathIntegerWithHttpInfo variant
#### Using the TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathWithHttpInfo variant
This returns an ApiResponse object which contains the response data, status code and headers.

```csharp
try
{
// Test path parameter(s)
ApiResponse<string> response = apiInstance.TestsPathStringPathStringIntegerPathIntegerWithHttpInfo(pathString, pathInteger);
ApiResponse<string> response = apiInstance.TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathWithHttpInfo(pathString, pathInteger, enumNonrefStringPath, enumRefStringPath);
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 PathApi.TestsPathStringPathStringIntegerPathIntegerWithHttpInfo: " + e.Message);
Debug.Print("Exception when calling PathApi.TestsPathStringPathStringIntegerPathIntegerEnumNonrefStringPathEnumRefStringPathWithHttpInfo: " + e.Message);
Debug.Print("Status Code: " + e.ErrorCode);
Debug.Print(e.StackTrace);
}
Expand All @@ -77,6 +79,8 @@ catch (ApiException e)
|------|------|-------------|-------|
| **pathString** | **string** | | |
| **pathInteger** | **int** | | |
| **enumNonrefStringPath** | **string** | | |
| **enumRefStringPath** | [**StringEnumRef**](StringEnumRef.md) | | |

### Return type

Expand Down
Loading

0 comments on commit 9e07f85

Please sign in to comment.