Skip to content

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.

Terminal window
swiftspawn generate api --from <path-or-url> [--name <ClientName>] [--dry-run] [--force] [--quiet] [--verbose]

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.

Terminal window
swiftspawn generate api --from openapi.yaml
swiftspawn generate api --from https://api.example.com/openapi.yaml --name TMDB
Sources/<ClientName>/openapi.yaml
Sources/<ClientName>/openapi-generator-config.yaml
Services/<ClientName>Service.swift # wrapper around the generated client
  • Adds swift-openapi-generator, swift-openapi-runtime, and swift-openapi-urlsession to Package.swift’s dependencies between the auto-managed markers.
  • Adds the generator plugin to the target.
FlagDescription
--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-runPreview without writing.
--forceOverwrite existing files.
CodeMeaning
5Not in a swiftspawn project.
9Spec file not found.
10Failed to fetch URL.
15Malformed OpenAPI spec.
16Package.swift is missing the markers.