Skip to content

Commit 3438872

Browse files
authoredApr 4, 2022
Refine implementation (#14)
- workaround for json content polymorphic + test - fix element ID name extraction (handle other SerialDescriptors that have < > in them) - fix knit tests not running - fix generic test #11
1 parent 8c3491a commit 3438872

18 files changed

+480
-58
lines changed
 

‎README.md

+26-15
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
# Kotlinx Serialization TypeScript Generator
44

5-
Create TypeScript interfaces from Kotlinx Serialization classes.
5+
[Kotlinx Serialization TypeScript Generator](https://github.com/adamko-dev/kotlinx-serialization-typescript-generator)
6+
creates TypeScript interfaces from
7+
[Kotlinx Serialization](https://github.com/Kotlin/kotlinx.serialization/)
8+
classes.
69

710
```kotlin
811
@Serializable
@@ -39,23 +42,31 @@ The Kotlinx Serialization API should be used to generate TypeScript. The
3942
[`SerialDescriptor`s](https://kotlin.github.io/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization.descriptors/-serial-descriptor/index.html)
4043
are flexible and comprehensive enough to allow for accurate TypeScript code, without any deviation.
4144

45+
The aim is to create TypeScript interfaces that can accurately produce Kotlinx Serialization
46+
compatible JSON.
47+
48+
The Kotlinx Serialization API should be used to generate TypeScript. The
49+
[`SerialDescriptor`s](https://kotlin.github.io/kotlinx.serialization/kotlinx-serialization-core/kotlinx.serialization.descriptors/-serial-descriptor/index.html)
50+
are flexible and comprehensive enough to allow for accurate TypeScript code, without any deviation.
51+
4252
See [the docs](./docs) for working examples.
4353

4454
## Status
4555

4656
This is a proof-of-concept.
4757

48-
| | Status | Notes |
49-
|---------------------------------------|----------------------------------------------------------|:-------------------------------------------------------------------------------------------------|
50-
| Kotlin multiplatform || The codebase is multiplatform, but only JVM has been tested |
51-
| `@SerialName` | ✅/⚠ | The serial name is directly converted and might produce invalid TypeScript |
52-
| Basic classes |[example](./docs/basic-classes.md) | |
53-
| Nullable and default-value properties |[example](./docs/default-values.md) | |
54-
| Value classes |[example](./docs/value-classes.md) | |
55-
| Enums |[example](./docs/enums.md) | |
56-
| Lists |[example](./docs/lists.md) | |
57-
| Maps | ✅/⚠ [example](./docs/maps.md) | Maps with complex keys are converted to an ES6 Map, [see](./docs/maps.md#maps-with-complex-keys) |
58-
| Polymorphism - Sealed classes | ✅/⚠ [example](./docs/polymorphism.md#sealed-classes) | Nested sealed classes are ignored, [see](./docs/polymorphism.md#nested-sealed-classes) |
59-
| Polymorphism - Open classes |[example](./docs/abstract-classes.md) | Not implemented. Converted to `type MyClass = any` |
60-
| `@JsonClassDiscriminator` || Not implemented |
61-
| Edge cases - circular dependencies |[example](./docs/edgecases.md) | |
58+
| | Status | Notes |
59+
|---------------------------------------|-----------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------|
60+
| Kotlin multiplatform || The codebase is multiplatform, but only JVM has been tested |
61+
| `@SerialName` | ✅/⚠ | The serial name is directly converted and might produce invalid TypeScript |
62+
| Basic classes |[example](./docs/basic-classes.md) | |
63+
| Nullable and default-value properties |[example](./docs/default-values.md) | |
64+
| Value classes |[example](./docs/value-classes.md) | |
65+
| Enums |[example](./docs/enums.md) | |
66+
| Lists |[example](./docs/lists.md) | |
67+
| Maps | ✅/⚠ [example](./docs/maps.md) | Maps with complex keys are converted to an ES6 Map, [see documentation](./docs/maps.md#maps-with-complex-keys) |
68+
| Polymorphism - Sealed classes | ✅/⚠ [example](./docs/polymorphism.md#sealed-classes) | Nested sealed classes are ignored, [see documentation](./docs/polymorphism.md#nested-sealed-classes) |
69+
| Polymorphism - Open classes |[example](./docs/abstract-classes.md) | Not implemented. Converted to `type MyClass = any` |
70+
| `@JsonClassDiscriminator` || Not implemented |
71+
| JSON Content polymorphism |[example](./docs/polymorphism.md#json-content-polymorphism) | Not implemented. Converted to `type MyClass = any` |
72+
| Edge cases - circular dependencies |[example](./docs/edgecases.md) | |

‎docs/code/example/example-generics-01.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import dev.adamko.kxstsgen.*
88
import kotlinx.serialization.builtins.serializer
99

1010
@Serializable
11-
class Box<T>(
11+
class Box<T : Number>(
1212
val value: T,
1313
)
1414

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// This file was automatically generated from polymorphism.md by Knit tool. Do not edit.
2+
@file:Suppress("PackageDirectoryMismatch", "unused")
3+
package dev.adamko.kxstsgen.example.exampleJsonPolymorphic01
4+
5+
import kotlinx.serialization.*
6+
import dev.adamko.kxstsgen.*
7+
8+
import kotlinx.serialization.json.*
9+
10+
@Serializable
11+
abstract class Project {
12+
abstract val name: String
13+
}
14+
15+
@Serializable
16+
data class BasicProject(override val name: String) : Project()
17+
18+
@Serializable
19+
data class OwnedProject(override val name: String, val owner: String) : Project()
20+
21+
object ProjectSerializer : JsonContentPolymorphicSerializer<Project>(Project::class) {
22+
override fun selectDeserializer(element: JsonElement) = when {
23+
"owner" in element.jsonObject -> OwnedProject.serializer()
24+
else -> BasicProject.serializer()
25+
}
26+
}
27+
28+
fun main() {
29+
val tsGenerator = KxsTsGenerator()
30+
println(tsGenerator.generate(ProjectSerializer))
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// This file was automatically generated from lists.md by Knit tool. Do not edit.
2+
@file:Suppress("PackageDirectoryMismatch", "unused")
3+
package dev.adamko.kxstsgen.example.exampleListObjects01
4+
5+
import kotlinx.serialization.*
6+
import dev.adamko.kxstsgen.*
7+
8+
@Serializable
9+
data class Colour(
10+
val rgb: String
11+
)
12+
13+
@Serializable
14+
data class MyLists(
15+
val colours: List<Colour>,
16+
val colourGroups: Set<List<Colour>>,
17+
val colourGroupGroups: LinkedHashSet<List<List<Colour>>>,
18+
)
19+
20+
fun main() {
21+
val tsGenerator = KxsTsGenerator()
22+
println(tsGenerator.generate(MyLists.serializer()))
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// This file was automatically generated from lists.md by Knit tool. Do not edit.
2+
@file:Suppress("PackageDirectoryMismatch", "unused")
3+
package dev.adamko.kxstsgen.example.exampleListObjects02
4+
5+
import kotlinx.serialization.*
6+
import dev.adamko.kxstsgen.*
7+
8+
@Serializable
9+
data class Colour(
10+
val rgb: String
11+
)
12+
13+
@Serializable
14+
data class MyLists(
15+
val listOfMaps: List<Map<String, Int>>,
16+
val listOfColourMaps: List<Map<String, Colour>>,
17+
)
18+
19+
fun main() {
20+
val tsGenerator = KxsTsGenerator()
21+
println(tsGenerator.generate(MyLists.serializer()))
22+
}

‎docs/code/example/example-list-primitive-01.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import dev.adamko.kxstsgen.*
88
@Serializable
99
data class MyLists(
1010
val strings: List<String>,
11-
val ints: List<Int>,
12-
val longs: List<Long>,
11+
val ints: Set<Int>,
12+
val longs: Collection<Long>,
1313
)
1414

1515
fun main() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// This file was automatically generated from lists.md by Knit tool. Do not edit.
2+
@file:Suppress("PackageDirectoryMismatch", "unused")
3+
package dev.adamko.kxstsgen.example.exampleListPrimitive02
4+
5+
import kotlinx.serialization.*
6+
import dev.adamko.kxstsgen.*
7+
8+
@Serializable
9+
data class Colour(
10+
val rgb: String
11+
)
12+
13+
@Serializable
14+
data class MyLists(
15+
val colours: List<Colour>,
16+
val colourGroups: List<List<Colour>>,
17+
val colourGroupGroups: List<List<List<Colour>>>,
18+
)
19+
20+
fun main() {
21+
val tsGenerator = KxsTsGenerator()
22+
println(tsGenerator.generate(MyLists.serializer()))
23+
}

‎docs/code/example/example-map-primitive-03.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@ import kotlinx.serialization.*
66
import dev.adamko.kxstsgen.*
77

88
@Serializable
9-
data class Config(
10-
val properties: Map<String?, String?>
9+
class MapsWithLists(
10+
val mapOfLists: Map<String, List<String>>
1111
)
1212

1313
fun main() {
1414
val tsGenerator = KxsTsGenerator()
15-
println(tsGenerator.generate(Config.serializer()))
15+
println(tsGenerator.generate(MapsWithLists.serializer()))
1616
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// This file was automatically generated from maps.md by Knit tool. Do not edit.
2+
@file:Suppress("PackageDirectoryMismatch", "unused")
3+
package dev.adamko.kxstsgen.example.exampleMapPrimitive04
4+
5+
import kotlinx.serialization.*
6+
import dev.adamko.kxstsgen.*
7+
8+
@Serializable
9+
@JvmInline
10+
value class Data(val content: String)
11+
12+
@Serializable
13+
class MyDataClass(
14+
val mapOfLists: Map<String, Data>
15+
)
16+
17+
fun main() {
18+
val tsGenerator = KxsTsGenerator()
19+
println(tsGenerator.generate(MyDataClass.serializer()))
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// This file was automatically generated from maps.md by Knit tool. Do not edit.
2+
@file:Suppress("PackageDirectoryMismatch", "unused")
3+
package dev.adamko.kxstsgen.example.exampleMapPrimitive05
4+
5+
import kotlinx.serialization.*
6+
import dev.adamko.kxstsgen.*
7+
8+
@Serializable
9+
data class Config(
10+
val properties: Map<String?, String?>
11+
)
12+
13+
fun main() {
14+
val tsGenerator = KxsTsGenerator()
15+
println(tsGenerator.generate(Config.serializer()))
16+
}

‎docs/code/test/ListsTests.kt

+43
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,47 @@ class ListsTests {
2525
.normalize()
2626
)
2727
}
28+
29+
@Test
30+
fun testExampleListObjects01() {
31+
captureOutput("ExampleListObjects01") {
32+
dev.adamko.kxstsgen.example.exampleListObjects01.main()
33+
}.normalizeJoin()
34+
.shouldBe(
35+
// language=TypeScript
36+
"""
37+
|export interface MyLists {
38+
| colours: Colour[];
39+
| colourGroups: Colour[][];
40+
| colourGroupGroups: Colour[][][];
41+
|}
42+
|
43+
|export interface Colour {
44+
| rgb: string;
45+
|}
46+
""".trimMargin()
47+
.normalize()
48+
)
49+
}
50+
51+
@Test
52+
fun testExampleListObjects02() {
53+
captureOutput("ExampleListObjects02") {
54+
dev.adamko.kxstsgen.example.exampleListObjects02.main()
55+
}.normalizeJoin()
56+
.shouldBe(
57+
// language=TypeScript
58+
"""
59+
|export interface MyLists {
60+
| listOfMaps: { [key: string]: number }[];
61+
| listOfColourMaps: { [key: string]: Colour }[];
62+
|}
63+
|
64+
|export interface Colour {
65+
| rgb: string;
66+
|}
67+
""".trimMargin()
68+
.normalize()
69+
)
70+
}
2871
}

‎docs/code/test/MapsTests.kt

+34
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,40 @@ class MapsTests {
4949
fun testExampleMapPrimitive03() {
5050
captureOutput("ExampleMapPrimitive03") {
5151
dev.adamko.kxstsgen.example.exampleMapPrimitive03.main()
52+
}.normalizeJoin()
53+
.shouldBe(
54+
// language=TypeScript
55+
"""
56+
|export interface MapsWithLists {
57+
| mapOfLists: { [key: string]: string[] };
58+
|}
59+
""".trimMargin()
60+
.normalize()
61+
)
62+
}
63+
64+
@Test
65+
fun testExampleMapPrimitive04() {
66+
captureOutput("ExampleMapPrimitive04") {
67+
dev.adamko.kxstsgen.example.exampleMapPrimitive04.main()
68+
}.normalizeJoin()
69+
.shouldBe(
70+
// language=TypeScript
71+
"""
72+
|export interface MyDataClass {
73+
| mapOfLists: { [key: string]: Data };
74+
|}
75+
|
76+
|export type Data = string;
77+
""".trimMargin()
78+
.normalize()
79+
)
80+
}
81+
82+
@Test
83+
fun testExampleMapPrimitive05() {
84+
captureOutput("ExampleMapPrimitive05") {
85+
dev.adamko.kxstsgen.example.exampleMapPrimitive05.main()
5286
}.normalizeJoin()
5387
.shouldBe(
5488
// language=TypeScript

‎docs/code/test/PolymorphismTest.kt

+30
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,34 @@ class PolymorphismTest {
206206
.normalize()
207207
)
208208
}
209+
210+
@Test
211+
fun testExampleGenerics01() {
212+
captureOutput("ExampleGenerics01") {
213+
dev.adamko.kxstsgen.example.exampleGenerics01.main()
214+
}.normalizeJoin()
215+
.shouldBe(
216+
// language=TypeScript
217+
"""
218+
|export interface Box {
219+
| value: number;
220+
|}
221+
""".trimMargin()
222+
.normalize()
223+
)
224+
}
225+
226+
@Test
227+
fun testExampleJsonPolymorphic01() {
228+
captureOutput("ExampleJsonPolymorphic01") {
229+
dev.adamko.kxstsgen.example.exampleJsonPolymorphic01.main()
230+
}.normalizeJoin()
231+
.shouldBe(
232+
// language=TypeScript
233+
"""
234+
|export type Project = any;
235+
""".trimMargin()
236+
.normalize()
237+
)
238+
}
209239
}

‎docs/lists.md

+78-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
* [Introduction](#introduction)
88
* [Primitive lists](#primitive-lists)
9+
* [Lists of objects](#lists-of-objects)
10+
* [Lists of collections](#lists-of-collections)
911

1012
<!--- END -->
1113

@@ -19,12 +21,14 @@ import dev.adamko.kxstsgen.*
1921

2022
### Primitive lists
2123

24+
A collection will get converted to array.
25+
2226
```kotlin
2327
@Serializable
2428
data class MyLists(
2529
val strings: List<String>,
26-
val ints: List<Int>,
27-
val longs: List<Long>,
30+
val ints: Set<Int>,
31+
val longs: Collection<Long>,
2832
)
2933

3034
fun main() {
@@ -44,3 +48,75 @@ export interface MyLists {
4448
```
4549

4650
<!--- TEST -->
51+
52+
### Lists of objects
53+
54+
```kotlin
55+
@Serializable
56+
data class Colour(
57+
val rgb: String
58+
)
59+
60+
@Serializable
61+
data class MyLists(
62+
val colours: List<Colour>,
63+
val colourGroups: Set<List<Colour>>,
64+
val colourGroupGroups: LinkedHashSet<List<List<Colour>>>,
65+
)
66+
67+
fun main() {
68+
val tsGenerator = KxsTsGenerator()
69+
println(tsGenerator.generate(MyLists.serializer()))
70+
}
71+
```
72+
73+
> You can get the full code [here](./code/example/example-list-objects-01.kt).
74+
75+
```typescript
76+
export interface MyLists {
77+
colours: Colour[];
78+
colourGroups: Colour[][];
79+
colourGroupGroups: Colour[][][];
80+
}
81+
82+
export interface Colour {
83+
rgb: string;
84+
}
85+
```
86+
87+
<!--- TEST -->
88+
89+
### Lists of collections
90+
91+
```kotlin
92+
@Serializable
93+
data class Colour(
94+
val rgb: String
95+
)
96+
97+
@Serializable
98+
data class MyLists(
99+
val listOfMaps: List<Map<String, Int>>,
100+
val listOfColourMaps: List<Map<String, Colour>>,
101+
)
102+
103+
fun main() {
104+
val tsGenerator = KxsTsGenerator()
105+
println(tsGenerator.generate(MyLists.serializer()))
106+
}
107+
```
108+
109+
> You can get the full code [here](./code/example/example-list-objects-02.kt).
110+
111+
```typescript
112+
export interface MyLists {
113+
listOfMaps: { [key: string]: number }[];
114+
listOfColourMaps: { [key: string]: Colour }[];
115+
}
116+
117+
export interface Colour {
118+
rgb: string;
119+
}
120+
```
121+
122+
<!--- TEST -->

‎docs/maps.md

+57-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
* [Introduction](#introduction)
88
* [Primitive maps](#primitive-maps)
99
* [Enum keys](#enum-keys)
10+
* [Maps with Collections](#maps-with-collections)
11+
* [Maps with value classes](#maps-with-value-classes)
1012
* [Nullable keys and values](#nullable-keys-and-values)
1113
* [Maps with complex keys](#maps-with-complex-keys)
1214
* [ES6 Map](#es6-map)
@@ -82,6 +84,60 @@ export enum SettingKeys {
8284

8385
<!--- TEST -->
8486

87+
### Maps with Collections
88+
89+
```kotlin
90+
@Serializable
91+
class MapsWithLists(
92+
val mapOfLists: Map<String, List<String>>
93+
)
94+
95+
fun main() {
96+
val tsGenerator = KxsTsGenerator()
97+
println(tsGenerator.generate(MapsWithLists.serializer()))
98+
}
99+
```
100+
101+
> You can get the full code [here](./code/example/example-map-primitive-03.kt).
102+
103+
```typescript
104+
export interface MapsWithLists {
105+
mapOfLists: { [key: string]: string[] };
106+
}
107+
```
108+
109+
<!--- TEST -->
110+
111+
### Maps with value classes
112+
113+
```kotlin
114+
@Serializable
115+
@JvmInline
116+
value class Data(val content: String)
117+
118+
@Serializable
119+
class MyDataClass(
120+
val mapOfLists: Map<String, Data>
121+
)
122+
123+
fun main() {
124+
val tsGenerator = KxsTsGenerator()
125+
println(tsGenerator.generate(MyDataClass.serializer()))
126+
}
127+
```
128+
129+
> You can get the full code [here](./code/example/example-map-primitive-04.kt).
130+
131+
```typescript
132+
export interface MyDataClass {
133+
mapOfLists: { [key: string]: Data };
134+
}
135+
136+
export type Data = string;
137+
```
138+
139+
<!--- TEST -->
140+
85141
### Nullable keys and values
86142

87143
```kotlin
@@ -96,7 +152,7 @@ fun main() {
96152
}
97153
```
98154

99-
> You can get the full code [here](./code/example/example-map-primitive-03.kt).
155+
> You can get the full code [here](./code/example/example-map-primitive-05.kt).
100156
101157
```typescript
102158
export interface Config {

‎docs/polymorphism.md

+51-7
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
* [Objects](#objects)
1414
* [Open Polymorphism](#open-polymorphism)
1515
* [Generics](#generics)
16+
* [JSON content polymorphism](#json-content-polymorphism)
1617

1718
<!--- END -->
1819

@@ -346,13 +347,14 @@ export namespace Response {
346347

347348
### Generics
348349

349-
<!--- INCLUDE
350-
import kotlinx.serialization.builtins.serializer
351-
-->
350+
Kotlinx Serialization doesn't have 'generic' SerialDescriptors, so KxsTsGen can't generate generic
351+
TypeScript classes.
352352

353353
```kotlin
354+
import kotlinx.serialization.builtins.serializer
355+
354356
@Serializable
355-
class Box<T>(
357+
class Box<T : Number>(
356358
val value: T,
357359
)
358360

@@ -370,9 +372,51 @@ fun main() {
370372
> You can get the full code [here](./code/example/example-generics-01.kt).
371373
372374
```typescript
373-
export type Double = number & { __kotlin_Double__: void }
374-
375375
export interface Box {
376-
value: Double
376+
value: number;
377377
}
378378
```
379+
380+
<!--- TEST -->
381+
382+
### JSON content polymorphism
383+
384+
Using a
385+
[`JsonContentPolymorphicSerializer`](https://kotlin.github.io/kotlinx.serialization/kotlinx-serialization-json/kotlinx.serialization.json/-json-content-polymorphic-serializer/index.html)
386+
means there's not enough data in the `SerialDescriptor` to generate a TypeScript interface. Instead,
387+
a named type alias to 'any' will be created instead.
388+
389+
```kotlin
390+
import kotlinx.serialization.json.*
391+
392+
@Serializable
393+
abstract class Project {
394+
abstract val name: String
395+
}
396+
397+
@Serializable
398+
data class BasicProject(override val name: String) : Project()
399+
400+
@Serializable
401+
data class OwnedProject(override val name: String, val owner: String) : Project()
402+
403+
object ProjectSerializer : JsonContentPolymorphicSerializer<Project>(Project::class) {
404+
override fun selectDeserializer(element: JsonElement) = when {
405+
"owner" in element.jsonObject -> OwnedProject.serializer()
406+
else -> BasicProject.serializer()
407+
}
408+
}
409+
410+
fun main() {
411+
val tsGenerator = KxsTsGenerator()
412+
println(tsGenerator.generate(ProjectSerializer))
413+
}
414+
```
415+
416+
> You can get the full code [here](./code/example/example-json-polymorphic-01.kt).
417+
418+
```typescript
419+
export type Project = any;
420+
```
421+
422+
<!--- TEST -->

‎modules/kxs-ts-gen-core/src/commonMain/kotlin/dev.adamko.kxstsgen/TsElementConverter.kt

+7
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,13 @@ fun interface TsElementConverter {
6767
descriptor: SerialDescriptor,
6868
): TsDeclaration {
6969

70+
if (descriptor.elementsCount == 0) {
71+
return TsDeclaration.TsTypeAlias(
72+
elementIdConverter(descriptor),
73+
TsTypeRef.Literal(TsLiteral.Primitive.TsAny, false)
74+
)
75+
}
76+
7077
val discriminatorIndex = descriptor.elementDescriptors
7178
.indexOfFirst { it.kind == PrimitiveKind.STRING }
7279
val discriminatorName = descriptor.getElementName(discriminatorIndex)
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
package dev.adamko.kxstsgen
22

3-
import kotlinx.serialization.descriptors.PolymorphicKind
4-
import kotlinx.serialization.descriptors.PrimitiveKind
53
import kotlinx.serialization.descriptors.SerialDescriptor
6-
import kotlinx.serialization.descriptors.SerialKind
7-
import kotlinx.serialization.descriptors.StructureKind
84

95

106
fun interface TsElementIdConverter {
@@ -13,30 +9,20 @@ fun interface TsElementIdConverter {
139

1410
object Default : TsElementIdConverter {
1511
override operator fun invoke(descriptor: SerialDescriptor): TsElementId {
16-
val targetId = TsElementId(descriptor.serialName.removeSuffix("?"))
17-
18-
return when (descriptor.kind) {
19-
PolymorphicKind.OPEN -> TsElementId(
20-
targetId.namespace + "." + targetId.name.substringAfter("<").substringBeforeLast(">")
21-
)
22-
PolymorphicKind.SEALED,
23-
PrimitiveKind.BOOLEAN,
24-
PrimitiveKind.BYTE,
25-
PrimitiveKind.CHAR,
26-
PrimitiveKind.DOUBLE,
27-
PrimitiveKind.FLOAT,
28-
PrimitiveKind.INT,
29-
PrimitiveKind.LONG,
30-
PrimitiveKind.SHORT,
31-
PrimitiveKind.STRING,
32-
SerialKind.CONTEXTUAL,
33-
SerialKind.ENUM,
34-
StructureKind.CLASS,
35-
StructureKind.LIST,
36-
StructureKind.MAP,
37-
StructureKind.OBJECT -> targetId
12+
13+
val serialName = descriptor.serialName.removeSuffix("?")
14+
15+
val namespace = serialName.substringBeforeLast('.')
16+
17+
val id = serialName
18+
.substringAfterLast('.')
19+
.substringAfter("<")
20+
.substringBeforeLast(">")
21+
22+
return when {
23+
namespace.isBlank() -> TsElementId("$id")
24+
else -> TsElementId("$namespace.$id")
3825
}
3926
}
40-
4127
}
4228
}

0 commit comments

Comments
 (0)
Please sign in to comment.