OpenAPITools / OpenAPITools/openapi-generator

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

Offen
#16,167 0 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Vorherrschende Sprache
Java
Sterne
26.8k
Forks
7.7k
PR-Merge-Kennzahlen
PR-Kennzahlen ausstehend

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Beginne mit modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache, insbesondere mit den verknüpften Stellen um die Zeilen 269 und 301. Untersuche, wie nicht unterstützte Funktionen derzeit TODO-Kommentare erzeugen und wie unimplemented! bereits verwendet wird. Erledigt ist die Aufgabe, wenn nicht unterstützte Pfade explizit mit unimplemented! oder compile_error! fehlschlagen, anstatt stillschweigend unvollständiges Verhalten zu erzeugen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
rust
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.