|
1 | 1 | # MetaObjects :: Codegen :: Kotlin (`codegen-kotlin`) |
2 | 2 |
|
3 | | -(README populated by implementation plan Task 5.3.) |
| 3 | +Kotlin codegen target. Emits idiomatic Kotlin code from MetaObjects metadata via KotlinPoet: |
| 4 | + |
| 5 | +| Generator | Output | Per | |
| 6 | +|---|---|---| |
| 7 | +| `KotlinEntityGenerator` | `<Entity>.kt` — @Serializable data class | every `object.entity` | |
| 8 | +| `KotlinExposedTableGenerator` | `<Entity>Table.kt` — Exposed `Table` object | every entity with `source.rdb` | |
| 9 | +| `KotlinPayloadGenerator` | `<Template>Payload.kt` — @Serializable payload class | every `template.prompt` / `template.output` | |
| 10 | +| `KotlinValidatorGenerator` | `MetadataStartupValidator.kt` + `ExposedTableValidator.kt` | once per project | |
| 11 | + |
| 12 | +## Wiring in your `pom.xml` |
| 13 | + |
| 14 | +```xml |
| 15 | +<plugin> |
| 16 | + <groupId>com.metaobjects</groupId> |
| 17 | + <artifactId>metaobjects-maven-plugin</artifactId> |
| 18 | + <configuration> |
| 19 | + <loader> |
| 20 | + <sourceDir>src/main/metaobjects</sourceDir> |
| 21 | + </loader> |
| 22 | + <generators> |
| 23 | + <generator> |
| 24 | + <classname>com.metaobjects.generator.kotlin.KotlinEntityGenerator</classname> |
| 25 | + <args><outputDir>${project.build.directory}/generated-sources/kotlin</outputDir></args> |
| 26 | + </generator> |
| 27 | + <generator> |
| 28 | + <classname>com.metaobjects.generator.kotlin.KotlinExposedTableGenerator</classname> |
| 29 | + <args><outputDir>${project.build.directory}/generated-sources/kotlin</outputDir></args> |
| 30 | + </generator> |
| 31 | + <generator> |
| 32 | + <classname>com.metaobjects.generator.kotlin.KotlinPayloadGenerator</classname> |
| 33 | + <args><outputDir>${project.build.directory}/generated-sources/kotlin</outputDir></args> |
| 34 | + </generator> |
| 35 | + <generator> |
| 36 | + <classname>com.metaobjects.generator.kotlin.KotlinValidatorGenerator</classname> |
| 37 | + <args> |
| 38 | + <outputDir>${project.build.directory}/generated-sources/kotlin</outputDir> |
| 39 | + <packageName>com.yourapp</packageName> |
| 40 | + </args> |
| 41 | + </generator> |
| 42 | + </generators> |
| 43 | + </configuration> |
| 44 | +</plugin> |
| 45 | +``` |
| 46 | + |
| 47 | +## Runtime drift gate |
| 48 | + |
| 49 | +After codegen runs, your consumer wires the generated `MetadataStartupValidator` into Spring boot: |
| 50 | + |
| 51 | +```kotlin |
| 52 | +@SpringBootApplication |
| 53 | +class App { |
| 54 | + @EventListener(ApplicationReadyEvent::class) |
| 55 | + fun validateMetadata() { |
| 56 | + val loader = loadResources("app", listOf("meta.author.json")) |
| 57 | + MetadataStartupValidator.validate(loader) |
| 58 | + } |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +This fails fast at boot if generated tables drift from metadata (drift source D7). |
| 63 | + |
| 64 | +## Coverage status |
| 65 | + |
| 66 | +MVP ships 7 primitive types (`field.string`, `int`, `long`, `double`, `boolean`, `date`, `timestamp`). |
| 67 | +Less-common types (`field.enum`, `field.currency`, `field.object`, `field.uuid`) throw |
| 68 | +`IllegalArgumentException` at codegen time with a clear message. Add support per real consumer ask. |
| 69 | + |
| 70 | +Flyway migration generation lives in the Maven plugin under the existing `meta:migrate` goal — |
| 71 | +pass `<flyway>true</flyway>` to switch output naming to Flyway conventions. |
| 72 | + |
| 73 | +CI drift detection lives in the new `meta:verify` goal — runs DB introspection + diffs vs metadata. |
0 commit comments