Skip to content

Fix #25719: ruby-nextgen parses JSON response bodies twice - #25759

Open
Inf1mum wants to merge 1 commit into
OpenAPITools:masterfrom
Inf1mum:fix/25719-json-body
Open

Inf1mum wants to merge 1 commit into
OpenAPITools:masterfrom
Inf1mum:fix/25719-json-body

Conversation

@Inf1mum

@Inf1mum Inf1mum commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #25719

Configuration#configure_faraday registered Faraday's :json response middleware (decoding bodies once), and Connection#deserialize then re-ran JSON.parse on any body still a String. A JSON response whose value is a string ("hello") was decoded by the middleware to the bare string, and the second parse failed → ApiError on a successful call (reproduced verbatim on upstream master).

The response middleware is removed — Connection#deserialize is the single parse point (request-side :json untouched). Generator test + fixture assert the generated configuration.rb has no conn.response :json while connection.rb keeps JSON.parse; both generated runtimes regenerated (one-line diff each). New runtime regression spec covers the issue's scenario: JSON string body → "hello", model building, invalid JSON → ApiError, empty body → nil.

Sample rspec 27/27; RubyNextgenClientCodegenTest 25/25; RubyApiRoutingTest 6/6.


Summary by cubic

Fixes the ruby-nextgen client raising ApiError on successful JSON responses whose value is a string, such as "hello", because the response body was parsed twice.

Bug Fixes

  • Removes Faraday's :json response middleware so JSON parsing happens only in Connection#deserialize.
  • Adds generator and runtime specs covering JSON string, model, invalid JSON, and empty response bodies.
  • Regenerates Ruby samples (qdrant, petstore) with the updated configuration.

Written for commit 8baa874. Summary will update on new commits.

View guided diff

Configuration#configure_faraday registered Faraday's :json response
middleware, which decodes JSON bodies, and Connection#deserialize then
JSON.parse'd any body still a String. A response whose JSON value is a
string ("hello") was decoded to hello by the middleware and the second
parse failed, raising ApiError on a successful call.

Drop the response middleware so Connection#deserialize remains the
single parse point: valid JSON parses once, invalid JSON and non-JSON
bodies still surface as ApiError.

Signed-off-by: Inf1mum <vadimlazuk5@gmail.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 6 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="samples/client/petstore/ruby-nextgen/lib/petstore/configuration.rb">

<violation number="1" location="samples/client/petstore/ruby-nextgen/lib/petstore/configuration.rb:34">
P2: Removing the response JSON middleware also changes `ApiError#body` for JSON error responses: it was a parsed Hash and is now the raw String. The README already describes `e.body` as the raw body, so this may be intended, but the PR does not call it out. Please note this as a behavior change, or add a spec covering the error body shape.</violation>
</file>

Reply with feedback, questions, or to request a fix.

View guided diff | Re-trigger cubic

conn.request :multipart
conn.request :url_encoded
conn.request :json
conn.response :json, content_type: /\bjson$/

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.

P2: Removing the response JSON middleware also changes ApiError#body for JSON error responses: it was a parsed Hash and is now the raw String. The README already describes e.body as the raw body, so this may be intended, but the PR does not call it out. Please note this as a behavior change, or add a spec covering the error body shape.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. When an issue isn't valid or won't be fixed in this PR, reply in its thread with the reason and then resolve the thread. At samples/client/petstore/ruby-nextgen/lib/petstore/configuration.rb, line 34:

<comment>Removing the response JSON middleware also changes `ApiError#body` for JSON error responses: it was a parsed Hash and is now the raw String. The README already describes `e.body` as the raw body, so this may be intended, but the PR does not call it out. Please note this as a behavior change, or add a spec covering the error body shape.</comment>

<file context>
@@ -31,7 +31,6 @@ def configure_faraday(conn)
       conn.request :url_encoded
       conn.request :json
-      conn.response :json, content_type: /\bjson$/
       conn.options.timeout = timeout
       conn.response :logger, logger if logger && debugging
       @middlewares.each { |mw, mw_args, mw_block| conn.use(mw, *mw_args, &mw_block) }
</file context>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG][RUBY-NEXTGEN] A JSON string response raises ApiError because the body is parsed twice

1 participant