Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken partial indentation with nested sections #181

Open
jbortkiewicz opened this issue Jul 5, 2024 · 1 comment
Open

Broken partial indentation with nested sections #181

jbortkiewicz opened this issue Jul 5, 2024 · 1 comment

Comments

@jbortkiewicz
Copy link

Description:

When a partial contains multiple nested standalone sections,the indentation is rendered for each standalone section tag (opening and closing), causing an accumulated indentation preceding a next output.

Context:

I found this issue while trying to develop templates that produce "pretty" formatted code with openapi-generator. It is a very common use case (not only with openapi-generator), that partial contains several nested sections intended to implement complicated if-else conditions, thus this issue makes it impossible to generate a properly indented code.

To Reproduce

Affected versions: 1.16, master (00be427)
Failing test cases:

  - name: Partial Nested Section Indentation
    desc: Multiple nested standalone sections should not change indentation
    data: { content: "value" }
    template: |
      \
       {{>partial}}
      /
    partials:
      partial: |
        |
        {{#content}}
        {{#content}}
        {{{.}}}
        {{/content}}
        {{/content}}
        |
    expected: |
      \
       |
       value
       |
      /

  - name: Partial Indentation With Empty Nested Sections
    desc: Empty nested standalone sections should not change indentation
    data: { content: "value" }
    template: |
      \
       {{>partial}}
      /
    partials:
      partial: |
        |
        {{#content}}
        {{#missing}}
        {{.}}
        {{/missing}}
        {{/content}}
        |
    expected: |
      \
       |
       |
      /
@agentgt
Copy link
Contributor

agentgt commented Jul 5, 2024

I will probably rewrite the parsing of JMustache later this summer to match JStachio and will attempt to fix this bug next week.

In the meantime I recommend considering using JStachio zero dependency mode for OpenAPI. With the zero dep mode https://jstach.io/doc/jstachio/current/apidocs/#code_generation_mode which is designed for code generation in APT or OpenAPI projects. I tested and this bug does not happen with it.

@jskov I know was using it for that so they maybe able to help you.

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

No branches or pull requests

2 participants