Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

[BUG] ExampleGenerator.generateFromResponseSchema treats the keys of an inline object `example` (java.util.Map) as media types

Aperta Adatta ai principianti
#25,236 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
java

Direzione di ricerca

Inizia da ExampleGenerator.generateFromResponseSchema(Schema, Set) e segui come un esempio di schema inline non null raggiunge gli overload di generate. Controlla i test esistenti per gli esempi degli schemi di risposta e aggiungi una copertura per un esempio di Map Java con application/json come tipo di media prodotto. Il lavoro è completato quando la mappa viene emessa come un unico esempio sotto quel tipo di media, invece di trattarne le chiavi come tipi di media.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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

When generateFromResponseSchema(statusCode, schema, produces) gets an inline (non-$ref, non-array) schema whose example is a java.util.Map, the "primitive type" branch casts the example to Map<String, Object> and passes it as the examples argument of generate(Map, List, Schema). That argument means {mediaType -> example}, so every key of the example becomes a contentType and every value becomes a separate example:

Schema<Object> response = new ObjectSchema()
        .addProperty("id", new IntegerSchema())
        .addProperty("name", new StringSchema());
response.setExample(Map.of("id", 1, "name", "Rex"));

new ExampleGenerator(Map.of(), new OpenAPI())
        .generateFromResponseSchema("200", response, Set.of("application/json"));
// actual:   [{contentType=name, example="Rex", statusCode=200}, {contentType=id, example=1, statusCode=200}]
// expected: [{contentType=application/json, example={"id":1,"name":"Rex"}, statusCode=200}]

When the spec is read from a file, swagger-parser gives the example as a Jackson ObjectNode, not a Map, so the CLI does not hit this path. It affects programmatic use, such as custom generators or tools that build or transform the OpenAPI model with plain Java maps.

openapi-generator version

7.25.0 (also current master).

Suggest a fix

In generateFromResponseSchema(Schema, Set), handle any non-null example (including Map) through generate(Object, List), and use the generate(Map, ...) overloads only for the media-type map.

Lingua principale
Java
Stelle
26.8k
Fork
7.7k
Merge medio
1g 11h
PR unite (30g)
139

Preparare l'ambiente

Apri in Codespaces

Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di OpenAPITools/openapi-generator

Tutte le issue di OpenAPITools/openapi-generator

Issue simili

Altre issue su Java

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.