Skip to content

Commit a62132e

Browse files
authored
fix exception in request body with enum ref (#17438)
1 parent b5cd4e9 commit a62132e

39 files changed

Lines changed: 999 additions & 143 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractPythonCodegen.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2200,7 +2200,7 @@ private PythonType getType(CodegenParameter cp) {
22002200
// TODO process the first one only at the moment
22012201
if (cmt != null)
22022202
// TODO: don't loop back to the deprecated getPydanticType method
2203-
result = getPydanticType(cmt.getSchema(), typingImports, pydanticImports, datetimeImports, modelImports, exampleImports, postponedModelImports, postponedExampleImports, classname);
2203+
return getPydanticType(cmt.getSchema(), typingImports, pydanticImports, datetimeImports, modelImports, exampleImports, postponedModelImports, postponedExampleImports, classname);
22042204
}
22052205
throw new RuntimeException("Error! Failed to process getPydanticType when getting the content: " + cp);
22062206
} else {

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,11 @@ class {{classname}}:
9797
{{/servers.0}}
9898

9999
_collection_formats: Dict[str, str] = {
100-
{{#allParams}}{{#isArray}}
101-
'{{baseName}}': '{{collectionFormat}}',{{/isArray}}{{/allParams}}
100+
{{#allParams}}
101+
{{#isArray}}
102+
'{{baseName}}': '{{collectionFormat}}',
103+
{{/isArray}}
104+
{{/allParams}}
102105
}
103106

104107
_path_params: Dict[str, str] = {}

modules/openapi-generator/src/test/resources/3_0/python/petstore-with-fake-endpoints-models-for-testing.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1365,6 +1365,19 @@ paths:
13651365
type: array
13661366
items:
13671367
$ref: "#/components/schemas/ListOfObjects"
1368+
/fake/ref_enum_string:
1369+
get:
1370+
tags:
1371+
- fake
1372+
summary: test ref to enum string
1373+
operationId: fake_ref_enum_string
1374+
responses:
1375+
200:
1376+
description: OK
1377+
content:
1378+
plain/text:
1379+
schema:
1380+
$ref: "#/components/schemas/EnumClass"
13681381
servers:
13691382
- url: 'http://{server}.swagger.io:{port}/v2'
13701383
description: petstore server

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/api/auth_api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ def _test_auth_http_basic_serialize(
239239
_host = None
240240

241241
_collection_formats: Dict[str, str] = {
242-
243242
}
244243

245244
_path_params: Dict[str, str] = {}
@@ -483,7 +482,6 @@ def _test_auth_http_bearer_serialize(
483482
_host = None
484483

485484
_collection_formats: Dict[str, str] = {
486-
487485
}
488486

489487
_path_params: Dict[str, str] = {}

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/api/body_api.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ def _test_binary_gif_serialize(
247247
_host = None
248248

249249
_collection_formats: Dict[str, str] = {
250-
251250
}
252251

253252
_path_params: Dict[str, str] = {}
@@ -503,7 +502,6 @@ def _test_body_application_octetstream_binary_serialize(
503502
_host = None
504503

505504
_collection_formats: Dict[str, str] = {
506-
507505
}
508506

509507
_path_params: Dict[str, str] = {}
@@ -779,7 +777,6 @@ def _test_body_multipart_formdata_array_of_binary_serialize(
779777
_host = None
780778

781779
_collection_formats: Dict[str, str] = {
782-
783780
'files': 'csv',
784781
}
785782

@@ -1051,7 +1048,6 @@ def _test_echo_body_all_of_pet_serialize(
10511048
_host = None
10521049

10531050
_collection_formats: Dict[str, str] = {
1054-
10551051
}
10561052

10571053
_path_params: Dict[str, str] = {}
@@ -1322,7 +1318,6 @@ def _test_echo_body_free_form_object_response_string_serialize(
13221318
_host = None
13231319

13241320
_collection_formats: Dict[str, str] = {
1325-
13261321
}
13271322

13281323
_path_params: Dict[str, str] = {}
@@ -1593,7 +1588,6 @@ def _test_echo_body_pet_serialize(
15931588
_host = None
15941589

15951590
_collection_formats: Dict[str, str] = {
1596-
15971591
}
15981592

15991593
_path_params: Dict[str, str] = {}
@@ -1864,7 +1858,6 @@ def _test_echo_body_pet_response_string_serialize(
18641858
_host = None
18651859

18661860
_collection_formats: Dict[str, str] = {
1867-
18681861
}
18691862

18701863
_path_params: Dict[str, str] = {}
@@ -2135,7 +2128,6 @@ def _test_echo_body_tag_response_string_serialize(
21352128
_host = None
21362129

21372130
_collection_formats: Dict[str, str] = {
2138-
21392131
}
21402132

21412133
_path_params: Dict[str, str] = {}

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/api/form_api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ def _test_form_integer_boolean_string_serialize(
282282
_host = None
283283

284284
_collection_formats: Dict[str, str] = {
285-
286285
}
287286

288287
_path_params: Dict[str, str] = {}
@@ -622,7 +621,6 @@ def _test_form_oneof_serialize(
622621
_host = None
623622

624623
_collection_formats: Dict[str, str] = {
625-
626624
}
627625

628626
_path_params: Dict[str, str] = {}

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/api/header_api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,6 @@ def _test_header_integer_boolean_string_enums_serialize(
309309
_host = None
310310

311311
_collection_formats: Dict[str, str] = {
312-
313312
}
314313

315314
_path_params: Dict[str, str] = {}

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/api/path_api.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ def _tests_path_string_path_string_integer_path_integer_enum_nonref_string_path_
294294
_host = None
295295

296296
_collection_formats: Dict[str, str] = {
297-
298297
}
299298

300299
_path_params: Dict[str, str] = {}

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent-true/openapi_client/api/query_api.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,6 @@ def _test_enum_ref_string_serialize(
274274
_host = None
275275

276276
_collection_formats: Dict[str, str] = {
277-
278277
}
279278

280279
_path_params: Dict[str, str] = {}
@@ -564,7 +563,6 @@ def _test_query_datetime_date_string_serialize(
564563
_host = None
565564

566565
_collection_formats: Dict[str, str] = {
567-
568566
}
569567

570568
_path_params: Dict[str, str] = {}
@@ -876,7 +874,6 @@ def _test_query_integer_boolean_string_serialize(
876874
_host = None
877875

878876
_collection_formats: Dict[str, str] = {
879-
880877
}
881878

882879
_path_params: Dict[str, str] = {}
@@ -1144,7 +1141,6 @@ def _test_query_style_deep_object_explode_true_object_serialize(
11441141
_host = None
11451142

11461143
_collection_formats: Dict[str, str] = {
1147-
11481144
}
11491145

11501146
_path_params: Dict[str, str] = {}
@@ -1404,7 +1400,6 @@ def _test_query_style_deep_object_explode_true_object_all_of_serialize(
14041400
_host = None
14051401

14061402
_collection_formats: Dict[str, str] = {
1407-
14081403
}
14091404

14101405
_path_params: Dict[str, str] = {}
@@ -1664,7 +1659,6 @@ def _test_query_style_form_explode_true_array_string_serialize(
16641659
_host = None
16651660

16661661
_collection_formats: Dict[str, str] = {
1667-
16681662
}
16691663

16701664
_path_params: Dict[str, str] = {}
@@ -1924,7 +1918,6 @@ def _test_query_style_form_explode_true_object_serialize(
19241918
_host = None
19251919

19261920
_collection_formats: Dict[str, str] = {
1927-
19281921
}
19291922

19301923
_path_params: Dict[str, str] = {}
@@ -2184,7 +2177,6 @@ def _test_query_style_form_explode_true_object_all_of_serialize(
21842177
_host = None
21852178

21862179
_collection_formats: Dict[str, str] = {
2187-
21882180
}
21892181

21902182
_path_params: Dict[str, str] = {}

samples/client/echo_api/python/openapi_client/api/auth_api.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,6 @@ def _test_auth_http_basic_serialize(
239239
_host = None
240240

241241
_collection_formats: Dict[str, str] = {
242-
243242
}
244243

245244
_path_params: Dict[str, str] = {}
@@ -483,7 +482,6 @@ def _test_auth_http_bearer_serialize(
483482
_host = None
484483

485484
_collection_formats: Dict[str, str] = {
486-
487485
}
488486

489487
_path_params: Dict[str, str] = {}

0 commit comments

Comments
 (0)