Swift OpenAPI Generator is an Apple-maintained Swift package plugin that automates the generation of Swift client and server code from OpenAPI documents. The tool reads OpenAPI specifications written in YAML or JSON and generates the necessary ceremony code to make API calls or implement API servers, eliminating the need to manually write boilerplate HTTP handling code. Code generation occurs at build-time, ensuring the generated code remains synchronized with the OpenAPI document without requiring commits to the source repository.
The generator supports OpenAPI Specification versions 3.0 and 3.1, with preliminary support for version 3.2. It provides comprehensive support for multiple content types including JSON, multipart, URL-encoded form, base64, plain text, and raw bytes, all represented as type-safe value types with strongly-typed properties. A notable feature is support for streaming request and response bodies, enabling use cases such as JSON event streams and handling large payloads without buffering them entirely in memory. The architecture employs client, server, and middleware abstractions that decouple generated code from specific HTTP client libraries and web frameworks, providing flexibility in implementation choices.
The project is structured across multiple repositories to enable extensibility and minimize dependencies. The core generator repository contains the Swift package plugin and command-line interface. The ecosystem includes a runtime library used by generated code, transport implementations for various HTTP clients and frameworks such as URLSession, AsyncHTTPClient, OkHttp, Vapor, Hummingbird, and AWS Lambda, allowing developers to choose their preferred networking and server solutions.
The repository shares contributors with microsoft/vscode, swiftlang/swift, and microsoft/typescript, indicating cross-ecosystem involvement.
Platform support is extensive for generated code and runtime components, covering macOS 10.15 and later, Linux, Windows, iOS 13 and later, tvOS 13 and later, watchOS 6 and later, visionOS 1 and later, and Android. The generator plugin itself runs on macOS, Linux, and Windows during development. The project provides comprehensive documentation including step-by-step tutorials and example projects demonstrating integration with other ecosystem packages. A WWDC23 presentation titled "Meet Swift OpenAPI Generator" offers video-based introduction to the tool's capabilities and usage patterns.