Generate a Swift SDK for your API
Octri generates a Swift package for your API with async/await methods and Codable models, pushes it to your repository with a semver tag for Swift Package Manager, and regenerates it whenever your API changes.
Or upload a file: OpenAPI 3.0 or 3.1, Swagger 2.0, Postman or AsyncAPI.
dependencies: [
.package(url: "https://github.com/acme/acme-swift", from: "1.0.0")
]The Swift API client your users get
What your users write once the Swift package is installed.
Two call styles come out of the same generator. class-namespaced is the default: one client object with operations grouped by resource, the shape most popular SDKs use and the one your API reference already shows. functions is the alternative: no client object, one configure call, and each operation imported on its own. It is one setting per language, and nothing else about the client changes with it.
Every operation is async throws with labeled arguments, and optional ones default to nil, so a call from SwiftUI’s .task modifier is a single line.
Swift Package Manager resolves straight from a repository, so there is no registry account to connect. Octri pushes the generated package and a semver tag, and Xcode picks it up under File, Add Package Dependencies.
import AcmeApi
let acme = Acme(config: ClientConfig(
baseUrl: "https://api.acme.com/v1",
auth: ClientAuthConfig(bearer: token)
))
// listPaginated returns an AsyncThrowingStream. Pages load as you iterate.
for try await user in acme.users.listPaginated(limit: 100) {
print(user.id)
}
let invoice = try await acme.invoices.create(customerId: "cus_123", amountCents: 4900)import AcmeApi
configureClient(ClientConfig(
baseUrl: "https://api.acme.com/v1",
auth: ClientAuthConfig(bearer: token)
))
for try await user in listUsersPaginated(limit: 100) {
print(user.id)
}The Swift SDK at a glance
What a developer checks before adding the Swift package to a project.
- Runs on
- iOS 15, macOS 12, tvOS 15, watchOS 8; Swift 5.9 tools
- Transport
- URLSession, with FoundationNetworking on Linux
- Runtime dependencies
- None
- Models
- Codable structs
- Pagination
- AsyncThrowingStream, consumed with for try await
- Ships to
- Your repository, as a semver tag for SwiftPM
When a call fails
SdkHttpError carries a kind enum for the statuses apps branch on most, so a catch ... where clause or a switch handles them without comparing integers. A declared error model is decoded onto error.data.
do {
let invoice = try await acme.invoices.create(customerId: "cus_123", amountCents: 4900)
} catch let error as SdkHttpError where error.kind == .rateLimit {
// 429 after the built-in retries. Offer a retry in the UI.
} catch let error as SdkHttpError {
logger.error("acme failed: \(error.statusCode) request \(error.requestId)")
}Configure your Swift SDK
Swift has no engine setting: URLSession is the transport an Apple-platform consumer expects, and it brings no third-party package into their app.
Client style
class-namespaced (default), class, namespaced, functionsA client class with a lazily built property per resource. Functions are module-level and read a global configuration, which suits a small app with one API.
Argument style
positional (default), objectLabeled arguments, the Swift call-site convention, with optional ones defaulting to nil. Object collects them into a request struct.
Doc comments
full (default), minimalFull writes Swift doc comments that Xcode shows in Quick Help and DocC can build into a reference.
Method naming and namespacing work the same in every language: operations are grouped by your API’s tags or by path, and the namespace word is dropped from the method name unless you ask to keep the operationId whole.
Swift Package Manager: the repository URL is the dependency
There is no registry in between: your users’ Package.swift and Xcode projects name your repository directly. Rename or move it and every consumer’s package resolution breaks, including apps that pinned it. SwiftPM also reads only semver tags, so a pushed commit without a tag is invisible to from: "1.0.0". Pick the repository name once.
github.com/ acme/ acme-swift- Not possible: Move or rename the repository
- Not possible: Resolve an untagged commit
- Still possible: Release with a semver tag
Retries, pagination and typed errors, built in
The parts nobody wants to hand-write, and the parts a hand-written client usually skips.
- Retries with exponential backoff and jitter, on the statuses that mean "try again", with a per-attempt timeout.
- Idempotency keys on the methods that need them, so a retried write does not become two.
- Auth wired in from your API’s security schemes, read from wherever your users keep secrets.
- Typed errors split by cause: a failed constraint, an HTTP status, a network failure and a timeout are four different things.
- Pagination that follows whichever style your API uses, cursor, offset, page number or next URL, without prefetching the collection.
- Server-sent events as a native stream, for the operations that stream.
- Error reporting to Octri’s monitoring, pre-wired and switched off until a consumer opts in.
Add your API
Upload an OpenAPI or Swagger file, paste a URL, connect the repository it lives in, or add endpoints in the editor.
Read the audit
Octri scores your API out of 10 on what a generator can do with it and names every missing schema and clashing operationId. 8 of the 14 rules come with a button that writes the fix.
Shape the client
Client style, argument style, namespacing, auth, retries and pagination, set once for the project and overridden per language or per endpoint.
Generate and read it
The package is generated, compiled and handed to you as source you can read before anyone installs it.
Publish, then keep publishing
Release to the registry under your own account. Every later change to your API regenerates the client, and the version number follows the version your API declares.
SDK generators for nine more languages
The same API in nine more languages, generated with the same settings at the same time.
Swift SDK generator questions
Apple’s Swift OpenAPI Generator runs as a package plugin or CLI in your own build, reads OpenAPI 3.0 and 3.1, and needs a separate transport package such as its URLSession one. OpenAPI Generator’s Swift client defaults to URLSession, with Alamofire as an option. Octri generates a finished package with no dependencies, tags it in your repository for Swift Package Manager, and regenerates it when your API changes.