OpenAPITools / OpenAPITools/openapi-generator
[BUG] [Java] additionalModelTypeAnnotations does not resolve variables
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
Bug Report Checklist
- Have you provided a full/minimal spec to reproduce the issue?
- Have you validated the input using an OpenAPI validator (example)?
- Have you tested with the latest master to confirm the issue still exists?
- Have you searched for related issues/PRs?
- What's the actual output vs expected output?
- [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
I am trying to add an annotation to my generated models that includes the version of the schema. This variable is available in a template as {{version}}. If I use a custom additionalModelTypeAnnotations.mustache containing the content: @com.example.SchemaVersion("{{version}}") then it is replaced with @com.example.SchemaVersion("1.2.3") as expected.
For simplicity's sake, I would like to do this without introducing a custom template file. I can add an annotation line using
--additonal-properties 'additionalModelTypeAnnotations=@com.example.SchemaVersion("{{version}}")'
Despite the template and the property above containing the exact same text, the annotation added through the property is rendered as @com.example.SchemaVersion("{{version}}") instead of resolving the {{version}} variable.
openapi-generator version
7.8.0 and 7.12.0
OpenAPI declaration file content or url
{
"openapi": "3.0.3",
"info": {
"title": "MyApi",
"version": "1.2.3"
},
"paths": {},
"components": {
"schemas": {
"MyModel": {
"title": "MyModel",
"type": "object",
"properties": {
"MyProperty": {
"title": "Property",
"type": "string"
}
}
}
}
}
}
Generation Details
java -jar openapi-generator-cli-7.8.0.jar \
generate -g java \
-i openapi.json -o out \
--global-property apis=false,invokers=false,models='' \
--additional-properties 'additionalModelTypeAnnotations=@com.example.SchemaVersion("{{version}}")'
Steps to reproduce
Run command above. The file generated at out/src/main/java/org/openapitools/client/model/MyModel.java contains the annotation line in question on line 51 (for generator version 7.8.0)
Related issues/PRs
Suggest a fix
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 by running the documented Java generator command with the supplied openapi.json and compare the output in out/src/main/java/org/openapitools/client/model/MyModel.java with output from the custom additionalModelTypeAnnotations.mustache template. Trace how additionalModelTypeAnnotations is rendered versus the template variable {{version}}. Done means the property-based annotation contains 1.2.3, matching the custom-template output.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100