Skip to content

fix(codegen-kotlin): write Spring controller through KotlinWriter - #660

Merged
dmealing merged 3 commits into
mainfrom
fm/mo-130-kt-writer-3
Nov 26, 2026
Merged

dmealing merged 3 commits into
mainfrom
fm/mo-130-kt-writer-3

Conversation

@dmealing

@dmealing dmealing commented Nov 26, 2026 •

Copy link
Copy Markdown
Member

What Changed

  • KotlinSpringControllerGenerator now writes the writable, TPH base, and read-only (projection and report) controllers through KotlinWriter instead of a hand-typed StringBuilder layout. sortColumnExpr became writeOrderBy, which writes the same orderBy when-expression through the writer. Its entry leaves the layout-ratchet allowlist.
  • Generated controllers change in layout only: imports sit in one sorted group, the class has no blank line at its start or end, the TPH controller has one blank line before its exception handlers, and two bodies (the Exposed 1.x WhereOp loop and a PATCH handler whose only automatic column is @autoSet) are indented by their blocks. Compiled behaviour is unchanged.
  • API change for open subclasses: emitFilterPipeline, emitPerFieldDispatchArm, emitTypedCoercer, emitM2mEndpoint and emitTphSubtypeM2mEndpoint take a KotlinWriter where they took a StringBuilder. Owned copies ejected at an earlier version keep their own code and still compile (EjectedAtBaseGeneratorsCompatTest). Recorded in CHANGELOG 1.3.0.

Author evidence (local, before the gate)

  • Before/after equivalence harness (temporary, not committed): the old and new generator over every loadable meta*.json in fixtures/ and the codegen-kotlin test resources (515 models) x 3 arg variants (exposedApi 0 defaults; exposedApi 1 + pagination + reject-unknown + report export; exposedApi 0 + pagination + allow + report export) = 3,774 generated files. Ignoring indentation, blank lines and import order: 0 text differences. Indentation differs only in the two bodies named above.
  • codegen-kotlin module: 706 tests, 0 failures (layout ratchet, six refreshed controller goldens, codegen compile gate, ejected-at-base compat).
  • scripts/ci-local.sh --only java passed: conformance java + kotlin, java-reactor (incl. the Exposed 1.x controller compile check), integration-tests java, and integration-tests kotlin (the generated api-contract lanes against Testcontainers Postgres).
  • The gate's "no live product scenario" Test note was declined on this evidence (approved Test exception; outcome passed-with-override). One no-mistakes run.
Validation

Risk Assessment

✅ Low: The change is a mechanical move from StringBuilder to KotlinWriter: the golden diffs are layout only (import order, blank lines), the only multi-line snippet (stripCredentials) matches the old trimMargin text, writeOrderBy writes the same when-expression, and the writer fails loudly on embedded newlines, unbalanced blocks and import conflicts, so the remaining risk is only the intended change to the protected hook signatures, which the CHANGELOG records.

Testing

Baseline affected-lane command passed. I re-ran the focused Kotlin suites for the ratchet, controller generator, eject-at-base compat, compile gates and snapshots against the worktree; all pass with fresh surefire reports. I did not drive the generator live through the Maven plugin or the CLI on a fixture, so no scenario is live and none is marked pass. Verdict inconclusive: the layout-only change is supported by the focused tests and the author's equivalence harness, but live product validation was not performed.

  • Live validation: ⚠️ inconclusive - 0 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Layout ratchet accepts the converted controller (controller entry removed from allowlist, ratchet green) ⏸️ untested no Unit test of generator source, not a live product run. Not driven through the CLI because the change is a source-layout check with no user-facing command.
Generated Spring controller output equivalent to pre-change generator (layout-only change) ⏸️ untested no Equivalence is proven by the author's 3,774-file harness, which I did not re-run. Driving mvn metaobjects:generate on a fixture needs the reactor plugin install, which is outside this step's time bu…
Generated controller compiles and runs (api-contract lanes) ⏸️ untested no Compile gates ran as unit-level tests. The Testcontainers Postgres api-contract lane (integration-tests-kotlin) was not run here; the author reports it passed under --only java.
  • Outcome: ⚠️ 1 warning across 1 run (4m0s)

Pipeline

Updates from git push no-mistakes

✅ **Intent** - passed

✅ No issues found.

✅ **Rebase** - passed

✅ No issues found.

⚠️ **Review** - 2 infos
  • ℹ️ CHANGELOG.md:1659 - The CHANGELOG called its list of layout diffs complete ("Regenerating shows those diffs and nothing else"), but the refreshed TPH golden (entity-with-tph/acme/auth/AuthController.kt, old line 677) also collapses a doubled blank line before the exception handlers. I added "one blank line where the TPH controller wrote two (before its exception handlers)" to the list. This is a documentation edit only; the layout-only requirement still holds.
  • ℹ️ server/java/codegen-kotlin/src/main/kotlin/com/metaobjects/generator/kotlin/KotlinSpringControllerGenerator.kt:2827 - The KDoc on writeOrderBy (formerly sortColumnExpr) still said "The generated Kotlin expression resolving a sort FIELD NAME…". It now writes the whole q = q.orderBy(...) statement through the writer, so I reworded the first line to "Writes the q = q.orderBy(...) statement whose when resolves a sort FIELD NAME to its Exposed column." Comment edit only.
⚠️ **Test** - 1 warning
  • ⚠️ live validation verdict: inconclusive (0 of 3 scenarios were driven live against the product); untested: Layout ratchet accepts the converted controller (controller entry removed from allowlist, ratchet green), Generated Spring controller output equivalent to pre-change generator (layout-only change), Generated controller compiles and runs (api-contract lanes)
  • Live validation: ⚠️ inconclusive - 0 of 3 scenarios driven live against the product
Scenario Result Live Evidence
Layout ratchet accepts the converted controller (controller entry removed from allowlist, ratchet green) ⏸️ untested no Unit test of generator source, not a live product run. Not driven through the CLI because the change is a source-layout check with no user-facing command.
Generated Spring controller output equivalent to pre-change generator (layout-only change) ⏸️ untested no Equivalence is proven by the author's 3,774-file harness, which I did not re-run. Driving mvn metaobjects:generate on a fixture needs the reactor plugin install, which is outside this step's time bu…
Generated controller compiles and runs (api-contract lanes) ⏸️ untested no Compile gates ran as unit-level tests. The Testcontainers Postgres api-contract lane (integration-tests-kotlin) was not run here; the author reports it passed under --only java.
  • scripts/ci-local.sh --affected --strict-toolchains
  • mvn -o -q -pl codegen-kotlin -am test -Dtest='KotlinLayoutRatchetTest,KotlinSpringControllerGeneratorTest*,EjectedAtBaseGeneratorsCompatTest' in server/java (exit 0; surefire: ratchet 20/20, controller 8/8, eject-at-base 3/3, 0 failures)
  • mvn -o -q -pl codegen-kotlin -am test -Dtest='CodegenCompileConformanceTest,KotlinWriteThroughCompileTest,KotlinCodegenSnapshotTest,KotlinCodegenE2ETest,KotlinM2mTraversalCompileRunTest' (exit 0; 2, 4, 18, 1, 1 tests, 0 failures)
  • Read server/java/codegen-kotlin/src/test/resources/layout-ratchet/allowlist.json: controller entry removed, no other change
  • Baseline: scripts/ci-local.sh --affected --strict-toolchains passed at target commit (broad regression, not re-run)
✅ **Document** - passed

✅ No issues found.

✅ **Lint** - passed

✅ No issues found.

✅ **Push** - passed

✅ No issues found.

…otlinWriter (W-KT-3)

KotlinSpringControllerGenerator (the writable, TPH base and read-only
controllers, with the filter pipeline, M:N traversal routes, sort surface
and credential redactor they share) now writes through KotlinWriter
(ADR-0063) instead of hand-indented StringBuilder text. Its entry leaves
the Kotlin layout ratchet's allowlist.

Generated output changes in layout only: imports in one sorted group, no
blank line at the start or end of the controller class, and two bodies the
old builder indented one level off (the Exposed 1.x WhereOp loop, and a
PATCH handler whose only automatic column is @autoset) now indented by
their blocks. The six controller snapshot goldens are refreshed.

The protected open hooks (emitFilterPipeline, emitPerFieldDispatchArm,
emitTypedCoercer, emitM2mEndpoint, emitTphSubtypeM2mEndpoint) take a
KotlinWriter where they took a StringBuilder; an owned copy ejected at an
earlier version carries its own and still compiles.
@dmealing
dmealing merged commit b7fc968 into main Nov 26, 2026
9 checks passed
@dmealing
dmealing deleted the fm/mo-130-kt-writer-3 branch November 26, 2026 11:34
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