Skip to content

fix(ruby): JSON-encode query params with content:application/json#24126

Merged
wing328 merged 3 commits into
OpenAPITools:masterfrom
nbudin:fix/ruby-client-query-param-json-serialization
Jun 25, 2026
Merged

fix(ruby): JSON-encode query params with content:application/json#24126
wing328 merged 3 commits into
OpenAPITools:masterfrom
nbudin:fix/ruby-client-query-param-json-serialization

Conversation

@nbudin

@nbudin nbudin commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

Fixes #24122.

Query parameters declared with content: { "application/json": ... } must be
serialized 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() sets queryIsJsonMimeType = true on any parameter whose content map has an application/json entry, and a test for this exists in DefaultCodegenTest#testQueryIsJsonMimeType. The Ruby api.mustache template 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_json instead of passing the value (or calling build_collection_param) directly
  • Updated three echo_api Ruby samples (faraday, httpx, typhoeus) to reflect the corrected output
  • Added RubyClientCodegenTest#testQueryParamJsonSerializationSetsQueryIsJsonMimeType to assert the flag propagates correctly through the Ruby codegen path

PR checklist

  • Read the contribution guidelines.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

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.

  • Bug Fixes
    • In ruby-client/api.mustache, use queryIsJsonMimeType for required and optional query params and call .to_json; fallback keeps existing behavior.
    • Regenerated echo_api samples for ruby-faraday, ruby-httpx, and ruby-typhoeus; in ruby-httpx, object refs use @api_client.object_to_hash(...).to_json.
    • Added RubyClientCodegenTest#testQueryParamJsonSerializationSetsQueryIsJsonMimeType to assert flag propagation for content: application/json params.

Written for commit 69196ff. Summary will update on new commits.

Review in cubic

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>

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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>
@wing328

wing328 commented Jun 25, 2026

Copy link
Copy Markdown
Member

@nbudin thanks for the contribution. Have you tested the fix in your production environment to confirm the fix is working as expected?

@nbudin

nbudin commented Jun 25, 2026

Copy link
Copy Markdown
Contributor Author

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.

@wing328 wing328 merged commit 36067a1 into OpenAPITools:master Jun 25, 2026
19 checks passed
@wing328

wing328 commented Jun 25, 2026

Copy link
Copy Markdown
Member

👌

let's give it a try

thanks for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ruby clients don't correctly handle JSON-encoded query parameters

2 participants