OpenAPITools / OpenAPITools/openapi-generator

[REQ][Rust] Add additionalProperties to the generated code

Open
#20,965 6 comments 1 reaction 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.

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

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 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.