Skip to content

Commit

Permalink
feat: object, int serialization for multipart reqs
Browse files Browse the repository at this point in the history
Extends previous commits (and OpenAPITools#18140) to cover the python-pydantic-v1
client as well.
  • Loading branch information
roryschadler committed Aug 27, 2024
1 parent d924de2 commit bbfd186
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,11 @@ class RESTClientObject:
filename=v[0],
content_type=v[2])
else:
# Ensures that dict objects are serialized
if isinstance(v, dict):
v = json.dumps(v)
elif isinstance(v, int):
v = str(v)
data.add_field(k, v)
args["data"] = data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ class RESTClientObject:
# Content-Type which generated by urllib3 will be
# overwritten.
del headers['Content-Type']
# Ensures that dict objects are serialized
post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a,b) for a, b in post_params]
r = self.pool_manager.request(
method, url,
fields=post_params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ def request(self, method, url, query_params=None, headers=None,
# Content-Type which generated by urllib3 will be
# overwritten.
del headers['Content-Type']
# Ensures that dict objects are serialized
post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a,b) for a, b in post_params]
r = self.pool_manager.request(
method, url,
fields=post_params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ async def request(self, method, url, query_params=None, headers=None,
filename=v[0],
content_type=v[2])
else:
# Ensures that dict objects are serialized
if isinstance(v, dict):
v = json.dumps(v)
elif isinstance(v, int):
v = str(v)
data.add_field(k, v)
args["data"] = data

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,8 @@ def request(self, method, url, query_params=None, headers=None,
# Content-Type which generated by urllib3 will be
# overwritten.
del headers['Content-Type']
# Ensures that dict objects are serialized
post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a,b) for a, b in post_params]
r = self.pool_manager.request(
method, url,
fields=post_params,
Expand Down

0 comments on commit bbfd186

Please sign in to comment.