You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When sending JSON request with body=None, payload is set to empty string, which is not a valid JSON and violates the definition of Content-Type header. Practically, it prevents requests parsing. The semantically correct payload would be '{}'.
request_body = None
if body is not None:
request_body = json.dumps(body)
r = self.pool_manager.request(
method, url,
body=request_body,
preload_content=_preload_content,
timeout=timeout,
headers=headers)
Describe a resource with POST, PUT, PATCH, OPTIONS or DELETE method,
Content-Type: application/json and empty body.
Make a request, try to parse its body with JSON parsing library such as python's built-in json.
json.loads(body) raises the error since body is empty string.
Related issues/PRs
3020 - issue and corresponding PR which introduced such a behaviour.
Suggest a fix/enhancement
Replace
request_body = None
if body is not None:
request_body = json.dumps(body)
With
request_body = '{}'
if body is not None:
request_body = json.dumps(body)
The text was updated successfully, but these errors were encountered:
Description
When sending JSON request with body=None, payload is set to empty string, which is not a valid JSON and violates the definition of Content-Type header. Practically, it prevents requests parsing. The semantically correct payload would be '{}'.
This behaviour is implemented in rest.mustache:
Swagger-codegen version
2.4.6
Swagger declaration file content or url
Command line used for generation
docker run --rm -v ${PWD}:/local swaggerapi/swagger-codegen-cli generate -l python -i /local/spec.yaml -o /local/swagger_out
Steps to reproduce
Describe a resource with
POST
,PUT
,PATCH
,OPTIONS
orDELETE
method,Content-Type: application/json and empty body.
Make a request, try to parse its body with JSON parsing library such as python's built-in json.
json.loads(body) raises the error since body is empty string.
Related issues/PRs
3020 - issue and corresponding PR which introduced such a behaviour.
Suggest a fix/enhancement
Replace
With
The text was updated successfully, but these errors were encountered: