OpenAPITools / OpenAPITools/openapi-generator

[REQ] Rust generated code should follow Clippy suggestions

Open
#7,270 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: Rust Enhancement: Code format Enhancement: Feature
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

Is your feature request related to a problem? Please describe.

Now, when using cargo clippy to check the generated code, some bad smell may raise.

For example, when running cargo clippy --all-targets --all-features --allow-dirty --allow-staged --fix -Z unstable-options -- -D warnings, the following warning may raise:

About naming

warning: structure field `UID` should have a snake case name
  --> external\hydra-client\src\models\plugin_config_user.rs:20:9
   |
20 |     pub UID: Option<i32>,
   |         ^^^ help: convert the identifier to snake case: `uid`

About rules like new_without_default

warning: you should consider adding a `Default` implementation for `models::logout_request::LogoutRequest`
  --> external\hydra-client\src\models\logout_request.rs:28:5
   |
28 | /     pub fn new() -> LogoutRequest {
29 | |         LogoutRequest { request_url: None, rp_initiated: None, sid: None, subject: None }
30 | |     }
   | |_____^
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#new_without_default
help: try this
   |
27 | impl Default for models::logout_request::LogoutRequest {
28 |     fn default() -> Self {
29 |         Self::new()
30 |     }
31 | }
   |

Describe the solution you'd like

More strict lint test is needed when testing the generator

Describe alternatives you've considered

No alternative

Additional context

You can test by using the following schema: https://github.com/ory/hydra/blob/master/.schema/config.schema.json

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 by generating Rust code using the Hydra config schema, then run the provided cargo clippy command with warnings denied. Inspect the generated files such as external/hydra-client/src/models/plugin_config_user.rs and logout_request.rs, and add a stricter generator test whose generated Rust code passes the relevant Clippy checks.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
testing-qa, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.