Skip to content

Commit 7b35613

Browse files
authored
[python] Encode list query params (#20148)
* Bugfix: #17688: Encode list query params * Test: #17688: Update validation error message tests for Pydantic 2.10+ Pydantic 2.10+ introduced changes to validation error messages, requiring updates to the affected test cases.
1 parent 7072009 commit 7b35613

File tree

7 files changed

+12
-7
lines changed

7 files changed

+12
-7
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -525,7 +525,7 @@ class ApiClient:
525525
if k in collection_formats:
526526
collection_format = collection_formats[k]
527527
if collection_format == 'multi':
528-
new_params.extend((k, str(value)) for value in v)
528+
new_params.extend((k, quote(str(value))) for value in v)
529529
else:
530530
if collection_format == 'ssv':
531531
delimiter = ' '

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def parameters_to_url_query(self, params, collection_formats):
518518
if k in collection_formats:
519519
collection_format = collection_formats[k]
520520
if collection_format == 'multi':
521-
new_params.extend((k, str(value)) for value in v)
521+
new_params.extend((k, quote(str(value))) for value in v)
522522
else:
523523
if collection_format == 'ssv':
524524
delimiter = ' '

samples/client/echo_api/python/openapi_client/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ def parameters_to_url_query(self, params, collection_formats):
518518
if k in collection_formats:
519519
collection_format = collection_formats[k]
520520
if collection_format == 'multi':
521-
new_params.extend((k, str(value)) for value in v)
521+
new_params.extend((k, quote(str(value))) for value in v)
522522
else:
523523
if collection_format == 'ssv':
524524
delimiter = ' '

samples/openapi3/client/petstore/python-aiohttp/petstore_api/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def parameters_to_url_query(self, params, collection_formats):
520520
if k in collection_formats:
521521
collection_format = collection_formats[k]
522522
if collection_format == 'multi':
523-
new_params.extend((k, str(value)) for value in v)
523+
new_params.extend((k, quote(str(value))) for value in v)
524524
else:
525525
if collection_format == 'ssv':
526526
delimiter = ' '

samples/openapi3/client/petstore/python/petstore_api/api_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ def parameters_to_url_query(self, params, collection_formats):
517517
if k in collection_formats:
518518
collection_format = collection_formats[k]
519519
if collection_format == 'multi':
520-
new_params.extend((k, str(value)) for value in v)
520+
new_params.extend((k, quote(str(value))) for value in v)
521521
else:
522522
if collection_format == 'ssv':
523523
delimiter = ' '

samples/openapi3/client/petstore/python/tests/test_api_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,8 @@ def test_parameters_to_url_query_list_value(self):
294294
params = self.api_client.parameters_to_url_query(params=[('list', [1, 2, 3])],
295295
collection_formats={'list': 'multi'})
296296
self.assertEqual(params, "list=1&list=2&list=3")
297+
298+
def test_parameters_to_url_query_list_value_encoded(self):
299+
params = self.api_client.parameters_to_url_query(params=[('list', [" !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", "2023-01-01T00:00:00+01:00"])],
300+
collection_formats={'list': 'multi'})
301+
self.assertEqual(params, "list=%20%21%22%23%24%25%26%27%28%29%2A%2B%2C-./%3A%3B%3C%3D%3E%3F%40%5B%5C%5D%5E_%60%7B%7C%7D~&list=2023-01-01T00%3A00%3A00%2B01%3A00")

samples/openapi3/client/petstore/python/tests/test_api_validation.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def test_required_param_validation(self):
5050
try:
5151
self.pet_api.get_pet_by_id() # type: ignore
5252
except ValidationError as e:
53-
self.assertIn("1 validation error for get_pet_by_id", str(e))
53+
self.assertIn("1 validation error for PetApi.get_pet_by_id", str(e))
5454
self.assertIn("Missing required argument", str(e))
5555

5656
def test_integer_validation(self):
@@ -61,7 +61,7 @@ def test_integer_validation(self):
6161
# pet_id
6262
# Input should be a valid integer [type=int_type, input_value='123', input_type=str]
6363
# For further information visit https://errors.pydantic.dev/2.3/v/int_type
64-
self.assertIn("1 validation error for get_pet_by_id", str(e))
64+
self.assertIn("1 validation error for PetApi.get_pet_by_id", str(e))
6565
self.assertIn("Input should be a valid integer", str(e))
6666

6767
def test_string_enum_validation(self):

0 commit comments

Comments
 (0)