Skip to content

@lambda-solutions/nx-plugin-openapi

The original Nx Plugin for seamless integration of OpenAPI Generator in your Nx workspace.

  • Executor for generating API clients from OpenAPI specifications
  • First-class Nx caching support
  • TypeScript Angular client generation
  • Works with both local and remote OpenAPI specs

The easiest way to install the plugin:

Terminal window
nx add @lambda-solutions/nx-plugin-openapi

This command will:

  • Install the plugin package
  • Install the required peer dependency (@openapitools/openapi-generator-cli)

If you prefer manual installation:

Terminal window
# Install the plugin
npm install --save-dev @lambda-solutions/nx-plugin-openapi
# Install the peer dependency
npm install --save-dev @openapitools/openapi-generator-cli

Add a generate-api target to your project.json:

project.json
{
"targets": {
"generate-api": {
"executor": "@lambda-solutions/nx-plugin-openapi:generate-api",
"options": {
"inputSpec": "apps/my-app/swagger.json",
"outputPath": "libs/api-client/src"
}
}
}
}
Terminal window
nx run my-app:generate-api
OptionTypeDescription
inputSpecstringPath to the OpenAPI specification file (local file or URL)
outputPathstringOutput directory for the generated client
OptionTypeDefaultDescription
configFilestring-Path to OpenAPI Generator configuration file
skipValidateSpecbooleanfalseSkip validation of the OpenAPI specification
authstring-Authentication for remote specs (e.g., bearer:token)
OptionTypeDescription
apiNameSuffixstringSuffix to append to API class names
apiPackagestringPackage name for API classes
packageNamestringPackage name for the generated library
modelNamePrefixstringPrefix for model class names
modelNameSuffixstringSuffix for model class names
modelPackagestringPackage name for model classes
OptionTypeDescription
artifactIdstringArtifact ID for the generated project
artifactVersionstringArtifact version
groupIdstringGroup ID for Maven-style organization
OptionTypeDefaultDescription
dryRunbooleanfalsePerform dry run without generating files
enablePostProcessFilebooleanfalseEnable post-processing of files
minimalUpdatebooleanfalseOnly update changed files
skipOverwritebooleanfalseDon’t overwrite existing files
removeOperationIdPrefixbooleanfalseRemove operation ID prefixes
skipOperationExamplebooleanfalseSkip operation examples
strictSpecbooleanfalseUse strict spec validation
OptionTypeDescription
templateDirectorystringCustom templates directory
ignoreFileOverridestringCustom ignore file path
OptionTypeDescription
globalPropertiesobjectProperties passed to OpenAPI Generator
OptionTypeDescription
gitHoststringGit host (e.g., github.com)
gitUserIdstringGit user/organization ID
gitRepoIdstringGit repository ID
OptionTypeDescription
httpUserAgentstringCustom HTTP user agent
releaseNotestringRelease notes for generated code
inputSpecRootDirectorystringRoot directory for specs
invokerPackagestringPackage for invoker classes
logToStderrbooleanLog to stderr instead of stdout
project.json
{
"targets": {
"generate-api": {
"executor": "@lambda-solutions/nx-plugin-openapi:generate-api",
"options": {
"inputSpec": "apps/my-app/swagger.json",
"outputPath": "libs/api-client/src"
}
}
}
}
project.json
{
"targets": {
"generate-api": {
"executor": "@lambda-solutions/nx-plugin-openapi:generate-api",
"options": {
"inputSpec": "apps/my-app/swagger.json",
"outputPath": "libs/api-client/src",
"globalProperties": {
"supportsES6": "true",
"npmName": "@my-org/api-client",
"npmVersion": "1.0.0",
"providedInRoot": "true",
"withInterfaces": "true",
"useSingleRequestParameter": "true"
}
}
}
}
}
apps/my-app/openapi-config.json
{
"npmName": "@my-org/api-client",
"npmVersion": "1.0.0",
"ngVersion": "17.0.0",
"providedInRoot": true,
"withInterfaces": true,
"useSingleRequestParameter": true,
"supportsES6": true,
"modelPropertyNaming": "camelCase",
"enumPropertyNaming": "UPPERCASE"
}
project.json
{
"targets": {
"generate-api": {
"executor": "@lambda-solutions/nx-plugin-openapi:generate-api",
"options": {
"inputSpec": "apps/my-app/swagger.json",
"outputPath": "libs/api-client/src",
"configFile": "apps/my-app/openapi-config.json"
}
}
}
}
project.json
{
"targets": {
"generate-api": {
"executor": "@lambda-solutions/nx-plugin-openapi:generate-api",
"options": {
"inputSpec": "https://api.example.com/v1/swagger.json",
"outputPath": "libs/api-client/src",
"auth": "bearer:your-api-token"
}
}
}
}
project.json
{
"targets": {
"generate-api": {
"executor": "@lambda-solutions/nx-plugin-openapi:generate-api",
"options": {
"inputSpec": "apps/my-app/swagger.json",
"outputPath": "libs/api-client/src"
},
"configurations": {
"development": {
"inputSpec": "http://localhost:3000/api/swagger.json",
"skipValidateSpec": true
},
"production": {
"inputSpec": "https://api.prod.example.com/swagger.json",
"strictSpec": true
}
}
}
}
}

Run with a specific configuration:

Terminal window
nx run my-app:generate-api:development

The plugin fully supports Nx’s caching system. Generated output is cached based on:

  • The OpenAPI specification file content
  • All configuration options
  • Plugin version

To enable caching in CI, configure Nx Cloud or local caching.

After installation, verify the plugin is working:

Terminal window
nx list @lambda-solutions/nx-plugin-openapi

Expected output:

@lambda-solutions/nx-plugin-openapi
Executors:
- generate-api : Generate API client code from OpenAPI specifications

OpenAPI Generator requires Java 8+:

Terminal window
java -version

If Java isn’t installed, download it from adoptium.net.

Skip validation if needed:

{
"skipValidateSpec": true
}

Clear the Nx cache if you encounter stale output:

Terminal window
nx reset

To migrate to the new modular architecture:

  1. Install the new packages:

    Terminal window
    npm install --save-dev @nx-plugin-openapi/core @nx-plugin-openapi/plugin-openapi
  2. Update your executor:

    {
    "executor": "@nx-plugin-openapi/core:generate-api",
    "options": {
    "generator": "openapi-tools",
    // ... other options remain the same
    }
    }
  3. Optionally remove the legacy package:

    Terminal window
    npm uninstall @lambda-solutions/nx-plugin-openapi

MIT