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

[BUG] ExampleGenerator returns the string "{}" (or null) for `type: object` schemas without `properties`

Aperta Adatta ai principianti
#25,237 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, openapi
Ambito
api

Direzione di ricerca

Individua resolvePropertyToExample e resolveModelToExample nel codice Java che implementa ExampleGenerator; l’issue non indica il loro file né un test. Inizia riproducendo il problema con lo schema OpenAPI fornito e verificando come vengono gestiti i valori $ref non risolti. Il lavoro è completato quando gli schemi oggetto senza proprietà producono un oggetto JSON vuoto sia negli esempi annidati sia in quelli di primo livello, anziché una stringa o null.

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

resolvePropertyToExample returns the Java string literal "{}" for an object schema without properties and for a $ref that cannot be resolved. Json.pretty then serializes it as a JSON string ("metadata" : "{}") instead of an empty object ("metadata" : { }), so the example has the wrong type (JSON Schema Validation wright-00, 5.21).

The same happens one level up. For a top-level model type: object without properties, resolveModelToExample falls through to return null, and generate(null, ["application/json"], "Anything") returns the example null. Through the CLI this model gets unaliased first, so the operation simply has no example; only programmatic callers see null.

openapi-generator version

7.25.0 (also current master).

OpenAPI declaration file content or url
components:
  schemas:
    Reading:
      type: object
      properties:
        metadata:
          type: object
Steps to reproduce

generate -g html → "Example data" shows "metadata" : "{}". Expected: "metadata" : { }.

Suggest a fix

Return new LinkedHashMap<>() (an empty map) instead of the string "{}" in both branches of resolvePropertyToExample, and also for object schemas without properties in resolveModelToExample.

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

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.