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

"required": true for a property. Does the codgen support it?

Aperta
#322 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
35/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
typescript
Ambito
devtools

Direzione di ricerca

Start by tracing how the generator reads Schema Object properties and determines whether each TypeScript property is optional; no source file or test is named in the issue. Compare handling of the object-level required array with property-level required values, then add or update coverage so the supported behavior is explicit in the generated output.

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

Descrizione

I have a Schema Object

{
  "Obj": {
    "description": "Obj",
    "required": [
      "id",
      "foo"
    ],
    "properties": {
      "id": {
        "type": "string",
        "pattern": "^[0-9a-f]{32}$"
      },
      "foo": {
        "type": "string",
        "pattern": "^[0-9a-f]{32}$"
      },
      "bar": {
        "type": "string",
        "pattern": "^[0-9a-f]{32}$"
      }
    }
  }
}

With this ShemaObject, a type generates perfectly fine.

/**
 * Obj
 */
export type Obj = {
  /**
   * @pattern ^[0-9a-f]{32}$
   */
  id: string;
  /**
   * @pattern ^[0-9a-f]{32}$
   */
  foo: string;
  /**
   * @pattern ^[0-9a-f]{32}$
   */
  bar?: string;
};

But if I move/distribute required to properties like this

{
  "Obj": {
    "description": "Obj",
    "properties": {
      "id": {
        "type": "string",
        "pattern": "^[0-9a-f]{32}$",
        "required": true
      },
      "foo": {
        "type": "string",
        "pattern": "^[0-9a-f]{32}$",
        "required": true
      },
      "bar": {
        "type": "string",
        "pattern": "^[0-9a-f]{32}$"
      }
    }
  }
}

It generates this:

/**
 * Obj
 */
export type Obj = {
  /**
   * @pattern ^[0-9a-f]{32}$
   */
  id?: string;
  /**
   * @pattern ^[0-9a-f]{32}$
   */
  foo?: string;
  /**
   * @pattern ^[0-9a-f]{32}$
   */
  bar?: string;
};

Conclusion:
It ignores this approach of requiring fields if the required is set at the property level. Is it a bug? Is it possible to set up this approach?

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.