Skip to content

Commit 42462db

Browse files
authored
Merge pull request #8900 from AlexInGitHub/master
fix the polymorphic issue
2 parents e15bbc9 + 10f0de6 commit 42462db

File tree

4 files changed

+34
-28
lines changed

4 files changed

+34
-28
lines changed

modules/swagger-codegen/src/main/resources/python/api_client.mustache

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -597,6 +597,9 @@ class ApiClient(object):
597597
)
598598
)
599599

600+
def __hasattr(self, object, name):
601+
return name in object.__class__.__dict__
602+
600603
def __deserialize_model(self, data, klass):
601604
"""Deserializes list or dict to model.
602605

@@ -605,8 +608,7 @@ class ApiClient(object):
605608
:return: model object.
606609
"""
607610

608-
if not klass.swagger_types and not hasattr(klass,
609-
'get_real_child_model'):
611+
if not klass.swagger_types and not self.__hasattr(klass, 'get_real_child_model'):
610612
return data
611613

612614
kwargs = {}
@@ -626,7 +628,7 @@ class ApiClient(object):
626628
for key, value in data.items():
627629
if key not in klass.swagger_types:
628630
instance[key] = value
629-
if hasattr(instance, 'get_real_child_model'):
631+
if self.__hasattr(instance, 'get_real_child_model'):
630632
klass_name = instance.get_real_child_model(data)
631633
if klass_name:
632634
instance = self.__deserialize(data, klass_name)

samples/client/petstore-security-test/python/petstore_api/api/fake_api.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,43 +34,43 @@ def __init__(self, api_client=None):
3434
self.api_client = api_client
3535

3636
def test_code_inject____end__rn_n_r(self, **kwargs): # noqa: E501
37-
"""To test code injection */ ' \" =end -- \\r\\n \\n \\r # noqa: E501
37+
"""To test code injection */ ' \" =end -- \\r\\n \\n \\r # noqa: E501
3838
3939
This method makes a synchronous HTTP request by default. To make an
40-
asynchronous HTTP request, please pass async=True
41-
>>> thread = api.test_code_inject____end__rn_n_r(async=True)
40+
asynchronous HTTP request, please pass async_req=True
41+
>>> thread = api.test_code_inject____end__rn_n_r(async_req=True)
4242
>>> result = thread.get()
4343
44-
:param async bool
44+
:param async_req bool
4545
:param str test_code_inject____end____rn_n_r: To test code injection */ ' \" =end -- \\r\\n \\n \\r
4646
:return: None
4747
If the method is called asynchronously,
4848
returns the request thread.
4949
"""
5050
kwargs['_return_http_data_only'] = True
51-
if kwargs.get('async'):
51+
if kwargs.get('async_req'):
5252
return self.test_code_inject____end__rn_n_r_with_http_info(**kwargs) # noqa: E501
5353
else:
5454
(data) = self.test_code_inject____end__rn_n_r_with_http_info(**kwargs) # noqa: E501
5555
return data
5656

5757
def test_code_inject____end__rn_n_r_with_http_info(self, **kwargs): # noqa: E501
58-
"""To test code injection */ ' \" =end -- \\r\\n \\n \\r # noqa: E501
58+
"""To test code injection */ ' \" =end -- \\r\\n \\n \\r # noqa: E501
5959
6060
This method makes a synchronous HTTP request by default. To make an
61-
asynchronous HTTP request, please pass async=True
62-
>>> thread = api.test_code_inject____end__rn_n_r_with_http_info(async=True)
61+
asynchronous HTTP request, please pass async_req=True
62+
>>> thread = api.test_code_inject____end__rn_n_r_with_http_info(async_req=True)
6363
>>> result = thread.get()
6464
65-
:param async bool
65+
:param async_req bool
6666
:param str test_code_inject____end____rn_n_r: To test code injection */ ' \" =end -- \\r\\n \\n \\r
6767
:return: None
6868
If the method is called asynchronously,
6969
returns the request thread.
7070
"""
7171

7272
all_params = ['test_code_inject____end____rn_n_r'] # noqa: E501
73-
all_params.append('async')
73+
all_params.append('async_req')
7474
all_params.append('_return_http_data_only')
7575
all_params.append('_preload_content')
7676
all_params.append('_request_timeout')
@@ -120,7 +120,7 @@ def test_code_inject____end__rn_n_r_with_http_info(self, **kwargs): # noqa: E50
120120
files=local_var_files,
121121
response_type=None, # noqa: E501
122122
auth_settings=auth_settings,
123-
async=params.get('async'),
123+
async_req=params.get('async_req'),
124124
_return_http_data_only=params.get('_return_http_data_only'),
125125
_preload_content=params.get('_preload_content', True),
126126
_request_timeout=params.get('_request_timeout'),

samples/client/petstore-security-test/python/petstore_api/api_client.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -245,12 +245,12 @@ def __deserialize(self, data, klass):
245245

246246
if type(klass) == str:
247247
if klass.startswith('list['):
248-
sub_kls = re.match('list\[(.*)\]', klass).group(1)
248+
sub_kls = re.match(r'list\[(.*)\]', klass).group(1)
249249
return [self.__deserialize(sub_data, sub_kls)
250250
for sub_data in data]
251251

252252
if klass.startswith('dict('):
253-
sub_kls = re.match('dict\(([^,]*), (.*)\)', klass).group(2)
253+
sub_kls = re.match(r'dict\(([^,]*), (.*)\)', klass).group(2)
254254
return {k: self.__deserialize(v, sub_kls)
255255
for k, v in six.iteritems(data)}
256256

@@ -274,12 +274,12 @@ def __deserialize(self, data, klass):
274274
def call_api(self, resource_path, method,
275275
path_params=None, query_params=None, header_params=None,
276276
body=None, post_params=None, files=None,
277-
response_type=None, auth_settings=None, async=None,
277+
response_type=None, auth_settings=None, async_req=None,
278278
_return_http_data_only=None, collection_formats=None,
279279
_preload_content=True, _request_timeout=None):
280280
"""Makes the HTTP request (synchronous) and returns deserialized data.
281281
282-
To make an async request, set the async parameter.
282+
To make an async request, set the async_req parameter.
283283
284284
:param resource_path: Path to method endpoint.
285285
:param method: Method to call.
@@ -294,7 +294,7 @@ def call_api(self, resource_path, method,
294294
:param response: Response data type.
295295
:param files dict: key -> filename, value -> filepath,
296296
for `multipart/form-data`.
297-
:param async bool: execute request asynchronously
297+
:param async_req bool: execute request asynchronously
298298
:param _return_http_data_only: response data without head status code
299299
and headers
300300
:param collection_formats: dict of collection formats for path, query,
@@ -307,13 +307,13 @@ def call_api(self, resource_path, method,
307307
timeout. It can also be a pair (tuple) of
308308
(connection, read) timeouts.
309309
:return:
310-
If async parameter is True,
310+
If async_req parameter is True,
311311
the request will be called asynchronously.
312312
The method will return the request thread.
313-
If parameter async is False or missing,
313+
If parameter async_req is False or missing,
314314
then the method will return the response directly.
315315
"""
316-
if not async:
316+
if not async_req:
317317
return self.__call_api(resource_path, method,
318318
path_params, query_params, header_params,
319319
body, post_params, files,
@@ -591,6 +591,9 @@ def __deserialize_datatime(self, string):
591591
)
592592
)
593593

594+
def __hasattr(self, object, name):
595+
return name in object.__class__.__dict__
596+
594597
def __deserialize_model(self, data, klass):
595598
"""Deserializes list or dict to model.
596599
@@ -599,8 +602,7 @@ def __deserialize_model(self, data, klass):
599602
:return: model object.
600603
"""
601604

602-
if not klass.swagger_types and not hasattr(klass,
603-
'get_real_child_model'):
605+
if not klass.swagger_types and not self.__hasattr(klass, 'get_real_child_model'):
604606
return data
605607

606608
kwargs = {}
@@ -620,7 +622,7 @@ def __deserialize_model(self, data, klass):
620622
for key, value in data.items():
621623
if key not in klass.swagger_types:
622624
instance[key] = value
623-
if hasattr(instance, 'get_real_child_model'):
625+
if self.__hasattr(instance, 'get_real_child_model'):
624626
klass_name = instance.get_real_child_model(data)
625627
if klass_name:
626628
instance = self.__deserialize(data, klass_name)

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -591,6 +591,9 @@ def __deserialize_datatime(self, string):
591591
)
592592
)
593593

594+
def __hasattr(self, object, name):
595+
return name in object.__class__.__dict__
596+
594597
def __deserialize_model(self, data, klass):
595598
"""Deserializes list or dict to model.
596599
@@ -599,8 +602,7 @@ def __deserialize_model(self, data, klass):
599602
:return: model object.
600603
"""
601604

602-
if not klass.swagger_types and not hasattr(klass,
603-
'get_real_child_model'):
605+
if not klass.swagger_types and not self.__hasattr(klass, 'get_real_child_model'):
604606
return data
605607

606608
kwargs = {}
@@ -620,7 +622,7 @@ def __deserialize_model(self, data, klass):
620622
for key, value in data.items():
621623
if key not in klass.swagger_types:
622624
instance[key] = value
623-
if hasattr(instance, 'get_real_child_model'):
625+
if self.__hasattr(instance, 'get_real_child_model'):
624626
klass_name = instance.get_real_child_model(data)
625627
if klass_name:
626628
instance = self.__deserialize(data, klass_name)

0 commit comments

Comments
 (0)