Skip to content

Commit

Permalink
Fix parameters_to_url_query doesn't properly convert lists to string (O…
Browse files Browse the repository at this point in the history
…penAPITools#17592)

* fix parameters_to_url_query to properly handle lists

* fix query parameters bug in sample clients

* add tests for url query list value

* build project

* tests fix

* Revert "build project"

This reverts commit a486a6d.
  • Loading branch information
rshacham authored Jan 13, 2024
1 parent b01b182 commit 406bc28
Show file tree
Hide file tree
Showing 13 changed files with 29 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ class ApiClient:
if k in collection_formats:
collection_format = collection_formats[k]
if collection_format == 'multi':
new_params.extend((k, value) for value in v)
new_params.extend((k, 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 @@ -491,7 +491,7 @@ class ApiClient:
if k in collection_formats:
collection_format = collection_formats[k]
if collection_format == 'multi':
new_params.extend((k, value) for value in v)
new_params.extend((k, 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 @@ -484,7 +484,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, value) for value in v)
new_params.extend((k, 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 @@ -539,7 +539,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, value) for value in v)
new_params.extend((k, 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 @@ -149,6 +149,12 @@ def test_parameters_to_url_query_boolean_value(self):
client = openapi_client.ApiClient()
params = client.parameters_to_url_query([("boolean", True),], {})
self.assertEqual(params, "boolean=true")

def test_parameters_to_url_query_list_value(self):
client = openapi_client.ApiClient()
params = client.parameters_to_url_query(params=[('list', [1, 2, 3])], collection_formats={'list': 'multi'})
self.assertEqual(params, "list=1&list=2&list=3")


def echoServerResponseParaserTest(self):
s = """POST /echo/body/Pet/response_string HTTP/1.1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,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, value) for value in v)
new_params.extend((k, str(value)) for value in v)
else:
if collection_format == 'ssv':
delimiter = ' '
Expand Down
7 changes: 6 additions & 1 deletion samples/client/echo_api/python/tests/test_manual.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,12 @@ def test_parameters_to_url_query_boolean_value(self):
client = openapi_client.ApiClient()
params = client.parameters_to_url_query([("boolean", True),], {})
self.assertEqual(params, "boolean=true")


def test_parameters_to_url_query_list_value(self):
client = openapi_client.ApiClient()
params = client.parameters_to_url_query(params=[('list', [1, 2, 3])], collection_formats={'list': 'multi'})
self.assertEqual(params, "list=1&list=2&list=3")

def echoServerResponseParaserTest(self):
s = """POST /echo/body/Pet/response_string HTTP/1.1
Host: localhost:3000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,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, value) for value in v)
new_params.extend((k, 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 @@ -509,7 +509,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, value) for value in v)
new_params.extend((k, 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 @@ -538,7 +538,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, value) for value in v)
new_params.extend((k, 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 @@ -260,3 +260,7 @@ def test_parameters_to_url_query(self):
def test_parameters_to_url_query_boolean_value(self):
result = self.api_client.parameters_to_url_query([('boolean', True)], {})
self.assertEqual(result, "boolean=true")

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")
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,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, value) for value in v)
new_params.extend((k, 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 @@ -245,3 +245,7 @@ def test_parameters_to_url_query_dict_values(self):
def test_parameters_to_url_query_boolean_value(self):
result = self.api_client.parameters_to_url_query([('boolean', True)], {})
self.assertEqual(result, "boolean=true")

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")

0 comments on commit 406bc28

Please sign in to comment.