Commit 0c048a1
fix(codegen-spring): close two cross-port parity gaps in SpringPayloadGenerator
Two divergences from Kotlin's `KotlinPayloadGenerator` discovered when
running against a non-trivial payload with `field.object` children:
## Gap 1 — `scalarFields()` filter dropped every `ObjectField`
Previously `SpringPayloadGenerator.emitPayloadRecord` routed VO fields through
a `scalarFields()` filter that excluded every `ObjectField`. Effect: a payload
with a naked `field.object @objectRef` (no `origin.*`) silently lost that
component. The class's own Javadoc promised a "no origin child — fall back to
SpringTypeMapper" path, but the fallback never ran because the field was
filtered before `resolveFieldType` saw it.
Kotlin's reference iterates `voObject.metaFields` with no filter and resolves
plain `ObjectField` via the same nested-payload recursion `origin.collection`
already uses.
**Fix:**
- Drop the `scalarFields()` filter; route every field through
`resolveFieldType` directly.
- Add a `field.object` arm to `resolveFieldType` (lower precedence than
`origin.*`): single ref → emit `<TargetShortName>Payload` and return that
type; `isArray: true` → return `java.util.List<TargetPayload>`.
- Extract the nested-emit-and-return-type logic into a shared
`emitNestedAndReturnType(target, loader, nestedPkg, outRoot,
emittedNestedFqns, asList)` helper, used by both `resolveCollectionType`
and the new `resolveObjectFieldType` arm. Dedupe by target FQN per-run as
before.
- Update class Javadoc — drop the "ObjectField children are skipped" bullet;
document the new `field.object` precedence + the PascalCase naming rule.
## Gap 2 — generated class names not PascalCase-capitalised
Templates declared in `camelCase` (e.g. `npcTurn`, `lookupWeather`,
`adjudicationUser`) produced lowercase-first record file names
(`npcTurnPayload.java`) — compiles, but violates Java's PascalCase
class-naming convention and diverges from Kotlin/C#/TS/Python.
**Fix:**
- Add `capitalizeFirst(s)` helper in both `SpringPayloadGenerator` and
`SpringOutputParserGenerator` (paired so the parser's payload-class
reference matches the actual generated file name).
- Apply to: the top-level record name, every nested record name in
`emitNestedAndReturnType`, and the `getSingleOutputFilename` overrides
on both generators. Already-PascalCase names pass through unchanged.
## Tests
- Existing `emitsRecordForPromptTemplate` (template `npcTurn`) and
`emitsRecordForToolcallTemplate` (template `lookupWeather`) rebaselined
from `npcTurnPayload.java` / `lookupWeatherPayload.java` to
`NpcTurnPayload.java` / `LookupWeatherPayload.java`.
- 4 new tests for the `field.object` arm:
- `fieldObjectSingleRefEmitsNestedPayloadAndRecordReferenceType` — single ref,
nested payload emitted, parent component is `<TargetPayload>` (NOT List).
- `fieldObjectIsArrayEmitsListType` — isArray:true emits
`java.util.List<<TargetPayload>>`, nested payload emitted once.
- `fieldObjectMixedFieldsAllSurviveIntoParent` — scalar + single ref +
isArray ref + passthrough origin all coexist in one payload.
- `camelCaseTemplateNameYieldsPascalCaseRecord` — pins Gap 2 directly:
template `adjudicationUser` → record `AdjudicationUserPayload`; nested VO
`userContext` → file `UserContextPayload.java`.
Test count: 37 → 41 in codegen-spring (full suite green). Wider reactor
smoke (`maven-plugin` depends on `codegen-spring` transitively) still green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 76bd448 commit 0c048a1
3 files changed
Lines changed: 335 additions & 35 deletions
File tree
- server/java/codegen-spring/src
- main/java/com/metaobjects/generator/spring
- test/java/com/metaobjects/generator/spring
Lines changed: 22 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
114 | 114 | | |
115 | 115 | | |
116 | 116 | | |
117 | | - | |
118 | | - | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
119 | 125 | | |
120 | 126 | | |
121 | 127 | | |
| |||
149 | 155 | | |
150 | 156 | | |
151 | 157 | | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
152 | 171 | | |
153 | 172 | | |
154 | 173 | | |
| |||
188 | 207 | | |
189 | 208 | | |
190 | 209 | | |
191 | | - | |
| 210 | + | |
192 | 211 | | |
193 | 212 | | |
Lines changed: 86 additions & 24 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
67 | 67 | | |
68 | 68 | | |
69 | 69 | | |
70 | | - | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
71 | 77 | | |
72 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
73 | 87 | | |
74 | 88 | | |
75 | 89 | | |
76 | 90 | | |
77 | 91 | | |
78 | 92 | | |
79 | 93 | | |
80 | | - | |
81 | 94 | | |
82 | 95 | | |
83 | 96 | | |
| |||
133 | 146 | | |
134 | 147 | | |
135 | 148 | | |
136 | | - | |
| 149 | + | |
137 | 150 | | |
138 | 151 | | |
139 | 152 | | |
| |||
165 | 178 | | |
166 | 179 | | |
167 | 180 | | |
168 | | - | |
169 | | - | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
170 | 187 | | |
171 | 188 | | |
172 | 189 | | |
| |||
187 | 204 | | |
188 | 205 | | |
189 | 206 | | |
190 | | - | |
191 | | - | |
192 | | - | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
193 | 211 | | |
194 | 212 | | |
195 | 213 | | |
196 | 214 | | |
197 | 215 | | |
198 | 216 | | |
199 | 217 | | |
200 | | - | |
201 | | - | |
202 | | - | |
203 | 218 | | |
204 | 219 | | |
205 | 220 | | |
| |||
209 | 224 | | |
210 | 225 | | |
211 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
212 | 230 | | |
213 | 231 | | |
214 | 232 | | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
215 | 256 | | |
216 | 257 | | |
217 | 258 | | |
| |||
293 | 334 | | |
294 | 335 | | |
295 | 336 | | |
| 337 | + | |
| 338 | + | |
296 | 339 | | |
297 | | - | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
298 | 357 | | |
299 | | - | |
300 | 358 | | |
301 | 359 | | |
302 | 360 | | |
303 | 361 | | |
304 | | - | |
| 362 | + | |
305 | 363 | | |
306 | 364 | | |
307 | 365 | | |
308 | 366 | | |
309 | 367 | | |
310 | 368 | | |
311 | | - | |
| 369 | + | |
312 | 370 | | |
313 | 371 | | |
314 | 372 | | |
| |||
380 | 438 | | |
381 | 439 | | |
382 | 440 | | |
383 | | - | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
391 | 453 | | |
392 | 454 | | |
393 | 455 | | |
| |||
418 | 480 | | |
419 | 481 | | |
420 | 482 | | |
421 | | - | |
| 483 | + | |
422 | 484 | | |
423 | 485 | | |
0 commit comments