Repository navigation
Conversation
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>
Contributor
There was a problem hiding this comment.
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$/ |
Contributor
There was a problem hiding this comment.
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #25719
Configuration#configure_faradayregistered Faraday's:jsonresponse middleware (decoding bodies once), andConnection#deserializethen re-ranJSON.parseon any body still aString. A JSON response whose value is a string ("hello") was decoded by the middleware to the bare string, and the second parse failed →ApiErroron a successful call (reproduced verbatim on upstream master).The response middleware is removed —
Connection#deserializeis the single parse point (request-side:jsonuntouched). Generator test + fixture assert the generatedconfiguration.rbhas noconn.response :jsonwhileconnection.rbkeepsJSON.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;
RubyNextgenClientCodegenTest25/25;RubyApiRoutingTest6/6.Summary by cubic
Fixes the ruby-nextgen client raising
ApiErroron successful JSON responses whose value is a string, such as"hello", because the response body was parsed twice.Bug Fixes
:jsonresponse middleware so JSON parsing happens only inConnection#deserialize.qdrant,petstore) with the updated configuration.Written for commit 8baa874. Summary will update on new commits.