Skip to content

♻️ Convert Enumeration generator to Stencil template#181

Open
MadsBogeskov wants to merge 1 commit intoios-430-convert-typealiasmodel-and-globalheadersmodel-to-stencil-v2from
ios-431-convert-enumeration-generator-to-stencil-template-v2
Open

♻️ Convert Enumeration generator to Stencil template#181
MadsBogeskov wants to merge 1 commit intoios-430-convert-typealiasmodel-and-globalheadersmodel-to-stencil-v2from
ios-431-convert-enumeration-generator-to-stencil-template-v2

Conversation

@MadsBogeskov
Copy link
Contributor

@MadsBogeskov MadsBogeskov commented Mar 16, 2026

Problem

Enumeration.toSwift() uses inline string interpolation for the file wrapper.

Solution

Extract file wrapper to Enumeration.stencil, keep complex body logic in Swift.

Testing

All 70 tests pass including golden file tests.

Stack

#169#179#180 → this PR → …

IOS-431


Note

Medium Risk
Moderate risk because enum code generation now depends on a new Enumeration.stencil template and a forced try! render call, which could change output formatting or crash if template/context mismatches.

Overview
Moves Enumeration.toSwift() from manual string concatenation to Stencil-based rendering, passing embedded, serviceName, imports, description, and the precomputed enum body into a new Enumeration.stencil template.

Updates ModelDefinition.toSwift() to thread a TemplateRenderer through the enumeration generation path so enums and other models share the same templating infrastructure.

Written by Cursor Bugbot for commit 33955f7. This will update automatically on new commits. Configure here.

{%- endif %}
{%- else -%}
{{ enumBody }}
{%- endif %}
Copy link

Choose a reason for hiding this comment

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

Embedded enum output gains spurious trailing newline

Medium Severity

When embedded is true, the old code returned modelDefinition(...) directly with no trailing newline. The new Stencil template's final {%- endif %} on line 19 uses %} (no trailing trim), so the file's trailing newline is always appended to the output. This means embedded enums now return enumBody\n instead of enumBody. In Model.modelDefinition, embedded definitions are .joined(separator: "\n\n") then .indentLines(1) — the extra \n produces an unwanted blank line before the enclosing struct's closing brace. The test spec has no inline enum definitions, so this isn't caught by golden file tests.

Additional Locations (1)
Fix in Cursor Fix in Web

@MadsBogeskov MadsBogeskov force-pushed the ios-430-convert-typealiasmodel-and-globalheadersmodel-to-stencil-v2 branch from 9bf4669 to ce10ed2 Compare March 16, 2026 11:23
@MadsBogeskov MadsBogeskov force-pushed the ios-431-convert-enumeration-generator-to-stencil-template-v2 branch from ea90dad to ba38e2b Compare March 16, 2026 11:23
[IOS-431](https://linear.app/lunar/issue/IOS-431)

- Create Enumeration.stencil template for file wrapper (imports, extension, description)
- Update Enumeration.toSwift() to use templateRenderer
- Thread templateRenderer through ModelDefinition.toSwift() to Enumeration
- Keep modelDefinition() for enum body generation (complex logic)

Amp-Thread-ID: https://ampcode.com/threads/T-019ce770-c162-72fe-8004-8407716bb370
Co-authored-by: Amp <amp@ampcode.com>
@MadsBogeskov MadsBogeskov force-pushed the ios-430-convert-typealiasmodel-and-globalheadersmodel-to-stencil-v2 branch from ce10ed2 to 9684aff Compare March 16, 2026 11:40
@MadsBogeskov MadsBogeskov force-pushed the ios-431-convert-enumeration-generator-to-stencil-template-v2 branch from ba38e2b to 33955f7 Compare March 16, 2026 11:40
Copy link

@cursor cursor bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

There are 2 total unresolved issues (including 1 from previous review).

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.

{% endfor %}
{%- if serviceName %}

extension {{ serviceName }} {
Copy link

Choose a reason for hiding this comment

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

Extra blank line between imports and extension declaration

Low Severity

When packagesToImport is non-empty, the template produces an extra blank line between the import statements and the extension declaration compared to the old inline code. The for loop emits a trailing newline after the last import, and the text after {%- if serviceName %} contributes two more newlines (end-of-line 5 plus the empty line 6), yielding two blank lines total instead of the original one. Golden file tests don't catch this because they always pass an empty packagesToImport.

Additional Locations (1)
Fix in Cursor Fix in Web

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.

1 participant