loopbackio / loopbackio/loopback-next

OpenAPI generator use case: recurring vs. one-time

Aperta
#7,029 1 commento 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

CLI feature OpenAPI
Lingua principale
TypeScript
Stelle
5.1k
Fork
1.1k
Merge medio
2g 21h
PR unite (30g)
27

Descrizione

Suggestion

The current OpenAPI generator seems like it's meant to be used once, upfront, to scaffold code.

My suggestion is to (also/instead) support the use case where you run the generator regularly as part of your build, and don't even check in the generated files. (this is how I generally prefer to use code generators)

Was this considered in the design of the current generator? Is it possible to achieve something like this with LoopBack today?

Details

I'm starting a new project, and I expect to gradually evolve the schema over a couple years. Here's how I want it to work when a developer is updating application code to account for changes in the schema:

  • pull down the new schema
  • run the application build (this runs the code generator, replacing all the generated files)
  • application code that references the generated files now has TypeScript errors, showing you where your attention is needed. (follow the squiggles)

Other desirable properties of code generators:

  • Generated files have a recognizable, git -ignorable ending (e.g. .gen.ts)
  • There's a big scary header comment at the top saying "THIS IS A GENERATED FILE, DO NOT EDIT"
  • Ideally the generated code is formatted, at generation time, according to the project's prettier config. (for example, see graphql-code-generator)
  • You never need to make a change in a generated file. Instead you make changes in the generator's input. (e.g. the OpenAPI schema or in the generator configuration)
  • Because the generated file is unversioned and replaced wholesale, you're never asked to resolve a merge conflict between the new template and your project-specific changes.

Alternatives

  • Is Loopback's OpenAPI generator built on top of other libraries or tools that I might be able to use separately?
  • Do you know of other node.js web frameworks that might align with this philosophy? I don't need all the features loopback provides, I'm just hoping to make my OpenAPI schema the source of truth for endpoint declarations, input/output types, etc.

Guida per i contributori

Apri la guida per i contributori

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.

Direzione di ricerca

Inizia dalla documentazione collegata di OpenAPI generator ed esamina come LoopBack esegue attualmente il generatore. Confronta questo comportamento con il workflow richiesto per le build ricorrenti, inclusi i file generati non versionati, i marker dei file generati, la formattazione e il feedback di TypeScript. Il lavoro sarebbe completato quando fossero disponibili un design concordato e un modo supportato per usare il generatore dalle build dell’applicazione.

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

Valutazione

Stack tecnologico
node.js, openapi, typescript
Ambito
api, backend-api-design
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
20/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.