fix(ruby): JSON-encode query params with content:application/json#24126
Conversation
Parameters declared with `content: { "application/json": ... }` must be
serialized as JSON strings per the OpenAPI 3 spec. The core model field
`queryIsJsonMimeType` was already set correctly by DefaultCodegen; the Ruby
template was simply not using it, causing raw Ruby object representations to
be sent instead of JSON.
Adds `{{#queryIsJsonMimeType}}...to_json{{/queryIsJsonMimeType}}` branches to
api.mustache for both required and optional query params, updates the three
ruby echo_api samples accordingly, and adds a RubyClientCodegenTest to assert
the flag is set on content:application/json parameters.
Fixes: OpenAPITools#2519 (partially — same root cause, jaxrs-cxf generator)
Related: OpenAPITools#6367, OpenAPITools#21934 (same bug in TypeScript generators)
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
There was a problem hiding this comment.
1 issue found across 5 files
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
…y_api.rb Co-authored-by: cubic-dev-ai[bot] <191113872+cubic-dev-ai[bot]@users.noreply.github.com>
|
@nbudin thanks for the contribution. Have you tested the fix in your production environment to confirm the fix is working as expected? |
|
Hi @wing328! I haven't tested it in a production environment, but I have tested it locally on my machine by building a JAR with the changes, regenerating my Ruby client, and running my test script with the regenerated client, disabling the workarounds I'd been doing locally. I can confirm that with the regenerated client, my workarounds are no longer necessary and the query params are correctly encoded as JSON. If you'd like me to try running it in production as well, I can discuss with my team and get back to you. |
|
👌 let's give it a try thanks for your contribution. |
Fixes #24122.
Query parameters declared with
content: { "application/json": ... }must beserialized as JSON strings per the OpenAPI 3 spec. The Ruby client generator was ignoring this and emitting raw Ruby object representations instead.
The core model already handles this correctly:
DefaultCodegen.fromParameter()setsqueryIsJsonMimeType = trueon any parameter whosecontentmap has anapplication/jsonentry, and a test for this exists inDefaultCodegenTest#testQueryIsJsonMimeType. The Rubyapi.mustachetemplate was simply not using the flag.(I used Claude Code to generate this PR, but I've hand-reviewed the code as well. Happy to remove the Claude attribution from the commit if desired!)
Mentioning the Ruby technical committee members: @cliffano @zlx @autopp
Changes
api.mustache(ruby-client): branch on{{#queryIsJsonMimeType}}for both required and optional query params, calling.to_jsoninstead of passing the value (or callingbuild_collection_param) directlyRubyClientCodegenTest#testQueryParamJsonSerializationSetsQueryIsJsonMimeTypeto assert the flag propagates correctly through the Ruby codegen pathPR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
Summary by cubic
JSON-encode Ruby client query parameters defined with content: application/json so they are sent as JSON strings, not Ruby object literals. Aligns with OpenAPI 3 and fixes #24122.
ruby-client/api.mustache, usequeryIsJsonMimeTypefor required and optional query params and call.to_json; fallback keeps existing behavior.@api_client.object_to_hash(...).to_json.RubyClientCodegenTest#testQueryParamJsonSerializationSetsQueryIsJsonMimeTypeto assert flag propagation forcontent: application/jsonparams.Written for commit 69196ff. Summary will update on new commits.