Martok is built for one thing and one thing only: converting Typescript schemas into kotlinx.serialization schemas. It's the brutal and chaotic rival to Dukat.
We've always been big believers in Kotlin Multiplatform for Mobile -- but also recognize the (well-earned) dominance of Node on the backend. Martok creates an automated schema pipeline from the Typescript in your backend codebase to the Kotlin data layer in your Android & iOS apps.
QuickType has gotten quite old and difficult to develop. The PRs have mostly stagnated, we currently cannot find a way to successfully build the project, so we've moved on.
Sure! For a quick example:
export type Unions = {
foo: { bar: string } | { baz: string };
};
Would translate to
@Serializable
data class Unions(
val foo: Foo
) {
@Serializable
data class Foo(
val bar: String? = null,
val baz: String? = null
)
}
Or this one:
export type AnonList = {
foo: {
bar: string;
baz: "one" | "two";
}[];
};
...which would translate to:
@Serializable
data class AnonList(
val foo: List<FooItem>
) {
@Serializable
data class FooItem(
val bar: String,
val baz: Baz
) {
@Serializable
enum class Baz(
val serialName: String
) {
@SerialName("one") ONE("one"),
@SerialName("two") TWO("two");
}
}
}
For more examples, check out the comparison files we use for our automated tests HERE.
npm install -g martok
# Martok works with single files, directories, and always infers the right thing to do.
martok ./someFile.d.ts -o Schema.kt --package example
martok ./someDirectory -o BigSchema.kt
martok ./someDirectory -o ./outputDirectory # produce lots of little files.
@Date
or @DateTime
. See HERE for examples)Omit
and Pick
)@precision
jsdoc tag.d.ts
files. Work on safer execution for .ts