Skip to content

Commit 81b8028

Browse files
committed
test(codegen-kotlin): initial snapshots for fixtures
1 parent 9b06300 commit 81b8028

5 files changed

Lines changed: 113 additions & 0 deletions

File tree

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package acme.demo
2+
3+
import java.time.Instant
4+
import java.time.LocalDate
5+
import kotlin.Boolean
6+
import kotlin.Double
7+
import kotlin.Int
8+
import kotlin.Long
9+
import kotlin.String
10+
import kotlinx.serialization.Serializable
11+
12+
/**
13+
* GENERATED — do not hand-edit. Regenerated from metadata.
14+
*/
15+
@Serializable
16+
public data class Author(
17+
public val id: Long? = null,
18+
public val name: String,
19+
public val bio: String? = null,
20+
public val age: Int? = null,
21+
public val active: Boolean? = null,
22+
public val ratio: Double? = null,
23+
public val birthday: LocalDate? = null,
24+
public val createdAt: Instant? = null,
25+
)
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package acme.demo
2+
3+
import org.jetbrains.exposed.sql.Table
4+
5+
/** GENERATED — do not hand-edit. Regenerated from metadata. */
6+
object AuthorTable : Table("authors") {
7+
val id = long("id").autoIncrement()
8+
val name = varchar("name", 100)
9+
val bio = varchar("bio", 255).nullable()
10+
val age = integer("age").nullable()
11+
val active = bool("active").nullable()
12+
val ratio = double("ratio").nullable()
13+
val birthday = date("birthday").nullable()
14+
val createdAt = timestampWithTimeZone("createdAt").nullable()
15+
16+
override val primaryKey = PrimaryKey(id)
17+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package acme.demo
2+
3+
import com.metaobjects.`object`.MetaObject
4+
import com.metaobjects.field.MetaField
5+
import org.jetbrains.exposed.sql.Table
6+
7+
/**
8+
* GENERATED — compares a [MetaObject]'s field set vs an Exposed [Table]'s column set
9+
* and records any discrepancies into the supplied `errors` list.
10+
*/
11+
object ExposedTableValidator {
12+
13+
fun check(obj: MetaObject, table: Table, errors: MutableList<String>) {
14+
val expectedCols = obj.metaFields.map { it.name }.toSet()
15+
val actualCols = table.columns.map { it.name }.toSet()
16+
val missing = expectedCols - actualCols
17+
val extra = actualCols - expectedCols
18+
if (missing.isNotEmpty()) {
19+
errors.add("${obj.name}: metadata declares fields not in generated table: $missing")
20+
}
21+
if (extra.isNotEmpty()) {
22+
errors.add("${obj.name}: generated table has columns not in metadata: $extra")
23+
}
24+
}
25+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package acme.demo
2+
3+
import com.metaobjects.loader.MetaDataLoader
4+
import com.metaobjects.metadata.ktx.metaObjectOrNull
5+
import org.jetbrains.exposed.sql.Table
6+
7+
/**
8+
* GENERATED — runtime drift gate. Call [validate] from a Spring `@PostConstruct` or
9+
* `ApplicationReadyEvent` listener to fail-fast when generated Tables drift from metadata.
10+
*/
11+
object MetadataStartupValidator {
12+
13+
private val tablesToValidate: List<Pair<String, Table>> = listOf(
14+
"acme::demo::Author" to AuthorTable
15+
)
16+
17+
fun validate(loader: MetaDataLoader) {
18+
val errors = mutableListOf<String>()
19+
for ((fqn, table) in tablesToValidate) {
20+
val obj = loader.metaObjectOrNull(fqn)
21+
if (obj == null) {
22+
errors.add("metadata missing $fqn (generated table: ${table.tableName})")
23+
continue
24+
}
25+
ExposedTableValidator.check(obj, table, errors)
26+
}
27+
check(errors.isEmpty()) {
28+
"MetadataStartupValidator: ${errors.size} drift(s):\n - " +
29+
errors.joinToString("\n - ")
30+
}
31+
}
32+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package acme.ai.prompts
2+
3+
import kotlin.Long
4+
import kotlin.String
5+
import kotlinx.serialization.Serializable
6+
7+
/**
8+
* GENERATED — payload for template `acme::ai::WelcomePrompt`.
9+
*/
10+
@Serializable
11+
public data class WelcomePromptPayload(
12+
public val id: Long,
13+
public val name: String,
14+
)

0 commit comments

Comments
 (0)