generate api
Generate a typed API client from an OpenAPI 3.0+ spec.
Generates a typed Swift API client from an OpenAPI 3.0+ specification using Apple’s swift-openapi-generator.
Synopsis
Section titled “Synopsis”swiftspawn generate api --from <path-or-url> [--name <ClientName>] [--dry-run] [--force] [--quiet] [--verbose]Description
Section titled “Description”Wires swift-openapi-generator, swift-openapi-runtime, and swift-openapi-urlsession into Package.swift between the auto-managed markers, copies the spec into the project, writes the generator config, and scaffolds a wrapper service.
The wrapper translates OpenAPI errors into AppError, so calling code never has to know the underlying generator’s error types.
The client name defaults to the spec’s info.title, slugified to PascalCase. Override with --name.
Examples
Section titled “Examples”swiftspawn generate api --from openapi.yamlswiftspawn generate api --from https://api.example.com/openapi.yaml --name TMDBGenerated files
Section titled “Generated files”Sources/<ClientName>/openapi.yamlSources/<ClientName>/openapi-generator-config.yamlServices/<ClientName>Service.swift # wrapper around the generated clientSide effects
Section titled “Side effects”- Adds
swift-openapi-generator,swift-openapi-runtime, andswift-openapi-urlsessiontoPackage.swift’s dependencies between the auto-managed markers. - Adds the generator plugin to the target.
Options
Section titled “Options”| Flag | Description |
|---|---|
--from <path-or-url> | Path or URL to an OpenAPI 3.0+ spec (YAML or JSON). |
--name <ClientName> | Override the client name. Defaults to info.title from the spec. |
--dry-run | Preview without writing. |
--force | Overwrite existing files. |
Exit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
| 5 | Not in a swiftspawn project. |
| 9 | Spec file not found. |
| 10 | Failed to fetch URL. |
| 15 | Malformed OpenAPI spec. |
| 16 | Package.swift is missing the markers. |
See also
Section titled “See also”generate servicefor non-OpenAPI services.- Markers