-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* allow for overriding of elements (partial support for #23 and #22), and update knit to allow for TS Compile to be disabled * make TsMapTypeConverter more clear, split inline/non-inline * code tidy * fix bug where overrides weren't consistently found and applied if the target was nullable
- Loading branch information
Showing
10 changed files
with
496 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// This file was automatically generated from customising-output.md by Knit tool. Do not edit. | ||
@file:Suppress("PackageDirectoryMismatch", "unused") | ||
package dev.adamko.kxstsgen.example.exampleCustomisingOutput01 | ||
|
||
import kotlinx.serialization.* | ||
import dev.adamko.kxstsgen.* | ||
|
||
import kotlinx.serialization.builtins.serializer | ||
import dev.adamko.kxstsgen.core.* | ||
|
||
@Serializable | ||
data class Item( | ||
val price: Double, | ||
val count: Int, | ||
) | ||
|
||
fun main() { | ||
val tsGenerator = KxsTsGenerator() | ||
|
||
tsGenerator.descriptorOverrides += | ||
Double.serializer().descriptor to TsDeclaration.TsTypeAlias( | ||
id = TsElementId("Double"), | ||
typeRef = TsTypeRef.Declaration( | ||
id = TsElementId("double"), | ||
parent = null, | ||
nullable = false, | ||
) | ||
) | ||
|
||
println(tsGenerator.generate(Item.serializer())) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// This file was automatically generated from customising-output.md by Knit tool. Do not edit. | ||
@file:Suppress("PackageDirectoryMismatch", "unused") | ||
package dev.adamko.kxstsgen.example.exampleCustomisingOutput02 | ||
|
||
import kotlinx.serialization.* | ||
import dev.adamko.kxstsgen.* | ||
|
||
import kotlinx.serialization.builtins.serializer | ||
import dev.adamko.kxstsgen.core.* | ||
|
||
@Serializable | ||
data class ItemHolder( | ||
val item: Item, | ||
) | ||
|
||
@Serializable | ||
data class Item( | ||
val count: UInt? = 0u, | ||
) | ||
|
||
fun main() { | ||
val tsGenerator = KxsTsGenerator() | ||
|
||
tsGenerator.descriptorOverrides += | ||
UInt.serializer().descriptor to TsDeclaration.TsTypeAlias( | ||
id = TsElementId("kotlin.UInt"), | ||
typeRef = TsTypeRef.Declaration(id = TsElementId("uint"), parent = null, nullable = false) | ||
) | ||
|
||
println(tsGenerator.generate(ItemHolder.serializer())) | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
// This file was automatically generated from customising-output.md by Knit tool. Do not edit. | ||
@file:Suppress("PackageDirectoryMismatch", "unused") | ||
package dev.adamko.kxstsgen.example.exampleCustomisingOutput03 | ||
|
||
import kotlinx.serialization.* | ||
import dev.adamko.kxstsgen.* | ||
|
||
import kotlinx.serialization.builtins.serializer | ||
import dev.adamko.kxstsgen.core.* | ||
|
||
|
||
@Serializable | ||
@JvmInline | ||
value class Tick(val value: UInt) | ||
|
||
@Serializable | ||
data class ItemHolder( | ||
val item: Item, | ||
val tick: Tick?, | ||
) | ||
|
||
@Serializable | ||
data class Item( | ||
val count: UInt? = 0u, | ||
) | ||
|
||
fun main() { | ||
val tsGenerator = KxsTsGenerator() | ||
|
||
tsGenerator.descriptorOverrides += | ||
UInt.serializer().descriptor to TsDeclaration.TsTypeAlias( | ||
id = TsElementId("kotlin.UInt"), | ||
typeRef = TsTypeRef.Declaration(id = TsElementId("uint"), parent = null, nullable = false) | ||
) | ||
|
||
println(tsGenerator.generate(ItemHolder.serializer())) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// This file was automatically generated from customising-output.md by Knit tool. Do not edit. | ||
@file:Suppress("JSUnusedLocalSymbols") | ||
package dev.adamko.kxstsgen.example.test | ||
|
||
import dev.adamko.kxstsgen.util.* | ||
import io.kotest.core.spec.style.* | ||
import io.kotest.matchers.* | ||
import kotlinx.knit.test.* | ||
|
||
class CustomisingOutputTest : FunSpec({ | ||
|
||
tags(Knit) | ||
|
||
context("ExampleCustomisingOutput01") { | ||
val actual = captureOutput("ExampleCustomisingOutput01") { | ||
dev.adamko.kxstsgen.example.exampleCustomisingOutput01.main() | ||
}.normalizeJoin() | ||
|
||
test("expect actual matches TypeScript") { | ||
actual.shouldBe( | ||
""" | ||
|export interface Item { | ||
| price: Double; | ||
| count: number; | ||
|} | ||
| | ||
|export type Double = double; // assume that 'double' will be provided by another library | ||
""".trimMargin() | ||
.normalize() | ||
) | ||
} | ||
|
||
// TS_COMPILE_OFF | ||
// test("expect actual compiles").config(tags = tsCompile) { | ||
// actual.shouldTypeScriptCompile() | ||
// } | ||
} | ||
|
||
context("ExampleCustomisingOutput02") { | ||
val actual = captureOutput("ExampleCustomisingOutput02") { | ||
dev.adamko.kxstsgen.example.exampleCustomisingOutput02.main() | ||
}.normalizeJoin() | ||
|
||
test("expect actual matches TypeScript") { | ||
actual.shouldBe( | ||
""" | ||
|export interface ItemHolder { | ||
| item: Item; | ||
|} | ||
| | ||
|export interface Item { | ||
| count?: UInt | null; | ||
|} | ||
| | ||
|export type UInt = uint; | ||
""".trimMargin() | ||
.normalize() | ||
) | ||
} | ||
|
||
// TS_COMPILE_OFF | ||
// test("expect actual compiles").config(tags = tsCompile) { | ||
// actual.shouldTypeScriptCompile() | ||
// } | ||
} | ||
|
||
context("ExampleCustomisingOutput03") { | ||
val actual = captureOutput("ExampleCustomisingOutput03") { | ||
dev.adamko.kxstsgen.example.exampleCustomisingOutput03.main() | ||
}.normalizeJoin() | ||
|
||
test("expect actual matches TypeScript") { | ||
actual.shouldBe( | ||
""" | ||
|export interface ItemHolder { | ||
| item: Item; | ||
| tick: Tick | null; | ||
|} | ||
| | ||
|export interface Item { | ||
| count?: UInt | null; | ||
|} | ||
| | ||
|export type Tick = UInt; | ||
| | ||
|export type UInt = uint; | ||
""".trimMargin() | ||
.normalize() | ||
) | ||
} | ||
|
||
// TS_COMPILE_OFF | ||
// test("expect actual compiles").config(tags = tsCompile) { | ||
// actual.shouldTypeScriptCompile() | ||
// } | ||
} | ||
}) |
Oops, something went wrong.