[python-nextgen] Add datetime, date format support (#14799)

* add datetime, date format support in python nextgen

* encode query parameters

* update default datetime format

* change default datetime format
This commit is contained in:
William Cheng
2023-03-01 15:29:47 +08:00
committed by GitHub
parent 854f8dbc6d
commit e82ae6bacd
32 changed files with 216 additions and 313 deletions

View File

@@ -145,14 +145,11 @@ class BodyApi(object):
# process the query parameters
_query_params = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
# process the body parameter
_body_params = None
if _params['pet']:
@@ -295,14 +292,11 @@ class BodyApi(object):
# process the query parameters
_query_params = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
# process the body parameter
_body_params = None
if _params['pet']:

View File

@@ -154,23 +154,22 @@ class FormApi(object):
# process the query parameters
_query_params = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
if _params['integer_form']:
_form_params.append(('integer_form', _params['integer_form']))
if _params['boolean_form']:
_form_params.append(('boolean_form', _params['boolean_form']))
if _params['string_form']:
_form_params.append(('string_form', _params['string_form']))
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
_header_params['Accept'] = self.api_client.select_header_accept(
['text/plain']) # noqa: E501

View File

@@ -154,23 +154,22 @@ class HeaderApi(object):
# process the query parameters
_query_params = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
if _params['integer_header']:
_header_params['integer_header'] = _params['integer_header']
if _params['boolean_header']:
_header_params['boolean_header'] = _params['boolean_header']
if _params['string_header']:
_header_params['string_header'] = _params['string_header']
# process the form parameters
_form_params = []
_files = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
_header_params['Accept'] = self.api_client.select_header_accept(
['text/plain']) # noqa: E501

View File

@@ -146,22 +146,20 @@ class PathApi(object):
_path_params = {}
if _params['path_string']:
_path_params['path_string'] = _params['path_string']
if _params['path_integer']:
_path_params['path_integer'] = _params['path_integer']
# process the query parameters
_query_params = []
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
_header_params['Accept'] = self.api_client.select_header_accept(
['text/plain']) # noqa: E501

View File

@@ -157,22 +157,27 @@ class QueryApi(object):
# process the query parameters
_query_params = []
if _params.get('datetime_query') is not None: # noqa: E501
_query_params.append(('datetime_query', _params['datetime_query']))
if isinstance(_params['datetime_query'], datetime):
_query_params.append(('datetime_query', _params['datetime_query'].strftime(self.api_client.configuration.datetime_format)))
else:
_query_params.append(('datetime_query', _params['datetime_query']))
if _params.get('date_query') is not None: # noqa: E501
_query_params.append(('date_query', _params['date_query']))
if isinstance(_params['date_query'], datetime):
_query_parame.append(('date_query', _params['date_query'].strftime(self.api_client.configuration.date_format)))
else:
_query_params.append(('date_query', _params['date_query']))
if _params.get('string_query') is not None: # noqa: E501
_query_params.append(('string_query', _params['string_query']))
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
_header_params['Accept'] = self.api_client.select_header_accept(
['text/plain']) # noqa: E501
@@ -315,21 +320,20 @@ class QueryApi(object):
_query_params = []
if _params.get('integer_query') is not None: # noqa: E501
_query_params.append(('integer_query', _params['integer_query']))
if _params.get('boolean_query') is not None: # noqa: E501
_query_params.append(('boolean_query', _params['boolean_query']))
if _params.get('string_query') is not None: # noqa: E501
_query_params.append(('string_query', _params['string_query']))
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
_header_params['Accept'] = self.api_client.select_header_accept(
['text/plain']) # noqa: E501
@@ -465,14 +469,11 @@ class QueryApi(object):
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
_header_params['Accept'] = self.api_client.select_header_accept(
['text/plain']) # noqa: E501
@@ -608,14 +609,11 @@ class QueryApi(object):
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
_header_params['Accept'] = self.api_client.select_header_accept(
['text/plain']) # noqa: E501
@@ -751,14 +749,11 @@ class QueryApi(object):
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
_header_params['Accept'] = self.api_client.select_header_accept(
['text/plain']) # noqa: E501
@@ -894,14 +889,11 @@ class QueryApi(object):
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
_header_params['Accept'] = self.api_client.select_header_accept(
['text/plain']) # noqa: E501
@@ -1037,14 +1029,11 @@ class QueryApi(object):
# process the header parameters
_header_params = dict(_params.get('_headers', {}))
# process the form parameters
_form_params = []
_files = {}
# process the body parameter
_body_params = None
# set the HTTP header `Accept`
_header_params['Accept'] = self.api_client.select_header_accept(
['text/plain']) # noqa: E501

View File

@@ -545,7 +545,7 @@ class ApiClient(object):
new_params.append(
(k, delimiter.join(quote(str(value)) for value in v)))
else:
new_params.append((k, v))
new_params.append((k, quote(str(v))))
return "&".join(["=".join(item) for item in new_params])

View File

@@ -175,6 +175,14 @@ class Configuration(object):
"""Options to pass down to the underlying urllib3 socket
"""
self.datetime_format = "%Y-%m-%dT%H:%M:%S.%f%z"
"""datetime format
"""
self.date_format = "%Y-%m-%d"
"""date format
"""
def __deepcopy__(self, memo):
cls = self.__class__
result = cls.__new__(cls)

View File

@@ -28,16 +28,28 @@ class TestManual(unittest.TestCase):
def tearDown(self):
pass
def testDateTimeQueryWithDateTimeFormat(self):
api_instance = openapi_client.QueryApi()
api_instance.api_client.configuration.datetime_format = "%Y-%m-%d %a %H:%M:%S%Z"
datetime_query = datetime.datetime.fromisoformat('2013-10-20T19:20:30-05:00') # datetime | (optional)
date_query = '2013-10-20' # date | (optional)
string_query = 'string_query_example' # str | (optional)
# Test query parameter(s)
api_response = api_instance.test_query_datetime_date_string(datetime_query=datetime_query, date_query=date_query, string_query=string_query)
e = EchoServerResponseParser(api_response)
self.assertEqual(e.path, "/query/datetime/date/string?datetime_query=2013-10-20%20Sun%2019%3A20%3A30UTC-05%3A00&date_query=2013-10-20&string_query=string_query_example")
def testDateTimeQueryWithDateTime(self):
api_instance = openapi_client.QueryApi()
datetime_query = datetime.datetime.fromisoformat('2013-10-20T19:20:30+01:00') # datetime | (optional)
datetime_query = datetime.datetime.fromisoformat('2013-10-20T19:20:30-05:00') # datetime | (optional)
date_query = '2013-10-20' # date | (optional)
string_query = 'string_query_example' # str | (optional)
# Test query parameter(s)
api_response = api_instance.test_query_datetime_date_string(datetime_query=datetime_query, date_query=date_query, string_query=string_query)
e = EchoServerResponseParser(api_response)
self.assertEqual(e.path, "/query/datetime/date/string?datetime_query=2013-10-20T19:20:30+01:00&date_query=2013-10-20&string_query=string_query_example")
self.assertEqual(e.path, "/query/datetime/date/string?datetime_query=2013-10-20T19%3A20%3A30.000000-0500&date_query=2013-10-20&string_query=string_query_example")
def testDateTimeQueryWithString(self):
api_instance = openapi_client.QueryApi()
@@ -48,7 +60,7 @@ class TestManual(unittest.TestCase):
# Test query parameter(s)
api_response = api_instance.test_query_datetime_date_string(datetime_query=datetime_query, date_query=date_query, string_query=string_query)
e = EchoServerResponseParser(api_response)
self.assertEqual(e.path, "/query/datetime/date/string?datetime_query=19:20:30%202013-10-20&date_query=2013-10-20&string_query=string_query_example")
self.assertEqual(e.path, "/query/datetime/date/string?datetime_query=19%3A20%3A30%202013-10-20&date_query=2013-10-20&string_query=string_query_example")
class EchoServerResponseParser():
def __init__(self, http_response):