Skip to content

[ALL-GENS] Utility - add open and close brace placeholders to additionalProperties for all mustache templates in all code gens#23259

Open
Picazsoo wants to merge 2 commits intoOpenAPITools:masterfrom
Picazsoo:feature/make-curly-braces-available-in-all-templates
Open

[ALL-GENS] Utility - add open and close brace placeholders to additionalProperties for all mustache templates in all code gens#23259
Picazsoo wants to merge 2 commits intoOpenAPITools:masterfrom
Picazsoo:feature/make-curly-braces-available-in-all-templates

Conversation

@Picazsoo
Copy link
Contributor

@Picazsoo Picazsoo commented Mar 15, 2026

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

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    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.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Makes {{openbrace}} and {{closebrace}} available in all Mustache templates by adding openbrace and closebrace to additionalProperties in DefaultCodegen’s constructor (using putIfAbsent to preserve overrides). Removes per-generator definitions from SpringCodegen, KotlinSpringServerCodegen, and JavaMicronautAbstractCodegen.

Written for commit c60de82. Summary will update on new commits.

@Picazsoo Picazsoo marked this pull request as ready for review March 16, 2026 07:58
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Contributor

@Chrimle Chrimle left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool! Seems way overdue 😂

Unfortunately, it means that custom mustache templates cannot be backwards-compatible if using this property. 😭

@Picazsoo
Copy link
Contributor Author

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 {{openbrace}} and {{closebrace}} redefined via additionalProperties for some other use, this will not work for them?

@Picazsoo
Copy link
Contributor Author

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

@Chrimle
Copy link
Contributor

Chrimle commented Mar 16, 2026

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 .mustache files, would allow it to be used in combination with ANY openapi-generator version. But to be honest, not sure if this should be considered at all. Having 2 files for 2 characters is overkill, and making it a default property is much better (but again, way too overdue) 😉

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)

@Picazsoo
Copy link
Contributor Author

Ok - I see. Yeah, that sucks a bit. So you imagine having them basically as partials? That is also a neat idea though...

But I never explored how partials reuse is handled in the generator to be honest.

If it is easy, I am all for it.

@Picazsoo
Copy link
Contributor Author

basically to have just:
{{>openbrace}} as:
{{=<% %>=}}{<%={{ }}=%>
and
{{>closebrace}} as:
{{=<% %>=}}}<%={{ }}=%>

?

Not sure if that works. I guess I will have to try it now (-:

@Chrimle
Copy link
Contributor

Chrimle commented Mar 16, 2026

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Mustache template fails to parse when a literal left brace { precedes a variable

2 participants