Skip to content
Latchkey

swagger-codegen generate: Clients from Swagger/OpenAPI

swagger-codegen generate produces client SDKs and server stubs from a Swagger 2.0 or OpenAPI 3.0 document.

swagger-codegen is the SmartBear-maintained generator that OpenAPI Generator forked from. Many older pipelines still call it directly; the flag names differ slightly (-l vs -g).

What it does

The generate command reads a spec (-i), picks a language/framework (-l), and writes generated code to -o. Per-generator options come from a JSON config passed with -c.

Common usage

Terminal
swagger-codegen generate -i openapi.yaml -l java -o ./client
# with a config file of language options
swagger-codegen generate -i openapi.yaml -l typescript-fetch \
  -o ./client -c codegen-config.json

Options

FlagWhat it does
-i, --input-spec <path>Input Swagger/OpenAPI file or URL
-l, --lang <name>Target language/framework (note: -l, not -g)
-o, --output <dir>Output directory
-c, --config <file>JSON config of language-specific options
--additional-properties <k=v>Inline generator options
-t, --template-dir <dir>Custom Mustache templates

In CI

Prefer openapi-generator-cli for new pipelines; if you are stuck on swagger-codegen, remember -l replaces -g and language names differ. Regenerate and diff against committed output to catch spec drift, the same as with OpenAPI Generator.

Common errors in CI

"The swagger specification supplied was not valid" (or "issues with the specification") means the input failed validation. "Unable to determine the current version of ..." and Java Exception in thread "main" traces usually mean a JRE/tool version mismatch, since swagger-codegen requires a JDK. "Unknown language" means a bad -l value; run swagger-codegen langs to list them.

Related guides

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