Skip to content

Conversation

esafak
Copy link

@esafak esafak commented Sep 10, 2025

This change modifies the KxsTsGenerator to accept a SerializersModule in its constructor. This module is then used to resolve contextual and polymorphic serializers during the TypeScript generation process.

The SerializerDescriptorsExtractor has been refactored to use the SerializersModule.dumpTo experimental API to collect all serializers from the module. This allows for a platform-independent way to handle complex serialization scenarios.

Closes #6

This change modifies the `KxsTsGenerator` to accept a `SerializersModule` in its constructor. This module is then used to resolve contextual and polymorphic serializers during the TypeScript generation process.

The `SerializerDescriptorsExtractor` has been refactored to use the `SerializersModule.dumpTo` experimental API to collect all serializers from the module. This allows for a platform-independent way to handle complex serialization scenarios.
@aSemy
Copy link
Contributor

aSemy commented Sep 11, 2025

Thanks for the PR! It's been a while since I've worked on this project so I'll have to dust off some cobwebs (both in my recollections and the project).


companion object {

fun default(serializersModule: SerializersModule) =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

serializersModule is unused here. How should it be used?

Comment on lines +56 to +59
test("Example4: expect contextual serializer to be extracted") {
val module = SerializersModule {
contextual(Example4.SomeType::class, Example4.SomeType.serializer())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test still passes if the custom contextual(...) is commented out.

Comment on lines +72 to +75
test("Example5: expect polymorphic serializer to be extracted") {
val module = SerializersModule {
polymorphic(Example5.Parent::class, Example5.SubClass::class, Example5.SubClass.serializer())
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This test still passes if the custom polymorphic(...) is commented out.

open val sourceCodeGenerator: TsSourceCodeGenerator = TsSourceCodeGenerator.Default(config),
open val serializersModule: SerializersModule = SerializersModule { },
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of SerializersModule { } please use EmptySerializersModule()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support SerializersModule, so by specifying serializers, the generated TypeScript can be controlled
2 participants