forked from loafle/openapi-generator-original
[python-nextgen] support dict query params (#14727)
* [python-nextgen] convert dictionary query params to string * [python-nextgen] regenerated samples * [python-nextgen] added some test cases for parameters_to_url_query * [python-nextgen] use json.dumps instead of str(v) * [python-nextgen] update api_client tests
This commit is contained in:
@@ -549,6 +549,8 @@ class ApiClient(object):
|
|||||||
v = str(v)
|
v = str(v)
|
||||||
if isinstance(v, bool):
|
if isinstance(v, bool):
|
||||||
v = str(v).lower()
|
v = str(v).lower()
|
||||||
|
if isinstance(v, dict):
|
||||||
|
v = json.dumps(v)
|
||||||
|
|
||||||
if k in collection_formats:
|
if k in collection_formats:
|
||||||
collection_format = collection_formats[k]
|
collection_format = collection_formats[k]
|
||||||
|
|||||||
@@ -526,6 +526,8 @@ class ApiClient(object):
|
|||||||
v = str(v)
|
v = str(v)
|
||||||
if isinstance(v, bool):
|
if isinstance(v, bool):
|
||||||
v = str(v).lower()
|
v = str(v).lower()
|
||||||
|
if isinstance(v, dict):
|
||||||
|
v = json.dumps(v)
|
||||||
|
|
||||||
if k in collection_formats:
|
if k in collection_formats:
|
||||||
collection_format = collection_formats[k]
|
collection_format = collection_formats[k]
|
||||||
|
|||||||
@@ -526,6 +526,8 @@ class ApiClient(object):
|
|||||||
v = str(v)
|
v = str(v)
|
||||||
if isinstance(v, bool):
|
if isinstance(v, bool):
|
||||||
v = str(v).lower()
|
v = str(v).lower()
|
||||||
|
if isinstance(v, dict):
|
||||||
|
v = json.dumps(v)
|
||||||
|
|
||||||
if k in collection_formats:
|
if k in collection_formats:
|
||||||
collection_format = collection_formats[k]
|
collection_format = collection_formats[k]
|
||||||
|
|||||||
@@ -525,6 +525,8 @@ class ApiClient(object):
|
|||||||
v = str(v)
|
v = str(v)
|
||||||
if isinstance(v, bool):
|
if isinstance(v, bool):
|
||||||
v = str(v).lower()
|
v = str(v).lower()
|
||||||
|
if isinstance(v, dict):
|
||||||
|
v = json.dumps(v)
|
||||||
|
|
||||||
if k in collection_formats:
|
if k in collection_formats:
|
||||||
collection_format = collection_formats[k]
|
collection_format = collection_formats[k]
|
||||||
|
|||||||
@@ -212,3 +212,50 @@ class ApiClientTests(unittest.TestCase):
|
|||||||
self.assertIsNotNone(client._pool)
|
self.assertIsNotNone(client._pool)
|
||||||
atexit._run_exitfuncs()
|
atexit._run_exitfuncs()
|
||||||
self.assertIsNone(client._pool)
|
self.assertIsNone(client._pool)
|
||||||
|
|
||||||
|
def test_parameters_to_url_query(self):
|
||||||
|
data = 'value={"category": "example", "category2": "example2"}'
|
||||||
|
dictionary = {
|
||||||
|
"category": "example",
|
||||||
|
"category2": "example2"
|
||||||
|
}
|
||||||
|
result = self.api_client.parameters_to_url_query([('value', dictionary)], {})
|
||||||
|
self.assertEqual(result, data)
|
||||||
|
|
||||||
|
data='value={"number": 1, "string": "str", "bool": true, "dict": {"number": 1, "string": "str", "bool": true}}'
|
||||||
|
dictionary = {
|
||||||
|
"number": 1,
|
||||||
|
"string": "str",
|
||||||
|
"bool": True,
|
||||||
|
"dict": {
|
||||||
|
"number": 1,
|
||||||
|
"string": "str",
|
||||||
|
"bool": True
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = self.api_client.parameters_to_url_query([('value', dictionary)], {})
|
||||||
|
self.assertEqual(result, data)
|
||||||
|
|
||||||
|
data='value={"strValues": ["one", "two", "three"], "dictValues": [{"name": "value1", "age": 14}, {"name": "value2", "age": 12}]}'
|
||||||
|
dictionary = {
|
||||||
|
"strValues": [
|
||||||
|
"one",
|
||||||
|
"two",
|
||||||
|
"three"
|
||||||
|
],
|
||||||
|
"dictValues": [
|
||||||
|
{
|
||||||
|
"name": "value1",
|
||||||
|
"age": 14
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "value2",
|
||||||
|
"age": 12
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
|
result = self.api_client.parameters_to_url_query([('value', dictionary)], {})
|
||||||
|
self.assertEqual(result, data)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user