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.
Compiling a module
Section titled “Compiling a module”emi kotlin --path module.yaml --output ./src/main/kotlin/generatedWithout --output, the generated virtual files are printed (as JSON) to the terminal so you can inspect them before
writing them to disk.
Sub commands
Section titled “Sub commands”| Command | Description |
|---|---|
emi kotlin | Compiles the entire Kotlin module (actions, DTOs, headers). |
emi kotlin:dto | Generates only the Kotlin DTO objects. |
emi kotlin:headers | Generates the headers, usable in both client and server code. |
Options
Section titled “Options”| Flag | Description |
|---|---|
—path | Path of the Emi definition file (.yaml or .json) on disk. |
—output | Directory the generated Kotlin files are written to. Omit it to print to stdout. |
—tags | Comma separated compile features to add or remove. |
Example
Section titled “Example”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.