[ALL-GENS] Utility - add open and close brace placeholders to additionalProperties for all mustache templates in all code gens#23259
Conversation
… mustache templates in all code gens
There was a problem hiding this comment.
2 issues found across 4 files
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java">
<violation number="1" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java:396">
P2: `openbrace`/`closebrace` are only set in `DefaultCodegen.processOpts()`, but some generator `processOpts()` overrides skip `super.processOpts()`, so placeholders are not available to all generators.</violation>
<violation number="2" location="modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java:396">
P2: `processOpts()` now unconditionally overwrites `additionalProperties["openbrace"]`/`["closebrace"]`, which can clobber user or generator-supplied additional-properties with the same keys.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java
Outdated
Show resolved
Hide resolved
Chrimle
left a comment
There was a problem hiding this comment.
Cool! Seems way overdue 😂
Unfortunately, it means that custom mustache templates cannot be backwards-compatible if using this property. 😭
Can you expand on that thought? I am not sure I understand correctly. Or if I understand, you mean that if someone already has the |
|
Maybe it would make sense to simply force-replace it. And let the people who now have this redefined move to another name (they should practically control both their templates and additionalProperties map entries...). I don't know which is better... |
|
No, that shouldn't be an issue. 👍 Was thinking from the perspective of overridden/custom mustache templates (cough cough), very niche use-case. A template using these properties will need to use openapi-generator v7.21.0 in order to work at all. Meanwhile, having them as But again, this (via properties) is the best implementation from the perspective of maintainability and ease of use. 👍 (but cannot be adopted by custom mustache templates in a backwards-compatible way) |
|
Ok - I see. Yeah, that sucks a bit. So you imagine having them basically as But I never explored how partials reuse is handled in the generator to be honest. If it is easy, I am all for it. |
|
basically to have just: ? Not sure if that works. I guess I will have to try it now (-: |
|
Nah, on second thought it's not worth it. If anything, that's something that custom mustache templates could introduce (to use partials instead of properties from the generator). I don't think it's worth the tech debt / maintainability loss in openapi-generator. 👍 |
Make
{{openbrace}}and{{closebrace}}available in all the mustache templates to solve issues when one needs to use{or}.E.g.
<version>{abc.version}</version>can now be easily encoded as:
<version>{{openbrace}}{{service}}.version{{closebrace}}</version>.Fixes #23109
PR checklist
Commit all changed files.
This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
These must match the expectations made by your contribution.
You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example
./bin/generate-samples.sh bin/configs/java*.IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
master(upcoming7.x.0minor release - breaking changes with fallbacks),8.0.x(breaking changes without fallbacks)"fixes #123"present in the PR description)Summary by cubic
Makes
{{openbrace}}and{{closebrace}}available in all Mustache templates by addingopenbraceandclosebracetoadditionalPropertiesinDefaultCodegen’s constructor (usingputIfAbsentto preserve overrides). Removes per-generator definitions fromSpringCodegen,KotlinSpringServerCodegen, andJavaMicronautAbstractCodegen.Written for commit c60de82. Summary will update on new commits.