OpenAPITools / OpenAPITools/openapi-generator

[REQ][RUST] Allow structs generated by using the `useSingleRequestParameter` option to derive from `#[derive(Default)]`

Open
#24,314 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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.

First up, thank you very much for all the work done on the specification and making this incredibly complex topic even possible to begin with

As mentioned in #24312 in the Alternatives section structs generated with the useSingleRequestParameter option do not currently derive from #[derive(Default)].

Using defaults, especially on structs with a large number of parameters has become a defacto standard for achieving similar to named parameter functionally in rust as mentioned in issues, thread or similar regarding the topic.

Describe the solution you'd like

Improving this would allow for something likes this:

struct someParams {
  some1: Option<String>,
  some2: Option<String>,
  some3: Option<String>,
  some4: Option<String>,
  some5: Option<String>,
  some6: Option<String>,
  some7: Option<String>,
  some8: Option<String>,
}

let tmp = someFn(someParams {
  some1: None, 
  some2: None, 
  some3: None, 
  some4: None, 
  some5: None, 
  some6: None,  
  some7: None, 
  some8: None
})

to turn into this:

#[derive(Default)]
struct someParams {
  some1: Option<String>,
  some2: Option<String>,
  some3: Option<String>,
  some4: Option<String>,
  some5: Option<String>,
  some6: Option<String>,
  some7: Option<String>,
  some8: Option<String>,
}

let tmp = someFn(someParams {some1: "smth",  some5: "smth", ..Default::default()})

Describe alternatives you've considered

using the useBonBuilder option as mentioned in #24312 & #24313

Additional context

std::Default
default example1
default example2

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 tracing the Rust generator's useSingleRequestParameter option and the template or entry point that emits its structs. Compare the behavior with the useBonBuilder alternative referenced in #24312 and #24313. Done means generated structs include #[derive(Default)] and support the shown ..Default::default() usage, with generator tests covering it.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.