OpenAPITools / OpenAPITools/openapi-generator

[Rust] Use `unimplemented!` or `compile_error!` instead of TODO

Aperta
#16,167 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Lingua principale
Java
Stelle
26.8k
Fork
7.7k
Metriche di merge delle PR
Metriche PR in attesa

Descrizione

Description

The Rust generator currently does not support all OpenAPI features. In case of an unsupported feature, instead of an implementation, a TODO comment is generated. One example would be file upload for clients if you enable supportAsync (which is enabled by default).

https://github.com/OpenAPITools/openapi-generator/blob/7f8b853f502d9039c9a0aac2614ce92871e895ed/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache#L269


There is nothing wrong with that. Supporting all features takes time. However, I would suggest to replace or complement this TODO comment with either an unimplemented! or compile_error! macro call.

Rationale:
This would improve the user (i.e. developer) experience. Because either the code would not compile (compile_error!), telling the developer exactly where something needs to be done. Or the code would fail in a more obvious way during runtime (unimplemented!), instead of just silently doing nothing.

Currently, you can generate a client, the code compiles, you can run it, and everything seems fine. You only realize something is not working correctly if the server returns an error, because the client ended up sending an invalid request. Or worse, the server doesn't give you an error because the file upload or whatever you were missing was optional, and you realize your mistake much later (maybe too late).


unimplemented! is already beeing used in some places of the template:

https://github.com/OpenAPITools/openapi-generator/blob/7f8b853f502d9039c9a0aac2614ce92871e895ed/modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache#L301

Some people already talked about compile_error! vs unimplemented!: https://github.com/OpenAPITools/openapi-generator/pull/1890#pullrequestreview-194210962

There was also an idea about using the function return type ! instead, but I think this would be much harder to implement, given how the templates work. https://github.com/OpenAPITools/openapi-generator/pull/1678#issuecomment-449430283

I think unimplemented! would be the way to go for now.

openapi-generator version

6.6.0
7.0.0-SNAPSHOT

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 da modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache, in particolare dalle posizioni collegate intorno alle righe 269 e 301. Esamina come le funzionalità non supportate producono attualmente commenti TODO e come viene già usato unimplemented!. Il lavoro è completato quando i percorsi non supportati falliscono esplicitamente con unimplemented! o compile_error!, invece di generare silenziosamente un comportamento incompleto.

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

Valutazione

Stack tecnologico
rust
Ambito
tooling
Tipo di issue
Funzionalità
Difficoltà
2/5
Tempo stimato
1-3 ore
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
45/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.