Skip to content

Commit aa7c62a

Browse files
authored
[BUG] [Python] Fix autoset constants Python code for default query string value (#19138)
* _query_params is list, not dict * Add test
1 parent aaeed0f commit aa7c62a

3 files changed

Lines changed: 10 additions & 2 deletions

File tree

modules/openapi-generator/src/main/resources/python/api.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class {{classname}}:
176176
{{#constantParams}}
177177
{{#isQueryParam}}
178178
# Set client side default value of Query Param "{{baseName}}".
179-
_query_params['{{baseName}}'] = {{#_enum}}'{{{.}}}'{{/_enum}}
179+
_query_params.append(('{{baseName}}', {{#_enum}}'{{{.}}}'{{/_enum}}))
180180
{{/isQueryParam}}
181181
{{#isHeaderParam}}
182182
# Set client side default value of Header Param "{{baseName}}".

modules/openapi-generator/src/test/java/org/openapitools/codegen/python/PythonClientCodegenTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,5 +528,6 @@ public void testHandleConstantParams() throws IOException {
528528
.get(Paths.get(output.getAbsolutePath(), "openapi_client", "api", "hello_example_api.py").toString());
529529
assertNotNull(apiFile);
530530
assertFileContains(apiFile.toPath(), "_header_params['X-CUSTOM_CONSTANT_HEADER'] = 'CONSTANT_VALUE'");
531+
assertFileContains(apiFile.toPath(), "_query_params.append(('CONSTANT_QUERY_STRING_KEY', 'CONSTANT_QUERY_STRING_VALUE'))");
531532
}
532533
}

modules/openapi-generator/src/test/resources/3_0/java/autoset_constant.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,13 @@ paths:
2121
type: string
2222
enum:
2323
- CONSTANT_VALUE
24+
- name: CONSTANT_QUERY_STRING_KEY
25+
in: query
26+
required: true
27+
schema:
28+
type: string
29+
enum:
30+
- CONSTANT_QUERY_STRING_VALUE
2431
- name: name
2532
in: path
2633
required: true
@@ -39,4 +46,4 @@ components:
3946
type: object
4047
properties:
4148
message:
42-
type: string
49+
type: string

0 commit comments

Comments
 (0)