OpenAPITools / OpenAPITools/openapi-generator
[REQ][Rust] Add additionalProperties to the generated code
Open
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.
Some openAPI specs do not contain every property they actually return. Right now it is not possible to access those properties
Describe the solution you'd like
The solution would be to include all undefined properties in the generated code, by modifying the model.mustache file like this:
--- /proc/self/fd/14 2025-03-25 10:57:36.081920827 +0100
+++ templates/model.mustache 2025-03-25 09:53:47.536340813 +0100
@@ -148,6 +148,8 @@
### Option End (and trailing comma)
}}{{#isNullable}}>{{/isNullable}}{{^required}}>{{/required}},
{{/vars}}
+ #[serde(flatten)]
+ pub additional_properties: std::collections::HashMap<String, serde_json::Value>,
}
impl {{{classname}}} {
@@ -169,6 +171,7 @@
{{#vars}}
{{{name}}}{{^required}}: None{{/required}}{{#required}}{{#isModel}}{{^avoidBoxedModels}}: {{^isNullable}}Box::new({{{name}}}){{/isNullable}}{{#isNullable}}if let Some(x) = {{{name}}} {Some(Box::new(x))} else {None}{{/isNullable}}{{/avoidBoxedModels}}{{/isModel}}{{/required}},
{{/vars}}
+ additional_properties: std::collections::HashMap::new(),
}
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with templates/model.mustache and compare the Rust model fields and constructor shown in the issue. Generate a Rust model from a spec containing undeclared response properties, then verify the generated code exposes those properties and initializes the added field correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- api, tooling
- Issue type
- Feature
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100