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

Ouverte Adaptée aux débutants
#25,719 1 commentaire 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@Inf1mum y travaille déjà.

Depuis le 19/11/2026.

  • #25759 par @Inf1mum — ouverte

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
77/100
Type d'issue
Bug
Clarté
Clairement spécifiée
Activité
Active
Stack technique
java, openapi, ruby

Piste de recherche

L’issue identifie Configuration#configure_faraday et Connection#deserialize comme le chemin d’analyse ; commencez par lire ces méthodes dans le générateur Ruby Nextgen et ses modèles de client générés. Ajoutez ou repérez un test de régression pour une réponse JSON sous forme de chaîne, comme "hello", puis exécutez les tests pertinents du client Ruby Nextgen. Le travail est terminé lorsque la réponse renvoie la chaîne sans lever ApiError.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Bug Report Checklist
  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?
  • What's the actual output vs expected output?
Description

Configuration#configure_faraday registers the :json response middleware, which decodes a JSON response body. Connection#deserialize then calls JSON.parse again on any body that is still a String. A response whose JSON value is a string ("hello") is decoded to hello by the middleware, the second parse fails, and a successful call raises ApiError.

openapi-generator version

master, 7.28.0-SNAPSHOT, 8a9fb722777e770e2c44b20b00bddbb51a0d525a

OpenAPI declaration file content or url
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]+$'
Generation Details
java -jar openapi-generator-cli.jar generate -g ruby-nextgen -i spec.yaml -o out \
  --additional-properties=gemName=petstore,moduleName=Petstore
Steps to reproduce
$LOAD_PATH.unshift 'out/lib'
require 'petstore'

# Replies to every request with a fixed JSON body.
class Reply < 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

client = Petstore::Client.new(base_url: 'http://localhost') { |c| c.use(Reply, '"hello"') }
begin
  p client.greeting.list.data
rescue Petstore::ApiError => e
  puts "#{e.class}: #{e.message}"
end

Actual (ruby 4.0.9, faraday 2.15.1):

Petstore::ApiError: invalid JSON in response body: unexpected character: 'hello' at line 1 column 1

Expected:

"hello"
Related issues/PRs

Raised by the automated review of #25717; the code is already on master and is not changed by that PR.

Langage dominant
Java
Étoiles
26.9k
Forks
7.8k
Merge moyen
2 j 23 min
PR mergées (30 j)
177

Préparer son environnement

Ouvrir dans Codespaces

Lance le conteneur de développement du projet dans votre navigateur, avec votre propre compte GitHub.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de OpenAPITools/openapi-generator

Toutes les issues de OpenAPITools/openapi-generator

Issues similaires

Plus d'issues Java

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.