Skip to content

OpenAPI Generator Plugin

The @nx-plugin-openapi/plugin-openapi plugin integrates OpenAPI Generator with the Nx Plugin OpenAPI ecosystem.

Terminal window
# Install the core package and plugin
npm install --save-dev @nx-plugin-openapi/core @nx-plugin-openapi/plugin-openapi
# Install the peer dependency
npm install --save-dev @openapitools/openapi-generator-cli
project.json
{
"targets": {
"generate-api": {
"executor": "@nx-plugin-openapi/core:generate-api",
"options": {
"generator": "openapi-tools",
"inputSpec": "apps/my-app/openapi.yaml",
"outputPath": "libs/api-client/src"
}
}
}
}

All OpenAPI Generator CLI options are supported. Pass them either directly in options or via the generatorOptions property.

OptionTypeDescription
generatorstringMust be "openapi-tools"
inputSpecstringPath to OpenAPI spec (local or URL)
outputPathstringOutput directory for generated code
configFilestringPath to OpenAPI Generator config file
skipValidateSpecbooleanSkip spec validation
OptionTypeDescription
apiNameSuffixstringSuffix for API class names
apiPackagestringPackage name for API classes
modelNamePrefixstringPrefix for model class names
modelNameSuffixstringSuffix for model class names
modelPackagestringPackage name for model classes
packageNamestringPackage name for the generated library
OptionTypeDescription
dryRunbooleanPerform dry run without generating files
minimalUpdatebooleanOnly update changed files
skipOverwritebooleanSkip overwriting existing files
removeOperationIdPrefixbooleanRemove operation ID prefixes
strictSpecbooleanUse strict spec validation
OptionTypeDescription
templateDirectorystringCustom templates directory
ignoreFileOverridestringCustom ignore file path
{
"globalProperties": {
"supportsES6": "true",
"npmName": "@my-org/api-client",
"npmVersion": "1.0.0",
"providedInRoot": "true",
"withInterfaces": "true",
"useSingleRequestParameter": "true"
}
}

For Angular projects, use these recommended settings:

project.json
{
"generate-api": {
"executor": "@nx-plugin-openapi/core:generate-api",
"options": {
"generator": "openapi-tools",
"inputSpec": "apps/my-app/swagger.json",
"outputPath": "libs/api-client/src",
"globalProperties": {
"supportsES6": "true",
"providedInRoot": "true",
"withInterfaces": "true",
"useSingleRequestParameter": "true"
}
}
}
}

Or use a separate config file:

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
{
"generate-api": {
"executor": "@nx-plugin-openapi/core:generate-api",
"options": {
"generator": "openapi-tools",
"inputSpec": "apps/my-app/swagger.json",
"outputPath": "libs/api-client/src",
"configFile": "apps/my-app/openapi-config.json"
}
}
}

OpenAPI Generator supports 50+ generators. Common ones include:

  • typescript-angular (default for this plugin)
  • typescript-fetch
  • typescript-axios
  • typescript-node
  • java
  • kotlin
  • python

See the OpenAPI Generator documentation for the full list.

OpenAPI Generator requires Java 8+. Ensure Java is installed and available in your PATH:

Terminal window
java -version

If you’re confident your spec is valid, you can skip validation:

{
"skipValidateSpec": true
}