Skip to content

[python] Encode list query params #20148

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -525,7 +525,7 @@ class ApiClient:
if k in collection_formats:
collection_format = collection_formats[k]
if collection_format == 'multi':
new_params.extend((k, str(value)) for value in v)
new_params.extend((k, quote(str(value))) for value in v)
else:
if collection_format == 'ssv':
delimiter = ' '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def parameters_to_url_query(self, params, collection_formats):
if k in collection_formats:
collection_format = collection_formats[k]
if collection_format == 'multi':
new_params.extend((k, str(value)) for value in v)
new_params.extend((k, quote(str(value))) for value in v)
else:
if collection_format == 'ssv':
delimiter = ' '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ def parameters_to_url_query(self, params, collection_formats):
if k in collection_formats:
collection_format = collection_formats[k]
if collection_format == 'multi':
new_params.extend((k, str(value)) for value in v)
new_params.extend((k, quote(str(value))) for value in v)
else:
if collection_format == 'ssv':
delimiter = ' '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,7 @@ def parameters_to_url_query(self, params, collection_formats):
if k in collection_formats:
collection_format = collection_formats[k]
if collection_format == 'multi':
new_params.extend((k, str(value)) for value in v)
new_params.extend((k, quote(str(value))) for value in v)
else:
if collection_format == 'ssv':
delimiter = ' '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ def parameters_to_url_query(self, params, collection_formats):
if k in collection_formats:
collection_format = collection_formats[k]
if collection_format == 'multi':
new_params.extend((k, str(value)) for value in v)
new_params.extend((k, quote(str(value))) for value in v)
else:
if collection_format == 'ssv':
delimiter = ' '
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,8 @@ def test_parameters_to_url_query_list_value(self):
params = self.api_client.parameters_to_url_query(params=[('list', [1, 2, 3])],
collection_formats={'list': 'multi'})
self.assertEqual(params, "list=1&list=2&list=3")

def test_parameters_to_url_query_list_value_encoded(self):
params = self.api_client.parameters_to_url_query(params=[('list', [" !\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~", "2023-01-01T00:00:00+01:00"])],
collection_formats={'list': 'multi'})
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")
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_required_param_validation(self):
try:
self.pet_api.get_pet_by_id() # type: ignore
except ValidationError as e:
self.assertIn("1 validation error for get_pet_by_id", str(e))
self.assertIn("1 validation error for PetApi.get_pet_by_id", str(e))
self.assertIn("Missing required argument", str(e))

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

def test_string_enum_validation(self):
Expand Down
Loading