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

$ref to array item leads to incorrect TypeScript type

Aperta
#308 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Ferma
Stack tecnologico
typescript
Ambito
api, devtools

Direzione di ricerca

Start by reproducing the generated TypeScript from the bundled OpenAPI schema, focusing on the $ref from Dog.dogName to DogNames/items. The change is complete when the property is typed as DogNames[number] rather than DogNames, while the DogNames array type remains unchanged.

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

Descrizione

I noticed a bug with the OpenAPI code generation output where a property that references an array item schema is being typed as an array in the generated TypeScript.

After bundling with swagger-parser bundler (because the original schema used an relative YAML file reference), the final JSON OpenAPI schema looks like this:

"components": {
  "schemas": {
    "DogNames": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string"
          }
        }
      }
    },
    "Dog": {
      "type": "object",
      "properties": {
        "dogName": {
          "$ref": "#/components/schemas/DogNames/items"
        }
      }
    }
  }
}

In the Dog schema, the property dogName references #/components/schemas/DogNames/items, which means it should be typed as a single object that matches the item structure from the DogNames array.

export type DogNames = {
  name?: string;
}[];

export type Dog = {
  dogName?: DogNames; // <-- This is incorrect
};

Expected output:

export type DogNames = {
  name?: string;
}[];

export type Dog = {
  dogName?: DogNames[number];
}
Lingua principale
TypeScript
Stelle
634
Fork
83
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

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 fabien0102/openapi-codegen

Tutte le issue di fabien0102/openapi-codegen

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.