Update 2
This commit is contained in:
1 parent
48b8538527
commit
0194b262c7
6 files changed
+117
-74
No files matched your search
+5
-16
@@ -5,10 +5,6 @@ plugins {
|
|||||||
`kotlin-dsl`
|
`kotlin-dsl`
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "no.iktdev"
|
|
||||||
version = "1.0-SNAPSHOT"
|
|
||||||
val named = "ts-gen"
|
|
||||||
|
|
||||||
val dynamicVersion = providers.provider {
|
val dynamicVersion = providers.provider {
|
||||||
val ref = System.getenv("GITHUB_REF") ?: ""
|
val ref = System.getenv("GITHUB_REF") ?: ""
|
||||||
val isSnapshot = ref.endsWith("/master") || ref.endsWith("/main")
|
val isSnapshot = ref.endsWith("/master") || ref.endsWith("/main")
|
||||||
@@ -29,6 +25,11 @@ val dynamicVersion = providers.provider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
group = "no.iktdev"
|
||||||
|
version = dynamicVersion.get()
|
||||||
|
val named = "ts-gen"
|
||||||
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
}
|
}
|
||||||
@@ -62,18 +63,6 @@ dependencies {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
tasks.jar {
|
|
||||||
manifest {
|
|
||||||
attributes(
|
|
||||||
"Implementation-Title" to project.name,
|
|
||||||
// Bruk en provider for å hente dynamisk versjon, slik at den ikke blir fastlåst til "1.0-SNAPSHOT"
|
|
||||||
"Implementation-Version" to provider {
|
|
||||||
// Hvis du har definert dynamicVersion som en lokal val, kan du kalle .get() på den her:
|
|
||||||
dynamicVersion.get()
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
tasks.test {
|
tasks.test {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
|
|||||||
@@ -3,14 +3,9 @@ package no.iktdev.ts
|
|||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
object TsGenerator {
|
object TsGenerator {
|
||||||
var consumerAppVersionInfo: String = "unknown"
|
var versionInfo: String = System.getProperty("tsgenerator.version")
|
||||||
var versionInfo: String = TsGenerator::class.java.getPackage()?.implementationVersion
|
?: TsGenerator::class.java.getPackage()?.implementationVersion
|
||||||
?: TsGenerator::class.java.getResource("/META-INF/MANIFEST.MF")?.let {
|
?: "dev"
|
||||||
// Alternativ fallback hvis du vil lese manifest-streamen direkte,
|
|
||||||
// men pakke-sjekken under dekker de fleste tilfeller når den er bygget.
|
|
||||||
null
|
|
||||||
}
|
|
||||||
?: "1.0.0" // Hardkodet fallback eller "unknown"
|
|
||||||
var buildTime: String = java.time.Instant.now().toString()
|
var buildTime: String = java.time.Instant.now().toString()
|
||||||
|
|
||||||
val ttm = TsTypeMapper()
|
val ttm = TsTypeMapper()
|
||||||
@@ -20,8 +15,8 @@ object TsGenerator {
|
|||||||
packageName: String,
|
packageName: String,
|
||||||
output: File,
|
output: File,
|
||||||
classLoader: ClassLoader = Thread.currentThread().contextClassLoader,
|
classLoader: ClassLoader = Thread.currentThread().contextClassLoader,
|
||||||
includeSealed: Boolean = true,
|
includeTypedSealed: Boolean = true,
|
||||||
includeInterface: Boolean = true
|
includeTypedInterface: Boolean = true
|
||||||
) {
|
) {
|
||||||
println("TsGenerator: scanning package: $packageName")
|
println("TsGenerator: scanning package: $packageName")
|
||||||
|
|
||||||
@@ -33,7 +28,6 @@ object TsGenerator {
|
|||||||
val ts = buildString {
|
val ts = buildString {
|
||||||
appendLine("// AUTO-GENERATED. DO NOT EDIT.")
|
appendLine("// AUTO-GENERATED. DO NOT EDIT.")
|
||||||
appendLine("// TSGenerator Version: $versionInfo")
|
appendLine("// TSGenerator Version: $versionInfo")
|
||||||
appendLine("// Consumer App Version: $consumerAppVersionInfo")
|
|
||||||
appendLine("// Time: $buildTime")
|
appendLine("// Time: $buildTime")
|
||||||
appendLine("// Source: $packageName")
|
appendLine("// Source: $packageName")
|
||||||
appendLine()
|
appendLine()
|
||||||
@@ -44,32 +38,25 @@ object TsGenerator {
|
|||||||
// 1) Sealed interface → union type alias
|
// 1) Sealed interface → union type alias
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
cls.isSealed && cls.java.isInterface -> {
|
cls.isSealed && cls.java.isInterface -> {
|
||||||
val subTypes = cls.sealedSubclasses
|
println("Generating union type for sealed interface: ${cls.simpleName}")
|
||||||
.mapNotNull { it.simpleName }
|
append(tmr.sealedUnionToTs(cls))
|
||||||
.joinToString(" | ")
|
|
||||||
|
|
||||||
println("Generating union type for sealed interface: ${cls.simpleName} = $subTypes")
|
|
||||||
appendLine("export type ${cls.simpleName} = $subTypes")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ----------------------------------------------------
|
||||||
// 1a) Sealed class → union type alias
|
// 1a) Sealed class → union type alias
|
||||||
|
// ----------------------------------------------------
|
||||||
cls.isSealed && !cls.java.isInterface -> {
|
cls.isSealed && !cls.java.isInterface -> {
|
||||||
val subTypes = cls.sealedSubclasses
|
println("Generating union type for sealed class: ${cls.simpleName}")
|
||||||
.mapNotNull { it.simpleName }
|
append(tmr.sealedUnionToTs(cls))
|
||||||
.joinToString(" | ")
|
|
||||||
|
|
||||||
println("Generating union type for sealed class: ${cls.simpleName} = $subTypes")
|
|
||||||
appendLine("export type ${cls.simpleName} = $subTypes")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
// 1b) Sealed subtype (data object / data class)
|
// 1b) Sealed subtype (data object / data class)
|
||||||
// → generer interface selv uten properties
|
// → Bruker includeTypedSealed for type-lappen
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
cls.isSealedSubtype() -> {
|
cls.isSealedSubtype() -> {
|
||||||
println("Generating sealed subtype interface: ${cls.simpleName}")
|
println("Generating sealed subtype interface: ${cls.simpleName}")
|
||||||
append(tmr.sealedSubtypeToTs(cls, ttm, includeSealed))
|
append(tmr.dataClassToTs(cls, ttm, includeTypedSealed))
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
@@ -82,10 +69,11 @@ object TsGenerator {
|
|||||||
|
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
// 3) Data class → interface
|
// 3) Data class → interface
|
||||||
|
// → Bruker includeTypedInterface for type-lappen
|
||||||
// ----------------------------------------------------
|
// ----------------------------------------------------
|
||||||
cls.hasProperties() && !cls.isSealed -> {
|
cls.hasProperties() && !cls.isSealed -> {
|
||||||
println("Generating interface: ${cls.simpleName}")
|
println("Generating interface: ${cls.simpleName}")
|
||||||
append(tmr.dataClassToTs(cls, ttm, includeInterface))
|
append(tmr.dataClassToTs(cls, ttm, includeTypedInterface))
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> {
|
else -> {
|
||||||
@@ -101,5 +89,4 @@ object TsGenerator {
|
|||||||
|
|
||||||
println("TsGenerator: wrote file to ${output.absolutePath}")
|
println("TsGenerator: wrote file to ${output.absolutePath}")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
|
||||||
@@ -2,7 +2,6 @@ package no.iktdev.ts
|
|||||||
|
|
||||||
import kotlin.reflect.KClass
|
import kotlin.reflect.KClass
|
||||||
import kotlin.reflect.full.memberProperties
|
import kotlin.reflect.full.memberProperties
|
||||||
import kotlin.reflect.full.primaryConstructor
|
|
||||||
|
|
||||||
class TsModelRenderer {
|
class TsModelRenderer {
|
||||||
|
|
||||||
@@ -13,11 +12,21 @@ class TsModelRenderer {
|
|||||||
return "export type ${cls.simpleName} = $values\n"
|
return "export type ${cls.simpleName} = $values\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun sealedSubtypeToTs(cls: KClass<*>, ttm: TsTypeMapper, includeTypeDiscriminator: Boolean): String {
|
// Genererer union-typen for sealed klasser (f.eks. export type Progress = A | B | C)
|
||||||
return dataClassToTs(cls, ttm, includeTypeDiscriminator)
|
fun sealedUnionToTs(cls: KClass<*>): String {
|
||||||
|
val subTypes = cls.sealedSubclasses
|
||||||
|
.mapNotNull { it.simpleName }
|
||||||
|
.joinToString(" | ")
|
||||||
|
|
||||||
|
return "export type ${cls.simpleName} = $subTypes\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
fun dataClassToTs(cls: KClass<*>, ttm: TsTypeMapper, includeTypeDiscriminator: Boolean): String {
|
// Genererer standard interface for klasser/subtyper
|
||||||
|
fun dataClassToTs(
|
||||||
|
cls: KClass<*>,
|
||||||
|
ttm: TsTypeMapper,
|
||||||
|
includeTypedInterface: Boolean
|
||||||
|
): String {
|
||||||
val typeParams = cls.typeParameters.map { it.name }
|
val typeParams = cls.typeParameters.map { it.name }
|
||||||
val generic = if (typeParams.isNotEmpty()) "<" + typeParams.joinToString(", ") + ">" else ""
|
val generic = if (typeParams.isNotEmpty()) "<" + typeParams.joinToString(", ") + ">" else ""
|
||||||
|
|
||||||
@@ -34,19 +43,18 @@ class TsModelRenderer {
|
|||||||
superClasses.addAll(superInterfaces)
|
superClasses.addAll(superInterfaces)
|
||||||
|
|
||||||
val extendsClause = if (superClasses.isNotEmpty()) {
|
val extendsClause = if (superClasses.isNotEmpty()) {
|
||||||
" extends ${superClasses.joinToString(", ") { it.simpleName!! }}"
|
" extends " + superClasses.joinToString(", ") { it.simpleName!! }
|
||||||
} else ""
|
} else ""
|
||||||
|
|
||||||
val inheritedPropNames = superClasses.flatMap { it.memberProperties }.map { it.name }.toSet()
|
val inheritedPropNames = superClasses.flatMap { it.memberProperties }.map { it.name }.toSet()
|
||||||
|
|
||||||
// Sjekk om klassen har et 'type'-felt, og tving det til klassens navn hvis flagget er satt
|
|
||||||
val hasTypeProp = cls.memberProperties.any { it.name == "type" }
|
val hasTypeProp = cls.memberProperties.any { it.name == "type" }
|
||||||
|
|
||||||
val props = cls.memberProperties
|
val props = cls.memberProperties
|
||||||
.filter { it.name !in inheritedPropNames }
|
.filter { it.name !in inheritedPropNames }
|
||||||
.joinToString("\n") { prop ->
|
.joinToString("\n") { prop ->
|
||||||
val tsType = if (prop.name == "type" && includeTypeDiscriminator) {
|
// HVIS feltet heter "type" og vi har slått på includeTypedInterface,
|
||||||
// Tving type-feltet til å bli en string literal basert på klassens navn (f.eks. "FileCopyProgress")
|
// tvinger vi type-definisjonen til å bli klassens navn som en string-literal!
|
||||||
|
val tsType = if (prop.name == "type" && includeTypedInterface) {
|
||||||
"\"${cls.simpleName}\""
|
"\"${cls.simpleName}\""
|
||||||
} else {
|
} else {
|
||||||
ttm.kotlinToTsType(prop.returnType.toString(), typeParams)
|
ttm.kotlinToTsType(prop.returnType.toString(), typeParams)
|
||||||
@@ -56,10 +64,12 @@ class TsModelRenderer {
|
|||||||
|
|
||||||
return buildString {
|
return buildString {
|
||||||
appendLine("export interface ${cls.simpleName}$generic$extendsClause {")
|
appendLine("export interface ${cls.simpleName}$generic$extendsClause {")
|
||||||
// Hvis klassen ikke har 'type'-felt i det hele tatt, men skal ha diskriminator, legg til den
|
|
||||||
if (includeTypeDiscriminator && !hasTypeProp && "type" !in inheritedPropNames) {
|
// Hvis klassen IKKE hadde "type"-felt fra før, men flagget er på, legger vi til lappen her
|
||||||
|
if (includeTypedInterface && !hasTypeProp && "type" !in inheritedPropNames) {
|
||||||
appendLine(" type: \"${cls.simpleName}\";")
|
appendLine(" type: \"${cls.simpleName}\";")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (props.isNotBlank()) appendLine(props)
|
if (props.isNotBlank()) appendLine(props)
|
||||||
appendLine("}")
|
appendLine("}")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,13 @@ package no.iktdev.ts
|
|||||||
class TsTypeMapper {
|
class TsTypeMapper {
|
||||||
fun kotlinToTsType(kotlinType: String, genericParams: List<String> = emptyList()): String {
|
fun kotlinToTsType(kotlinType: String, genericParams: List<String> = emptyList()): String {
|
||||||
val isNullable = kotlinType.endsWith("?")
|
val isNullable = kotlinType.endsWith("?")
|
||||||
val clean = kotlinType.removeSuffix("?")
|
// Fjerner eventuelle backticks som Kotlin legger rundt lokale/test-klasser, og trimmet
|
||||||
|
val clean = kotlinType.removeSuffix("?").replace("`", "").trim()
|
||||||
|
|
||||||
|
// Sjekk om typen er en generisk parameter (f.eks. "T")
|
||||||
|
if (genericParams.contains(clean)) {
|
||||||
|
return if (isNullable) "$clean | null" else clean
|
||||||
|
}
|
||||||
|
|
||||||
// UUID → string
|
// UUID → string
|
||||||
if (clean == "java.util.UUID") {
|
if (clean == "java.util.UUID") {
|
||||||
@@ -66,7 +72,7 @@ class TsTypeMapper {
|
|||||||
return if (isNullable) "$base | null" else base
|
return if (isNullable) "$base | null" else base
|
||||||
}
|
}
|
||||||
|
|
||||||
// Primitive mappings
|
// Primitive mappings / Klasser
|
||||||
val base = when (clean) {
|
val base = when (clean) {
|
||||||
"kotlin.String" -> "string"
|
"kotlin.String" -> "string"
|
||||||
"kotlin.Int",
|
"kotlin.Int",
|
||||||
@@ -76,8 +82,8 @@ class TsTypeMapper {
|
|||||||
"kotlin.Boolean" -> "boolean"
|
"kotlin.Boolean" -> "boolean"
|
||||||
"kotlin.Any" -> "any"
|
"kotlin.Any" -> "any"
|
||||||
else -> {
|
else -> {
|
||||||
if (clean.contains(".")) clean.substringAfterLast(".")
|
// Stripper vekk alt av pakkenavn og eventuelle lokale test-referanser med $
|
||||||
else "any"
|
clean.substringAfterLast(".").substringAfterLast("$")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,29 +12,28 @@ interface TsGeneratorExtension {
|
|||||||
val packageName: Property<String>
|
val packageName: Property<String>
|
||||||
val outputFile: Property<File>
|
val outputFile: Property<File>
|
||||||
|
|
||||||
val includeSealed: Property<Boolean>
|
val includeTypedSealed: Property<Boolean>
|
||||||
val includeInterface: Property<Boolean>
|
val includeTypedInterface: Property<Boolean>
|
||||||
}
|
}
|
||||||
|
|
||||||
class TsGeneratorPlugin : Plugin<Project> {
|
class TsGeneratorPlugin : Plugin<Project> {
|
||||||
override fun apply(project: Project) {
|
override fun apply(project: Project) {
|
||||||
val extension = project.extensions.create("tsGenerator", TsGeneratorExtension::class.java).apply {
|
val extension = project.extensions.create("tsGenerator", TsGeneratorExtension::class.java).apply {
|
||||||
includeSealed.convention(true)
|
includeTypedSealed.convention(false)
|
||||||
includeInterface.convention(true)
|
includeTypedInterface.convention(false)
|
||||||
}
|
}
|
||||||
|
|
||||||
project.tasks.register("generateTs") {
|
project.tasks.register("generateTs") {
|
||||||
group = "typescript"
|
group = "typescript"
|
||||||
dependsOn("compileKotlin")
|
dependsOn("compileKotlin")
|
||||||
|
|
||||||
doLast {
|
doLast {
|
||||||
TsGenerator.versionInfo = project.version.toString()
|
TsGenerator.versionInfo = project.version.toString()
|
||||||
TsGenerator.buildTime = java.time.Instant.now().toString()
|
TsGenerator.buildTime = java.time.Instant.now().toString()
|
||||||
|
|
||||||
val pkg = extension.packageName.get()
|
val pkg = extension.packageName.get()
|
||||||
val out = extension.outputFile.get()
|
val out = extension.outputFile.get()
|
||||||
val includeSealed = extension.includeSealed.get()
|
val includeTypedSealed = extension.includeTypedSealed.get()
|
||||||
val includeInterface = extension.includeInterface.get()
|
val includeTypedInterface = extension.includeTypedInterface.get()
|
||||||
|
|
||||||
// Hent classpath for å lage ClassLoaderen
|
// Hent classpath for å lage ClassLoaderen
|
||||||
val mainSourceSet = project.extensions.getByType(JavaPluginExtension::class.java)
|
val mainSourceSet = project.extensions.getByType(JavaPluginExtension::class.java)
|
||||||
@@ -44,7 +43,7 @@ class TsGeneratorPlugin : Plugin<Project> {
|
|||||||
val cl = URLClassLoader(urls, TsGenerator::class.java.classLoader)
|
val cl = URLClassLoader(urls, TsGenerator::class.java.classLoader)
|
||||||
|
|
||||||
// Kall generatoren med det nye flagget
|
// Kall generatoren med det nye flagget
|
||||||
TsGenerator.generate(pkg, out, cl, includeSealed, includeInterface)
|
TsGenerator.generate(pkg, out, cl, includeTypedSealed, includeTypedInterface)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,23 +39,77 @@ class TsModelRendererTest {
|
|||||||
assertThat(enumTs).isEqualTo("export type DeviceStatus = \"ONLINE\" | \"OFFLINE\"\n")
|
assertThat(enumTs).isEqualTo("export type DeviceStatus = \"ONLINE\" | \"OFFLINE\"\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should handle generic classes correctly`() {
|
||||||
|
data class Wrapper<T>(val data: T, val message: String?)
|
||||||
|
|
||||||
|
val result = renderer.dataClassToTs(Wrapper::class, ttm, true)
|
||||||
|
|
||||||
|
assertThat(result).contains("export interface Wrapper<T>")
|
||||||
|
assertThat(result).contains("data: T;")
|
||||||
|
assertThat(result).contains("message: string | null;")
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `sealed subtype test - verifiser type discriminator`() {
|
fun `sealed subtype test - verifiser type discriminator`() {
|
||||||
data class Sensor(val type: String = "TEMP_SENSOR", val value: Double)
|
data class Sensor(val type: String = "TEMP_SENSOR", val value: Double)
|
||||||
|
|
||||||
// Send med true for å inkludere type-diskriminatoren i testen
|
// Bruker dataClassToTs direkte ettersom sealed subtyper nå bruker denne metoden
|
||||||
val sensorTs = renderer.sealedSubtypeToTs(Sensor::class, ttm, includeTypeDiscriminator = true)
|
val sensorTs = renderer.dataClassToTs(Sensor::class, ttm, includeTypedInterface = true)
|
||||||
|
|
||||||
assertThat(sensorTs).contains("type: \"Sensor\";")
|
assertThat(sensorTs).contains("type: \"Sensor\";")
|
||||||
assertThat(sensorTs).contains("value: number;")
|
assertThat(sensorTs).contains("value: number;")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should generate string literal union for enums`() {
|
||||||
|
val result = renderer.enumToTs(DeviceStatus::class)
|
||||||
|
|
||||||
|
assertThat(result).isEqualTo("export type DeviceStatus = \"ONLINE\" | \"OFFLINE\"\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should handle classes with no unique properties gracefully`() {
|
||||||
|
open class Base(val id: String)
|
||||||
|
data class EmptySub(val type: String = "EmptySub") : Base("123")
|
||||||
|
|
||||||
|
val result = renderer.dataClassToTs(EmptySub::class, ttm, true)
|
||||||
|
|
||||||
|
assertThat(result).contains("export interface EmptySub extends Base")
|
||||||
|
assertThat(result).contains("type: \"EmptySub\";")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should map list of complex objects correctly`() {
|
||||||
|
data class SubItem(val code: String)
|
||||||
|
data class Container(val items: List<SubItem>)
|
||||||
|
|
||||||
|
val result = renderer.dataClassToTs(Container::class, ttm, false)
|
||||||
|
|
||||||
|
assertThat(result).contains("items: SubItem[];")
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `should correctly inherit properties from parent data class`() {
|
||||||
|
open class Parent(val id: String, val createdAt: String)
|
||||||
|
data class Child(val name: String, val age: Int) : Parent("default-id", "now")
|
||||||
|
|
||||||
|
val result = renderer.dataClassToTs(Child::class, ttm, false)
|
||||||
|
|
||||||
|
assertThat(result).contains("extends Parent")
|
||||||
|
assertThat(result).contains("name: string;")
|
||||||
|
assertThat(result).contains("age: number;")
|
||||||
|
// Felt fra Parent skal være filtrert bort fra Child-interfacet
|
||||||
|
assertThat(result).doesNotContain("id: string;")
|
||||||
|
assertThat(result).doesNotContain("createdAt: string;")
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `sealed subtype test - no type when off`() {
|
fun `sealed subtype test - no type when off`() {
|
||||||
data class Sensor(val type: String = "TEMP_SENSOR", val value: Double)
|
data class Sensor(val type: String = "TEMP_SENSOR", val value: Double)
|
||||||
|
|
||||||
// Send med true for å inkludere type-diskriminatoren i testen
|
// Tester med false for å verifisere at type-lappen utelates
|
||||||
val sensorTs = renderer.sealedSubtypeToTs(Sensor::class, ttm, includeTypeDiscriminator = false)
|
val sensorTs = renderer.dataClassToTs(Sensor::class, ttm, includeTypedInterface = false)
|
||||||
|
|
||||||
assertThat(sensorTs).doesNotContain("type: \"Sensor\";")
|
assertThat(sensorTs).doesNotContain("type: \"Sensor\";")
|
||||||
assertThat(sensorTs).contains("value: number;")
|
assertThat(sensorTs).contains("value: number;")
|
||||||
@@ -70,12 +124,10 @@ class TsModelRendererTest {
|
|||||||
assertThat(result).contains("extends AParent")
|
assertThat(result).contains("extends AParent")
|
||||||
|
|
||||||
// 3. Verifiser at felt som finnes i AParent IKKE er duplisert i AChild
|
// 3. Verifiser at felt som finnes i AParent IKKE er duplisert i AChild
|
||||||
// Dette bekrefter at filtreringen mot superclass fungerer
|
|
||||||
assertThat(result).doesNotContain("macAdress: string;")
|
assertThat(result).doesNotContain("macAdress: string;")
|
||||||
assertThat(result).doesNotContain("interfaceName: string;")
|
assertThat(result).doesNotContain("interfaceName: string;")
|
||||||
|
|
||||||
// 4. Verifiser at unike felt for sub-klassen er med
|
// 4. Verifiser at unike felt for sub-klassen er med
|
||||||
// (Merk: ttm mapper List til string[] i din originale kode)
|
|
||||||
assertThat(result).contains("caps: string[];")
|
assertThat(result).contains("caps: string[];")
|
||||||
|
|
||||||
// 5. Sjekk at klassenavnet er riktig
|
// 5. Sjekk at klassenavnet er riktig
|
||||||
|
|||||||
Reference in new issue
Block a user