Repository navigation
Fix #25719: ruby-nextgen parses JSON response bodies twice #25759
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Inf1mum
wants to merge
1
commit into
OpenAPITools:master
Choose a base branch
from
Inf1mum:fix/25719-json-body
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
38 changes: 38 additions & 0 deletions
38
modules/openapi-generator/src/test/resources/3_0/ruby-nextgen/json-string-body.yaml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| openapi: 3.0.3 | ||
| info: | ||
| title: probes | ||
| version: 1.0.0 | ||
| paths: | ||
| /greeting: | ||
| get: | ||
| operationId: getGreeting | ||
| responses: | ||
| '200': | ||
| description: OK | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: string | ||
| /pets: | ||
| get: | ||
| operationId: listPets | ||
| responses: | ||
| '200': | ||
| description: OK | ||
| content: | ||
| application/json: | ||
| schema: | ||
| type: array | ||
| items: | ||
| $ref: '#/components/schemas/Pet' | ||
| components: | ||
| schemas: | ||
| Pet: | ||
| type: object | ||
| properties: | ||
| birthday: | ||
| type: string | ||
| format: date | ||
| code: | ||
| type: string | ||
| pattern: '^[a-z]+$' |
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
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
48 changes: 48 additions & 0 deletions
48
samples/client/petstore/ruby-nextgen/spec/connection_spec.rb
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| require 'spec_helper' | ||
|
|
||
| class StubReplyMiddleware < Faraday::Middleware | ||
| def initialize(app, body) | ||
| super(app) | ||
| @body = body | ||
| end | ||
|
|
||
| def call(env) | ||
| env.status = 200 | ||
| env.body = @body | ||
| env.response_headers = Faraday::Utils::Headers.new('Content-Type' => 'application/json') | ||
| env.response = Faraday::Response.new(env) | ||
| end | ||
| end | ||
|
|
||
| RSpec.describe Petstore::Connection do | ||
| def connection_replying_with(body) | ||
| Petstore::Client.new(base_url: 'http://localhost') { |c| c.use(StubReplyMiddleware, body) }.connection | ||
| end | ||
|
|
||
| it 'deserializes a JSON string body to a String instead of raising ApiError' do | ||
| response = connection_replying_with('"hello"').call(:GET, '/greeting') | ||
|
|
||
| expect(response.data).to eq('hello') | ||
| expect(response.status).to eq(200) | ||
| end | ||
|
|
||
| it 'builds a model from a JSON object body' do | ||
| response = connection_replying_with({ 'name' => 'Rex' }.to_json) | ||
| .call(:GET, '/pet/1', type: Petstore::Models::Pet) | ||
|
|
||
| expect(response.data).to be_a(Petstore::Models::Pet) | ||
| expect(response.data.name).to eq('Rex') | ||
| end | ||
|
|
||
| it 'raises ApiError on a body that is not valid JSON' do | ||
| expect do | ||
| connection_replying_with('not json').call(:GET, '/greeting') | ||
| end.to raise_error(Petstore::ApiError, /invalid JSON in response body/) | ||
| end | ||
|
|
||
| it 'returns nil data for an empty body' do | ||
| expect(connection_replying_with('').call(:GET, '/greeting').data).to be_nil | ||
| end | ||
| end |
Oops, something went wrong.
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.
There was a problem hiding this comment.
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#bodyfor JSON error responses: it was a parsed Hash and is now the raw String. The README already describese.bodyas 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