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 via the generatorOptions property (generator, inputSpec and outputPath stay top-level).

OptionTypeDescription
generatorstringMust be "openapi-tools"
inputSpecstringPath to OpenAPI spec (local or URL)
outputPathstringOutput directory for generated code
generatorNamestringOpenAPI Generator to use (-g). Default: typescript-angular
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

Generator-specific settings can be passed without a config file. Values may be string, boolean or number; each map is serialized to a single k=v,k2=v2 CLI flag.

OptionTypeCLI flag
additionalPropertiesRecord<string, string | boolean | number>--additional-properties
typeMappingsRecord<string, string | boolean | number>--type-mappings
importMappingsRecord<string, string | boolean | number>--import-mappings
schemaMappingsRecord<string, string | boolean | number>--schema-mappings
nameMappingsRecord<string, string | boolean | number>--name-mappings
{
"generatorOptions": {
"additionalProperties": {
"npmName": "@my-org/api-client",
"providedIn": "root",
"withInterfaces": true,
"useSingleRequestParameter": true
},
"typeMappings": {
"DateTime": "Date"
}
}
}

Global properties control which files are generated (--global-property):

{
"globalProperties": {
"models": "",
"apis": "",
"supportingFiles": "false"
}
}

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",
"generatorOptions": {
"additionalProperties": {
"supportsES6": true,
"providedIn": "root",
"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",
"generatorOptions": {
"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

Select one via generatorName:

{
"generator": "openapi-tools",
"generatorOptions": {
"generatorName": "typescript-fetch"
}
}

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

The plugin resolves @openapitools/openapi-generator-cli/main.js from the workspace root via Node module resolution (works with npm, yarn and pnpm). If it cannot be resolved, install it in the workspace:

Terminal window
npm install --save-dev @openapitools/openapi-generator-cli

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

{
"generatorOptions": {
"skipValidateSpec": true
}
}