Skip to content
Latchkey

openapi-generator-cli generate: Clients and Servers

openapi-generator-cli generate reads an OpenAPI spec and emits a client, server stub, or model set for a chosen generator (language/framework).

OpenAPI Generator turns your spec into typed SDKs and server stubs across dozens of languages. In CI it is used to regenerate committed clients and fail when the spec drifts from the code.

What it does

The generate command loads the input spec (-i), selects a generator (-g, e.g. typescript-axios, java, python, go), and writes the output tree to -o. Behavior per generator is tuned with --additional-properties.

Common usage

Terminal
openapi-generator-cli generate \
  -i openapi.yaml -g typescript-axios -o src/api
# pass generator options and skip spec validation warnings-as-errors off
openapi-generator-cli generate -i openapi.yaml -g go \
  -o pkg/client \
  --additional-properties=packageName=client,withGoMod=false

Options

FlagWhat it does
-i, --input-spec <path>Input OpenAPI file or URL
-g, --generator-name <name>Target generator (language/framework)
-o, --output <dir>Output directory
-p, --additional-properties <k=v>Generator-specific options, comma separated
--skip-validate-specDo not validate the spec before generating
-c, --config <file>JSON/YAML file of generator options
--global-property <k=v>Limit what is generated (e.g. models, apis)

In CI

Regenerate into a temp dir, then git diff --exit-code (or copy over the committed dir and diff) to fail the build when the checked-in client is stale. Pin the generator version via openapi-generator-cli version-manager set so codegen output is reproducible across runners.

Common errors in CI

"The spec file is not valid. The following problems were found: ..." with a list of schema errors means the input fails validation; fix the spec or (rarely) add --skip-validate-spec. "Can't load config file" points at a bad -c path. "generator ... not found" means a typo in -g (list valid names with openapi-generator-cli list). A NullPointerException deep in the stack usually means an unsupported construct for that specific generator.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →