Skip to content

Commit

Permalink
Fixes double serialization bug in python-experimental (#12561)
Browse files Browse the repository at this point in the history
* Partial template update, simplifies ref6570 serialization

* Updated serialization

* Typo fixes

* Fixes test_query_style_form_serialization

* Fixes test_cookie_style_form_serialization

* FIxes test_style_simple_in_path_serialization

* Fixes test_style_simple_in_header_serialization

* Fixes many parameter tests

* Deletes duplicate method

* Fixes TestParameter.test_path_params_no_style

* Fixes test_style_pipe_delimited_serialization

* Fixes test_header_params_no_style

* Fixes test_style_space_delimited_serialization

* Fixes test_query_style_form_serialization

* Fixes test_cookie_style_form_serialization

* Fixes test_query_params_no_style

* Fixes test_cookie_params_no_style

* Fixes test_delete_endpoint_without_request_body

* Fixes all tests

* Reverts version file

* Adds test_get_user_by_name to test path param url encoding

* Adds test_body_with_query_params

* Samples regenerated
  • Loading branch information
spacether authored Jun 13, 2022
1 parent 3190084 commit a00ae46
Show file tree
Hide file tree
Showing 66 changed files with 1,366 additions and 1,069 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ class {{operationIdCamelCase}}(api_client.Api):
{{#if cookieParams}}
self._verify_typed_dict_inputs(RequestCookieParams, cookie_params)
{{/if}}
used_path = _path
{{#if pathParams}}

_path_params = {}
Expand All @@ -449,10 +450,13 @@ class {{operationIdCamelCase}}(api_client.Api):
continue
serialized_data = parameter.serialize(parameter_data)
_path_params.update(serialized_data)

for k, v in _path_params.items():
used_path = used_path.replace('{%s}' % k, v)
{{/if}}
{{#if queryParams}}

_query_params = []
prefix_separator_iterator = None
for parameter in (
{{#each queryParams}}
request_query_{{paramName}},
Expand All @@ -461,8 +465,11 @@ class {{operationIdCamelCase}}(api_client.Api):
parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset:
continue
serialized_data = parameter.serialize(parameter_data)
_query_params.extend(serialized_data)
if prefix_separator_iterator is None:
prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value
{{/if}}
{{#or headerParams bodyParam produces}}

Expand Down Expand Up @@ -509,14 +516,8 @@ class {{operationIdCamelCase}}(api_client.Api):
{{/if}}

response = self.api_client.call_api(
resource_path=_path,
resource_path=used_path,
method=_method,
{{#if pathParams}}
path_params=_path_params,
{{/if}}
{{#if queryParams}}
query_params=tuple(_query_params),
{{/if}}
{{#or headerParams bodyParam produces}}
headers=_headers,
{{/or}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ class RESTClientObject(object):
self,
method: str,
url: str,
query_params: typing.Optional[typing.Tuple[typing.Tuple[str, str], ...]] = None,
headers: typing.Optional[HTTPHeaderDict] = None,
fields: typing.Optional[typing.Tuple[typing.Tuple[str, typing.Any], ...]] = None,
body: typing.Optional[typing.Union[str, bytes]] = None,
Expand All @@ -94,7 +93,6 @@ class RESTClientObject(object):

:param method: http request method
:param url: http request url
:param query_params: query parameters in the url
:param headers: http request headers
:param body: request body, for other types
:param fields: request parameters for
Expand Down Expand Up @@ -130,13 +128,10 @@ class RESTClientObject(object):
try:
# For `POST`, `PUT`, `PATCH`, `OPTIONS`, `DELETE`
if method in ['POST', 'PUT', 'PATCH', 'OPTIONS', 'DELETE']:
if query_params:
url += '?' + urlencode(query_params)
if 'Content-Type' not in headers and body is None:
r = self.pool_manager.request(
method,
url,
fields=query_params,
preload_content=not stream,
timeout=timeout,
headers=headers
Expand Down Expand Up @@ -181,7 +176,6 @@ class RESTClientObject(object):
# For `GET`, `HEAD`
else:
r = self.pool_manager.request(method, url,
fields=query_params,
preload_content=not stream,
timeout=timeout,
headers=headers)
Expand All @@ -195,63 +189,58 @@ class RESTClientObject(object):

return r

def GET(self, url, headers=None, query_params=None, stream=False,
def GET(self, url, headers=None, stream=False,
timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("GET", url,
headers=headers,
stream=stream,
timeout=timeout,
query_params=query_params, fields=fields)
fields=fields)

def HEAD(self, url, headers=None, query_params=None, stream=False,
def HEAD(self, url, headers=None, stream=False,
timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("HEAD", url,
headers=headers,
stream=stream,
timeout=timeout,
query_params=query_params, fields=fields)
fields=fields)

def OPTIONS(self, url, headers=None, query_params=None,
def OPTIONS(self, url, headers=None,
body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("OPTIONS", url,
headers=headers,
query_params=query_params,
stream=stream,
timeout=timeout,
body=body, fields=fields)

def DELETE(self, url, headers=None, query_params=None, body=None,
def DELETE(self, url, headers=None, body=None,
stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("DELETE", url,
headers=headers,
query_params=query_params,
stream=stream,
timeout=timeout,
body=body, fields=fields)

def POST(self, url, headers=None, query_params=None,
def POST(self, url, headers=None,
body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("POST", url,
headers=headers,
query_params=query_params,
stream=stream,
timeout=timeout,
body=body, fields=fields)

def PUT(self, url, headers=None, query_params=None,
def PUT(self, url, headers=None,
body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("PUT", url,
headers=headers,
query_params=query_params,
stream=stream,
timeout=timeout,
body=body, fields=fields)

def PATCH(self, url, headers=None, query_params=None,
def PATCH(self, url, headers=None,
body=None, stream=False, timeout=None, fields=None) -> urllib3.HTTPResponse:
return self.request("PATCH", url,
headers=headers,
query_params=query_params,
stream=stream,
timeout=timeout,
body=body, fields=fields)
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def call_123_test_special_tags(
api_response.body and api_response.headers will not be deserialized into schema
class instances
"""
used_path = _path

_headers = HTTPHeaderDict()
# TODO add cookie handling
Expand All @@ -145,7 +146,7 @@ class instances
elif 'body' in serialized_data:
_body = serialized_data['body']
response = self.api_client.call_api(
resource_path=_path,
resource_path=used_path,
method=_method,
headers=_headers,
fields=_fields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ def foo_get(
api_response.body and api_response.headers will not be deserialized into schema
class instances
"""
used_path = _path

_headers = HTTPHeaderDict()
# TODO add cookie handling
Expand All @@ -145,7 +146,7 @@ class instances
_headers.add('Accept', accept_content_type)

response = self.api_client.call_api(
resource_path=_path,
resource_path=used_path,
method=_method,
headers=_headers,
stream=stream,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def additional_properties_with_array_of_enums(
api_response.body and api_response.headers will not be deserialized into schema
class instances
"""
used_path = _path

_headers = HTTPHeaderDict()
# TODO add cookie handling
Expand All @@ -142,7 +143,7 @@ class instances
elif 'body' in serialized_data:
_body = serialized_data['body']
response = self.api_client.call_api(
resource_path=_path,
resource_path=used_path,
method=_method,
headers=_headers,
fields=_fields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def array_model(
api_response.body and api_response.headers will not be deserialized into schema
class instances
"""
used_path = _path

_headers = HTTPHeaderDict()
# TODO add cookie handling
Expand All @@ -141,7 +142,7 @@ class instances
elif 'body' in serialized_data:
_body = serialized_data['body']
response = self.api_client.call_api(
resource_path=_path,
resource_path=used_path,
method=_method,
headers=_headers,
fields=_fields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ def array_of_enums(
api_response.body and api_response.headers will not be deserialized into schema
class instances
"""
used_path = _path

_headers = HTTPHeaderDict()
# TODO add cookie handling
Expand All @@ -142,7 +143,7 @@ class instances
elif 'body' in serialized_data:
_body = serialized_data['body']
response = self.api_client.call_api(
resource_path=_path,
resource_path=used_path,
method=_method,
headers=_headers,
fields=_fields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ def body_with_file_schema(
api_response.body and api_response.headers will not be deserialized into schema
class instances
"""
used_path = _path

_headers = HTTPHeaderDict()
# TODO add cookie handling
Expand All @@ -130,7 +131,7 @@ class instances
elif 'body' in serialized_data:
_body = serialized_data['body']
response = self.api_client.call_api(
resource_path=_path,
resource_path=used_path,
method=_method,
headers=_headers,
fields=_fields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,16 +143,20 @@ def body_with_query_params(
class instances
"""
self._verify_typed_dict_inputs(RequestQueryParams, query_params)
used_path = _path

_query_params = []
prefix_separator_iterator = None
for parameter in (
request_query_query,
):
parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset:
continue
serialized_data = parameter.serialize(parameter_data)
_query_params.extend(serialized_data)
if prefix_separator_iterator is None:
prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value

_headers = HTTPHeaderDict()
# TODO add cookie handling
Expand All @@ -169,9 +173,8 @@ class instances
elif 'body' in serialized_data:
_body = serialized_data['body']
response = self.api_client.call_api(
resource_path=_path,
resource_path=used_path,
method=_method,
query_params=tuple(_query_params),
headers=_headers,
fields=_fields,
body=_body,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def boolean(
api_response.body and api_response.headers will not be deserialized into schema
class instances
"""
used_path = _path

_headers = HTTPHeaderDict()
# TODO add cookie handling
Expand All @@ -139,7 +140,7 @@ class instances
elif 'body' in serialized_data:
_body = serialized_data['body']
response = self.api_client.call_api(
resource_path=_path,
resource_path=used_path,
method=_method,
headers=_headers,
fields=_fields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,9 @@ def case_sensitive_params(
class instances
"""
self._verify_typed_dict_inputs(RequestQueryParams, query_params)
used_path = _path

_query_params = []
prefix_separator_iterator = None
for parameter in (
request_query_some_var,
request_query_some_var2,
Expand All @@ -155,14 +156,16 @@ class instances
parameter_data = query_params.get(parameter.name, unset)
if parameter_data is unset:
continue
serialized_data = parameter.serialize(parameter_data)
_query_params.extend(serialized_data)
if prefix_separator_iterator is None:
prefix_separator_iterator = parameter.get_prefix_separator_iterator()
serialized_data = parameter.serialize(parameter_data, prefix_separator_iterator)
for serialized_value in serialized_data.values():
used_path += serialized_value
# TODO add cookie handling

response = self.api_client.call_api(
resource_path=_path,
resource_path=used_path,
method=_method,
query_params=tuple(_query_params),
stream=stream,
timeout=timeout,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ def client_model(
api_response.body and api_response.headers will not be deserialized into schema
class instances
"""
used_path = _path

_headers = HTTPHeaderDict()
# TODO add cookie handling
Expand All @@ -145,7 +146,7 @@ class instances
elif 'body' in serialized_data:
_body = serialized_data['body']
response = self.api_client.call_api(
resource_path=_path,
resource_path=used_path,
method=_method,
headers=_headers,
fields=_fields,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def composed_one_of_different_types(
api_response.body and api_response.headers will not be deserialized into schema
class instances
"""
used_path = _path

_headers = HTTPHeaderDict()
# TODO add cookie handling
Expand All @@ -141,7 +142,7 @@ class instances
elif 'body' in serialized_data:
_body = serialized_data['body']
response = self.api_client.call_api(
resource_path=_path,
resource_path=used_path,
method=_method,
headers=_headers,
fields=_fields,
Expand Down
Loading

0 comments on commit a00ae46

Please sign in to comment.