Skip to content

Kotlin Compiler

The Kotlin compiler lets you generate type-safe clients and DTOs for Android and JVM projects out of the same Emi definitions used by every other target. As with the other compilers, the generated Kotlin stays in sync with your backend because it comes from one shared source of truth.

Terminal window
emi kotlin --path module.yaml --output ./src/main/kotlin/generated

Without --output, the generated virtual files are printed (as JSON) to the terminal so you can inspect them before writing them to disk.

CommandDescription
emi kotlinCompiles the entire Kotlin module (actions, DTOs, headers).
emi kotlin:dtoGenerates only the Kotlin DTO objects.
emi kotlin:headersGenerates the headers, usable in both client and server code.
FlagDescription
—pathPath of the Emi definition file (.yaml or .json) on disk.
—outputDirectory the generated Kotlin files are written to. Omit it to print to stdout.
—tagsComma separated compile features to add or remove.

For the postsModule from the OpenAPI page, emi kotlin generates a GetSinglePostAction.kt for the action plus a shared common.kt containing the reusable building blocks (headers, helpers) referenced by the actions.