Swift Compiler
Emi ships with a Swift compiler, so the same definitions that drive your Go backend and JavaScript front end can also
power native iOS and macOS clients. The generated Swift is plain Foundation based code (it falls back to
FoundationNetworking on Linux), so it does not pull in any third party dependency.
The Swift compiler generates type-safe request/response objects and an action wrapper per action, mirroring the behaviour of the other Emi compilers.
Compiling a module
Section titled “Compiling a module”emi swift --path module.yaml --output ./Sources/GeneratedWithout --output, the generated virtual files are printed (as JSON) to the terminal so you can inspect them before
writing anything to disk.
Sub commands
Section titled “Sub commands”The full Swift compiler (emi swift) generates everything for a module. If you only need a slice of the output, two
focused sub commands are available:
| Command | Description |
|---|---|
emi swift | Compiles the entire Swift module (actions, DTOs, headers). |
emi swift:dto | Generates only the Swift DTO objects. |
emi swift: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 Swift 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 swift generates an
GetSinglePostAction.swift file that starts like this:
import Foundation#if canImport(FoundationNetworking)import FoundationNetworking#endif/** Action to communicate with the action GetSinglePostAction */struct GetSinglePostActionMeta { let name: String = "GetSinglePostAction" let url: String = "/posts/:id" let method: String = "Get"}
struct GetSinglePostActionResponse { let statusCode: Int let headers: [String: String] let payload: Data? // ...}Each action carries its metadata (name, URL, method) and a strongly typed response, so the calling code never has to hardcode routes or guess the response shape.