Skip to content

Commit 20e3283

Browse files
[PYTHON][bugfix] Fix missing post-params when content type is json (#23526)
* Fix missing post-params when content type is json * Generated samples for new rest.py templates * Update .gitignore Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com> --------- Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
1 parent 3bbc993 commit 20e3283

12 files changed

Lines changed: 25 additions & 0 deletions

File tree

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,3 +309,6 @@ samples/client/petstore/ocaml-recursion-test/_build/
309309

310310
# jetbrain http client
311311
samples/client/jetbrains/adyen/checkout71/http/client/Apis/http-client.private.env.json
312+
313+
# Generated by the run-in-docker.sh
314+
\?/

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class RESTClientObject:
128128
if re.search('json', headers['Content-Type'], re.IGNORECASE):
129129
if body is not None:
130130
body = json.dumps(body)
131+
if body is None and post_params:
132+
body = json.dumps(dict(post_params))
131133
args["data"] = body
132134
elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
133135
args["data"] = aiohttp.FormData(post_params)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,8 @@ class RESTClientObject:
172172
request_body = None
173173
if body is not None:
174174
request_body = json.dumps(body)
175+
if body is None and post_params:
176+
request_body = json.dumps(dict(post_params))
175177
r = self.pool_manager.request(
176178
method, url,
177179
body=request_body,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,8 @@ class RESTClientObject:
112112
if re.search('json', headers['Content-Type'], re.IGNORECASE):
113113
if body:
114114
body = json.dumps(body)
115+
if body is None and post_params:
116+
body = json.dumps(dict(post_params))
115117
request.body = body
116118
elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
117119
request.body = urlencode(post_params)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ class RESTClientObject:
156156
if re.search('json', headers['Content-Type'], re.IGNORECASE):
157157
if body is not None:
158158
body = json.dumps(body)
159+
if body is None and post_params:
160+
body = json.dumps(dict(post_params))
159161
args["data"] = body
160162
elif headers['Content-Type'] == 'application/x-www-form-urlencoded':
161163
args["data"] = aiohttp.FormData(post_params)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,8 @@ class RESTClientObject:
128128
if re.search('json', headers['Content-Type'], re.IGNORECASE):
129129
if body is not None:
130130
args["json"] = body
131+
if body is None and post_params:
132+
args["json"] = dict(post_params)
131133
elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
132134
args["data"] = dict(post_params)
133135
elif headers['Content-Type'] == 'multipart/form-data':

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ class RESTClientObject:
122122
if re.search('json', headers['Content-Type'], re.IGNORECASE):
123123
if body:
124124
body = json.dumps(body)
125+
if body is None and post_params:
126+
body = json.dumps(dict(post_params))
125127
request.body = body
126128
elif headers['Content-Type'] == 'application/x-www-form-urlencoded':
127129
request.body = urlencode(post_params)

samples/client/echo_api/python-pydantic-v1/openapi_client/rest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,8 @@ def request(self, method, url, query_params=None, headers=None,
182182
request_body = None
183183
if body is not None:
184184
request_body = json.dumps(body)
185+
if body is None and post_params:
186+
request_body = json.dumps(dict(post_params))
185187
r = self.pool_manager.request(
186188
method, url,
187189
body=request_body,

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,8 @@ async def request(
165165
if re.search('json', headers['Content-Type'], re.IGNORECASE):
166166
if body is not None:
167167
body = json.dumps(body)
168+
if body is None and post_params:
169+
body = json.dumps(dict(post_params))
168170
args["data"] = body
169171
elif headers['Content-Type'] == 'application/x-www-form-urlencoded':
170172
args["data"] = aiohttp.FormData(post_params)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,8 @@ async def request(
137137
if re.search('json', headers['Content-Type'], re.IGNORECASE):
138138
if body is not None:
139139
args["json"] = body
140+
if body is None and post_params:
141+
args["json"] = dict(post_params)
140142
elif headers['Content-Type'] == 'application/x-www-form-urlencoded': # noqa: E501
141143
args["data"] = dict(post_params)
142144
elif headers['Content-Type'] == 'multipart/form-data':

0 commit comments

Comments
 (0)