openapi-generator-cli generate: Build API Clients in CI
openapi-generator-cli generate turns an OpenAPI spec into client or server code: -i is the input spec, -g the generator (language), and -o the output dir.
OpenAPI Generator scaffolds typed clients in dozens of languages from a spec. In CI it keeps SDKs in sync with the API contract automatically.
What it does
openapi-generator-cli generate reads the OpenAPI document at -i, selects a generator with -g (for example typescript-axios, go, python, java), and writes the generated client/server into -o. Generator-specific knobs go through --additional-properties or a -c config file.
Common usage
# via npm wrapper
npx @openapitools/openapi-generator-cli generate \
-i openapi.yaml \
-g typescript-axios \
-o sdk/ts \
--additional-properties=supportsES6=true
# validate before generating
npx @openapitools/openapi-generator-cli validate -i openapi.yamlFlags and options
| Flag | What it does |
|---|---|
| -i, --input-spec <file/url> | OpenAPI spec to generate from |
| -g, --generator-name <name> | Target generator (language/framework) |
| -o, --output <dir> | Output directory for generated code |
| --additional-properties=k=v | Generator-specific options (comma-separated) |
| -c, --config <file> | Config file with generator options |
| --skip-validate-spec | Generate even if the spec fails validation |
| validate -i <file> | Validate a spec without generating |
In CI
Pin the generator version (the npm wrapper records it in openapitools.json) so output is reproducible across runs. Run validate first so spec problems fail fast with a clear message. Generate into a clean dir and git diff to detect drift between the spec and committed SDKs.
Common errors in CI
"[main] ERROR ... Can't load config ... Unknown option: -g" or "Unsupported "generator-name": <x>" means a bad -g value; run list to see valid names. "The spec file is not valid" comes from a malformed spec; fix it or use --skip-validate-spec knowingly. "Could not resolve reference ... $ref" means a broken $ref. On large specs, "java.lang.OutOfMemoryError: Java heap space" needs more heap via JAVA_OPTS=-Xmx2g.