openapi-generator-cli is a free, open source api development & testing project written in TypeScript and released under Apache-2.0. It has 1,977 GitHub stars, 208 forks and 71 open issues, and was last pushed yesterday. On this registry it ranks #110 of 178 tracked projects in API Development & Testing, with 5 head-to-head comparisons available.

What is openapi-generator-cli?

@openapitools/openapi-generator-cli is a Node package that wraps the Java-based OpenAPI Generator, letting JavaScript and TypeScript developers generate API client libraries, server stubs, and documentation from OpenAPI 2.0 and 3.0 specifications without invoking the upstream Java toolchain by hand.

What it is

The package is a Node wrapper around OpenAPITools/openapi-generator, published to npm as @openapitools/openapi-generator-cli and distributed from an Apache-2.0-licensed TypeScript codebase. The underlying OpenAPI Generator is a Java project, so the wrapper downloads the appropriate JAR file and invokes the java executable to run generation. It lives squarely in the npm ecosystem, and its topics are npm, openapi, openapi-generator, openapi2, and openapi3.

The concrete problem it solves is toolchain friction. A Node or TypeScript team that wants generated clients normally has to obtain the upstream Java generator, manage the JAR, and keep the generator version aligned across machines and contributors. This wrapper replaces that manual JAR management: it fetches and pins the generator, exposes it through a single command, and lets the same version be reproduced from a checked-in configuration file. Since version 2.x the command itself was renamed, so the executable is openapi-generator-cli rather than openapi-generator.

Key capabilities

  • Runs openapi-generator-cli generate -i -g -o to produce API client libraries, server stubs, documentation, and configuration from a single OpenAPI spec.
  • Accepts both OpenAPI 2.0 and 3.0 specifications as input, from a local file path or a remote URL.
  • Ships a version manager with semver support: openapi-generator-cli version-manager list shows available versions and openapi-generator-cli version-manager set switches to another release.
  • Downloads the last stable upstream OpenAPITools/openapi-generator version on first run by default, and records it in the openapitools.json file.
  • Configures code generation inside openapitools.json, including glob expressions so code can be generated for every file matching a given pattern.
  • Passes generator-specific options through --additional-properties, for example --additional-properties=ngVersion=6.1.7,npmName=restClient,supportsES6=true,npmVersion=6.9.0,withInterfaces=true, where whitespace between values is significant.
  • Installs either locally, through npm install @openapitools/openapi-generator-cli or yarn add @openapitools/openapi-generator-cli, or globally, which places openapi-generator-cli on the path.

Who uses it and how

  • Node and TypeScript projects that wire generation into an npm script, such as a package.json script invoking openapi-generator-cli generate -i docs/openapi.yaml -g typescript-angular -o generated-sources/openapi, so regeneration becomes a repeatable project command.
  • Angular front-end teams, which the README's example properties target directly through ngVersion, npmName, npmVersion, supportsES6, and withInterfaces.
  • Teams that pin the generator version repository-wide by committing openapitools.json to version control, ensuring the correct upstream version is used on the next invocation.
  • Developers performing one-off generation against a remote spec, as in the README's Mac/Linux and Windows examples that point -i at a hosted petstore.yaml and emit a client into a temporary directory.
  • Global-install users who want the command available across projects without adding it as a dependency per repository.

Getting started

Install with npm install @openapitools/openapi-generator-cli (or yarn add), then run npx openapi-generator-cli; alternatively install globally with npm install -g @openapitools/openapi-generator-cli. A java binary must be available on the PATH, with JDK 11 as the minimum supported version.

How it compares

No paid product list accompanies these facts, so the meaningful reference point is the upstream project itself: OpenAPITools/openapi-generator, the Java generator this package downloads and invokes. The relationship is one of packaging rather than replacement, since generation behaviour, supported generators, and feature coverage all come from the upstream Java release the wrapper pins.

When to use it — and when not to

The wrapper still requires a working Java runtime: a java binary on the PATH and JDK 11 or newer, plus network access for the first run while the JAR downloads. Teams that do not want a JVM dependency, or that already run the Java generator directly and manage its version themselves, gain little from the extra layer. The package also inherits its capability set and its bugs from upstream, and the repository currently carries 71 open issues alongside its 1,977 stars, so gaps in generation behaviour generally have to be resolved upstream rather than here.

project readme (upstream, from github) — read inline

@openapitools/openapi-generator-cli

Join the Slack chat room

Build Renovate enabled semantic-release

OpenAPI Generator allows generation of API client libraries (SDK generation), server stubs, documentation and configuration automatically given an OpenAPI Spec (both 2.0 and 3.0 are supported). Please see OpenAPITools/openapi-generator.

The OpenAPI Generator is a Java project. openapi-generator-cli will download the appropriate JAR file and invoke the java executable to run the OpenAPI Generator. You must have the java binary executable available on your PATH for this to work. (JDK 11 is the minimal version supported. To install OpenJDK, please visit https://adoptium.net/)

If you find this tool useful, please consider sponsoring this project financially via https://opencollective.com/openapi_generator or directly to Kay Schecker (the author of this tool) :pray:


Version 2.x.x

[update] The command has been renamed

You need to execute openapi-generator-cli instead of openapi-generator from now on.

[added] semver support! 🎉

To make that happen, a version management was added to the package. The first time you run the command openapi-generator-cli the last stable version of OpenAPITools/openapi-generator is downloaded by default.

That version is saved in the file openapitools.json. Therefore, you should include this file in your version control, to ensure that the correct version is being used next time you call the command.

If you would like to use a different version of the OpenAPITools/openapi-generator, you could change it by using one of the following commands:

  • openapi-generator-cli version-manager list
  • openapi-generator-cli version-manager set
[added] generator config

You will now be able to configure the code generation in openapitools.json. This makes it more convenient to generate code for every file that matches the given glob expression. For more information, please check out the configuration documentation below.

Installation

Locally (recommended)

npm install @openapitools/openapi-generator-cli

or using yarn

yarn add @openapitools/openapi-generator-cli

After the installation has finished you can run npx openapi-generator-cli or add a script like this:

{
  "name": "my-cool-package",
  "version": "0.0.0",
  "scripts": {
    "my-awesome-script-name": "openapi-generator-cli generate -i docs/openapi.yaml -g typescript-angular -o generated-sources/openapi --additional-properties=ngVersion=6.1.7,npmName=restClient,supportsES6=true,npmVersion=6.9.0,withInterfaces=true"
  }
}

Note the whitespace sensitivity when using multiple additional-properties:

--additional-properties=ngVersion=6.1.7,npmName=restClient,supportsES6=true,npmVersion=6.9.0,withInterfaces=true

Globally

npm install -g @openapitools/openapi-generator-cli

or using yarn

yarn global add @openapitools/openapi-generator-cli

After the installation has finished you can run openapi-generator-cli

Usage

Mac/Linux:

openapi-generator-cli generate -g ruby -i https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o /var/tmp/ruby-client

Windows:

openapi-generator-cli generate -g ruby -i https://raw.githubusercontent.com/OpenAPITools/openapi-generator/master/modules/openapi-generator/src/test/resources/3_0/petstore.yaml -o C:\temp\ruby-client

Configuration

If you have installed the package locally and executed the command openapi-generator-cli at least once, you will find a new file called openapitools.json along with the package.json. Please add this file to your VCS.

Initially the file has the following content:

{
  "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "7.8.0" // or the current latest version ;)
  }
}

This configuration indicates the following:

  • the json file shall be formatted using 2 spaces
  • the jar files shall be downloaded to ./my/custom/storage/dir
  • the generator-cli version 7.8.0 is used

Further it is also possible to configure generators, for example:

{
  "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "7.8.0",
    "storageDir": "~/my/custom/storage/dir", // optional
    "generators": { // optional
      "v2.0": { // any name you like (just printed to the console log or reference it using --generator-key) 
        "generatorName": "typescript-angular",
        "output": "#{cwd}/output/v2.0/#{ext}/#{name}",
        "glob": "examples/v2.0/{json,yaml}/*.{json,yaml}",
        "additionalProperties": {
          "ngVersion": "6.1.7",
          "npmName": "restClient",
          "supportsES6": "true",
          "npmVersion": "6.9.0",
          "withInterfaces": true
        }
      },
      "v3.0": { // any name you like (just printed to the console log or reference it using --generator-key) 
        "generatorName": "typescript-fetch",
        "output": "#{cwd}/output/v3.0/#{ext}/#{name}",
        "glob": "examples/v3.0/petstore.{json,yaml}"
      }
    }
  }
}

If openapi-generator-cli generate is called without further arguments, then the configuration is automatically used to generate your code. 🎉

Available placeholders
placeholder description example
name just file name auth
Name just file name, but starting with a capital letter Auth
cwd the current cwd /Users/some-user/projects/some-project
base file name and extension auth.yaml
path full path and filename /Users/some-user/projects/some-project/docs/auth.yaml
dir path without the filename /Users/some-user/projects/some-project/docs
relDir directory name of file relative to the glob provided docs
relPath file name and extension of file relative to the glob provided docs/auth.yaml
ext just file extension yaml
env. environment variable (use ${env.name} syntax)

Using custom / private maven registry

If you're using a private maven registry you can configure the downloadUrl and queryUrl like this:

{
  "$schema": "node_modules/@openapitools/openapi-generator-cli/config.schema.json",
  "spaces": 2,
  "generator-cli": {
    "version": "7.8.0",
    "repository": {
      "queryUrl": "https://private.maven.intern/solrsearch/select?q=g:${group.id}+AND+a:${artifact.id}&core=gav&start=0&rows=200",
      "downloadUrl": "https://private.maven.intern/maven2/${groupId}/${artifactId}/${versionName}/${artifactId}-${versionName}.jar"
    }
  }
}

If the version property param is set it is not necessary to configure the queryUrl.

queryUrl and downloadUrl can use the following placeholders:

placeholder description
groupId maven groupId where '.' has been replaced with /
artifactId maven artifactI

readme truncated — read the full docs on github

Frequently asked questions

Is openapi-generator-cli free to use?

openapi-generator-cli is open source under the Apache-2.0 licence. There is no licence fee and no seat count — you can self-host it or, where the project offers one, pay a vendor for a managed version instead.

What does openapi-generator-cli do?

A node package wrapper for https://github.com/OpenAPITools/openapi-generator

What is openapi-generator-cli written in?

openapi-generator-cli is primarily written in TypeScript. Its source is publicly available at https://github.com/OpenAPITools/openapi-generator-cli, and it has 1,977 GitHub stars.