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

Reconsider closed enums for string values decoded from API responses

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

I maintainer di solito rispondono entro 3 giorni

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Da chiarire
Stato di attività
Attiva
Stack tecnologico
openapi, swift

Direzione di ricerca

Start by reading the response-side enum examples and the four options in the issue, especially the 16 generated StatusPayload enums and Batch.StatusPayload. Compare how the Swift generator handles the proposed anyOf pattern with the Java and Python examples cited. The issue is done when a direction is chosen for existing and future response enums, including whether it applies generally or only to selected fields.

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

Descrizione

swift-openapi-generator turns every string enum in the spec into a closed @frozen Swift enum. Many of these types are public, through Components.Schemas or typealiases such as ResponseObject.Status. That has different consequences for values we send and values we decode.

Values we send (request side)

When OpenAI adds a value, a closed enum costs two things:

  • The API-breakage check flags the new case, and we allowlist it with a changelog entry (as in c5d14f7). CONTRIBUTING already lists new enum cases as an accepted additive change.
  • Users can't send the new value until we regenerate and release.

Neither is a real problem.

Values we decode (response side)

If the API returns a value the enum doesn't know, decoding throws and the whole call fails. That would hit already-shipped apps, which no SDK release can fix. Examples:

  • ResponseObject.Status (Components.Schemas.Response.Value3Payload.StatusPayload)
  • Components.Schemas.Batch.StatusPayload, exposed directly by the Batch API (MacPaw/OpenAI#401)
  • 16 generated StatusPayload enums in total, plus other response-side enums

Java models every string enum as an open type: known constants plus an _UNKNOWN member, including Batch.Status. Python uses Literal types, which don't fail on unknown values at runtime.

Options

  1. Keep closed enums. This is what happens today. The risk is low per field, but a failure takes down every call that returns the field.
  2. Hand-written open types in Edited/ or Facade/. For example, a RawRepresentable struct with static constants for the fields that matter most, like statuses.
  3. Decode unknown values tolerantly. For example, a ParsingOptions flag or a custom init(from:) that maps unknown raw values to a fallback. This needs an unknown-style case, which generated enums don't have.
  4. Use the generator's open-enum pattern. Rewrite selected schemas in prepare_openapi.py as anyOf: [<enum>, {type: string}], which swift-openapi-generator turns into a struct with a known-value field and a raw-string fallback.

To decide

  • Whether response-side enums should be open in general, or only for selected fields such as statuses.
  • Which option to use, and whether it applies to existing types (a public API change) or only to new ones.
Lingua principale
Swift
Stelle
2.9k
Fork
519
Merge medio
4g 9h
PR unite (30g)
13

Preparare l'ambiente

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 MacPaw/OpenAI

Tutte le issue di MacPaw/OpenAI

Issue simili

Altre issue su Swift

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.