OpenAPITools / OpenAPITools/openapi-generator

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

Open
#16,167 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with modules/openapi-generator/src/main/resources/rust/reqwest/api.mustache, especially the linked locations around lines 269 and 301. Inspect how unsupported features currently produce TODO comments and how unimplemented! is already used. Done means unsupported paths fail explicitly with unimplemented! or compile_error! instead of silently generating incomplete behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
tooling
Issue type
Feature
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.