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
  • Required: Yes
  • Description: Path to the OpenAPI specification file or URL

The input specification can be:

  • A local file path (JSON or YAML)
  • A remote URL
  • Relative paths are resolved from the workspace root

Examples:

{
"inputSpec": "apps/my-app/swagger.json"
}
{
"inputSpec": "https://api.example.com/swagger.json"
}
  • 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}"]
}
}
}

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