[BUG][ruby-client] Body variable not properly serialized when named `body`
See original GitHub issueBug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What’s the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
When the body variable is named body
, this line of code makes it bypass the call to @api_client.object_to_http_body
, which prevents the transformation of the object into a hash, thus making to_json
return invalid JSON.
At Datadog, we make extensive use of the x-codegen-request-body-name
extension and set it to body
for consistency and ease of use across our different endpoints, which causes this issue.
openapi-generator version
5.0.0-beta
OpenAPI declaration file content or url
The following example will generate
paths:
/send_body:
post:
x-codegen-request-body-name: body
requestBody:
content:
"application/json":
schema:
$ref: "#/components/schemas/BodyParam"
responses:
"200":
description: OK
components:
schemas:
BodyParam:
type: object
properties:
prop:
type: string
Steps to reproduce
Generating the ruby client for the above endpoint will create this code:
# http body (model)
post_body = opts[:body] || @api_client.object_to_http_body(opts[:'body'])
Now when using the endpoint, you would do something like the following
body_param = BodyParam.new
body_param.prop = "foo"
api.send_body({body: body_param})
Because of the generated line of code above, the object will be passed as is to the call_api
method, and the JSON serialization will produce invalid JSON, as the object did not go through the object_to_http_body
method:
"{:prop=>\"foo\"}"
Suggest a fix
Looking for suggestions on how to fix this. I’d be happy to implement it.
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top GitHub Comments
I’ll talk to that PR author about the additional logic to pass various options (parameter values) to the method.
(other clients do not have similar logic as the method should work according to the contract/spec)
Thanks, this solves my use case as well, so I’d be okay to merge. I just hope no one has a body variable named
debug_body
😅. For the time being though I’m 👍