Skip to content

Commit b7ea139

Browse files
authored
[Python] Fix object serialization for multipart requests (#18140)
* Fix multipart object serialization * Update samples
1 parent e58f19c commit b7ea139

4 files changed

Lines changed: 8 additions & 0 deletions

File tree

  • modules/openapi-generator/src/main/resources/python
  • samples
    • client/echo_api
      • python-disallowAdditionalPropertiesIfNotPresent/openapi_client
      • python/openapi_client
    • openapi3/client/petstore/python/petstore_api

modules/openapi-generator/src/main/resources/python/rest.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,8 @@ class RESTClientObject:
192192
# Content-Type which generated by urllib3 will be
193193
# overwritten.
194194
del headers['Content-Type']
195+
# Ensures that dict objects are serialized
196+
post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a,b) for a, b in post_params]
195197
r = self.pool_manager.request(
196198
method,
197199
url,

samples/client/echo_api/python-disallowAdditionalPropertiesIfNotPresent/openapi_client/rest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ def request(
203203
# Content-Type which generated by urllib3 will be
204204
# overwritten.
205205
del headers['Content-Type']
206+
# Ensures that dict objects are serialized
207+
post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a,b) for a, b in post_params]
206208
r = self.pool_manager.request(
207209
method,
208210
url,

samples/client/echo_api/python/openapi_client/rest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,8 @@ def request(
203203
# Content-Type which generated by urllib3 will be
204204
# overwritten.
205205
del headers['Content-Type']
206+
# Ensures that dict objects are serialized
207+
post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a,b) for a, b in post_params]
206208
r = self.pool_manager.request(
207209
method,
208210
url,

samples/openapi3/client/petstore/python/petstore_api/rest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,8 @@ def request(
202202
# Content-Type which generated by urllib3 will be
203203
# overwritten.
204204
del headers['Content-Type']
205+
# Ensures that dict objects are serialized
206+
post_params = [(a, json.dumps(b)) if isinstance(b, dict) else (a,b) for a, b in post_params]
205207
r = self.pool_manager.request(
206208
method,
207209
url,

0 commit comments

Comments
 (0)