Skip to content

generate-api Executor

The generate-api executor generates TypeScript Angular API client code from OpenAPI specifications using the OpenAPI Generator.

Terminal window
nx run <project>:generate-api
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"
}
}
}
}
  • Type: string | Record<string, string>
  • Required: Yes
  • Description: Path to the OpenAPI specification file(s) or URL(s)

The input specification can be:

  • A single string: Path to one OpenAPI specification (backward compatible)
  • An object: Multiple specifications mapped by service name (for microservices)

For projects with a single API:

{
"inputSpec": "apps/my-app/swagger.json"
}
{
"inputSpec": "https://api.example.com/swagger.json"
}

For microservice architectures with multiple APIs:

{
"inputSpec": {
"ms-product": "apps/my-app/ms-product.json",
"ms-user": "apps/my-app/ms-user.json",
"ms-inventory": "apps/my-app/ms-inventory.json"
}
}

When using multiple specifications:

  • Each key becomes a subdirectory name under outputPath
  • Each API is generated in its own subdirectory
  • All configured options are applied to each generation

Generated structure for multiple specs:

libs/api/src/
ms-product/
// generated API for product service
ms-user/
// generated API for user service
ms-inventory/
// generated API for inventory service
  • Type: string
  • Required: Yes
  • Description: Output directory for the generated API client code

The output directory will be cleaned before generation. Relative paths are resolved from the workspace root.

Examples:

{
"outputPath": "libs/api-client/src"
}
{
"outputPath": "apps/my-app/src/app/generated"
}
  • Type: string
  • Default: undefined
  • Description: Path to OpenAPI Generator configuration file

Allows you to specify detailed generation options in a separate JSON file.

Example:

{
"configFile": "apps/my-app/openapi-config.json"
}
  • Type: boolean
  • Default: false
  • Description: Skip validation of the OpenAPI specification

Set to true for faster generation when you’re confident your specification is valid.

Example:

{
"skipValidateSpec": true
}
  • Type: string
  • Default: undefined
  • Description: Authentication configuration for accessing remote specifications

Example:

{
"auth": "bearer:your-api-token"
}
  • Type: string
  • Default: undefined
  • Description: Suffix to append to generated API class names

Example:

{
"apiNameSuffix": "Client"
}
  • Type: string
  • Default: undefined
  • Description: Package name for API classes

Example:

{
"apiPackage": "com.example.api"
}
  • Type: string
  • Default: undefined
  • Description: Package name for the generated client library

Example:

{
"packageName": "@my-org/api-client"
}
  • Type: string
  • Default: undefined
  • Description: Prefix for generated model class names

Example:

{
"modelNamePrefix": "Api"
}
  • Type: string
  • Default: undefined
  • Description: Suffix for generated model class names

Example:

{
"modelNameSuffix": "Model"
}
  • Type: string
  • Default: undefined
  • Description: Package name for model classes

Example:

{
"modelPackage": "com.example.models"
}
  • Type: string
  • Default: undefined
  • Description: Artifact ID for the generated code

Example:

{
"artifactId": "my-api-client"
}
  • Type: string
  • Default: undefined
  • Description: Version of the generated artifact

Example:

{
"artifactVersion": "1.0.0"
}
  • Type: string
  • Default: undefined
  • Description: Group ID for the generated code

Example:

{
"groupId": "com.example"
}
  • Type: boolean
  • Default: false
  • Description: Perform a dry run without actually generating files

Useful for testing configuration without creating files.

Example:

{
"dryRun": true
}
  • Type: boolean
  • Default: false
  • Description: Enable post-processing of generated files

Example:

{
"enablePostProcessFile": true
}
  • Type: boolean
  • Default: false
  • Description: Only update files that have actually changed

Example:

{
"minimalUpdate": true
}
  • Type: boolean
  • Default: false
  • Description: Skip overwriting existing files

Example:

{
"skipOverwrite": true
}
  • Type: boolean
  • Default: false
  • Description: Remove operation ID prefixes from generated method names

Example:

{
"removeOperationIdPrefix": true
}
  • Type: boolean
  • Default: false
  • Description: Skip generating operation examples in the code

Example:

{
"skipOperationExample": true
}
  • Type: boolean
  • Default: false
  • Description: Use strict specification validation

Example:

{
"strictSpec": true
}
  • Type: string
  • Default: undefined
  • Description: Directory containing custom templates for code generation

Example:

{
"templateDirectory": "apps/my-app/templates"
}
  • Type: string
  • Default: undefined
  • Description: Path to a custom ignore file

Example:

{
"ignoreFileOverride": "apps/my-app/.openapi-generator-ignore"
}
  • Type: object
  • Default: undefined
  • Description: Global properties for the OpenAPI Generator

An object where keys are property names and values are property values.

Example:

{
"globalProperties": {
"supportsES6": "true",
"npmName": "@my-org/api-client",
"npmVersion": "1.0.0",
"providedInRoot": "true",
"withInterfaces": "true"
}
}
  • Type: string
  • Default: undefined
  • Description: Custom HTTP user agent string

Example:

{
"httpUserAgent": "MyApp/1.0.0"
}
  • Type: string
  • Default: undefined
  • Description: Release notes for the generated code

Example:

{
"releaseNote": "Initial release of the API client"
}
  • Type: string
  • Default: undefined
  • Description: Root directory for input specifications

Example:

{
"inputSpecRootDirectory": "specs/"
}
  • Type: string
  • Default: undefined
  • Description: Package name for invoker classes

Example:

{
"invokerPackage": "com.example.invoker"
}
  • Type: string
  • Default: undefined
  • Description: Git host for the repository

Example:

{
"gitHost": "github.com"
}
  • Type: string
  • Default: undefined
  • Description: Git user ID

Example:

{
"gitUserId": "my-username"
}
  • Type: string
  • Default: undefined
  • Description: Git repository ID

Example:

{
"gitRepoId": "my-api-client"
}
  • Type: boolean
  • Default: false
  • Description: Log output to stderr instead of stdout

Example:

{
"logToStderr": true
}

Here’s a comprehensive example showing many options:

project.json
{
"targets": {
"generate-api": {
"executor": "@lambda-solutions/nx-plugin-openapi:generate-api",
"options": {
"inputSpec": "apps/demo/swagger.json",
"outputPath": "libs/api-client/src",
"configFile": "apps/demo/openapi-config.json",
"packageName": "@my-org/demo-api-client",
"apiNameSuffix": "Service",
"modelNamePrefix": "Api",
"modelNameSuffix": "Model",
"skipValidateSpec": false,
"strictSpec": true,
"globalProperties": {
"supportsES6": "true",
"npmName": "@my-org/demo-api-client",
"npmVersion": "1.0.0",
"providedInRoot": "true",
"withInterfaces": "true"
}
},
"outputs": ["{options.outputPath}"]
}
}
}

For microservice architectures:

project.json
{
"targets": {
"generate-api": {
"executor": "@lambda-solutions/nx-plugin-openapi:generate-api",
"options": {
"inputSpec": {
"auth-service": "apis/auth-service.yaml",
"product-service": "apis/product-service.yaml",
"order-service": "apis/order-service.yaml",
"payment-service": "apis/payment-service.yaml"
},
"outputPath": "libs/api-clients/src",
"packageName": "@my-org/api-clients",
"apiNameSuffix": "ApiService",
"modelNamePrefix": "Api",
"globalProperties": {
"supportsES6": "true",
"providedInRoot": "true",
"withInterfaces": "true"
}
},
"outputs": ["{options.outputPath}"]
}
}
}

This will generate:

libs/api-clients/src/
auth-service/
// Auth API client
product-service/
// Product API client
order-service/
// Order API client
payment-service/
// Payment API client

Use configurations for different environments:

project.json
{
"targets": {
"generate-api": {
"executor": "@lambda-solutions/nx-plugin-openapi:generate-api",
"options": {
"inputSpec": "apps/demo/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 configuration:

Terminal window
nx run demo:generate-api:development