A Swift package plugin generates Swift types and HTTP ceremony from OpenAPI documents, keeping generated code in sync at build time.
Overview
Swift OpenAPI Generator reads OpenAPI descriptions in YAML or JSON and emits Swift code for HTTP clients or server stubs. Generation runs as a Swift package plugin at build time so outputs stay aligned with the spec without committing generated sources.
It targets OpenAPI 3.0 and 3.1 with preliminary 3.2 support. Features include streaming bodies, typed encodings for JSON, multipart, forms, and raw bytes, and abstractions that separate generated code from the HTTP client or web framework via ClientTransport and ServerTransport.
Client code exposes one method per operation and works with any library that implements ClientTransport, such as URLSession or AsyncHTTPClient. Servers implement the generated APIProtocol and register handlers through a ServerTransport compatible with Vapor, Hummingbird, or AWS Lambda adapters in the ecosystem.
The generator plugin and CLI run on macOS, Linux, and Windows during development; generated runtime code targets additional Apple and Android platforms. Configuration uses an openapi-generator-config.yaml file beside the spec.
Key features
- OpenAPI 3.0, 3.1, and preliminary 3.2
- Client and server stub generation
- Build-time Swift package plugin
- Streaming request and response bodies
- ClientTransport and ServerTransport abstractions
- JSON, multipart, and form payload types
- Separate runtime and transport packages
- YAML generator configuration file
Use cases
- Typed Swift API clients from OpenAPI
- Server handlers matching a published spec
- Spec-driven HTTP services in Swift
- Integrating OpenAPI with Vapor or URLSession