generate-api Executor
generate-api Executor
Section titled “generate-api Executor”The generate-api
executor generates TypeScript Angular API client code from OpenAPI specifications using the OpenAPI Generator.
nx run <project>:generate-api
Basic Configuration
Section titled “Basic Configuration”{ "targets": { "generate-api": { "executor": "@lambda-solutions/nx-plugin-openapi:generate-api", "options": { "inputSpec": "apps/my-app/swagger.json", "outputPath": "libs/api-client/src" } } }}
Required Options
Section titled “Required Options”inputSpec
Section titled “inputSpec”- 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"}
outputPath
Section titled “outputPath”- 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"}
Optional Configuration Options
Section titled “Optional Configuration Options”configFile
Section titled “configFile”- 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"}
skipValidateSpec
Section titled “skipValidateSpec”- 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}
Authentication & Security
Section titled “Authentication & Security”- Type:
string
- Default:
undefined
- Description: Authentication configuration for accessing remote specifications
Example:
{ "auth": "bearer:your-api-token"}
Naming & Package Configuration
Section titled “Naming & Package Configuration”apiNameSuffix
Section titled “apiNameSuffix”- Type:
string
- Default:
undefined
- Description: Suffix to append to generated API class names
Example:
{ "apiNameSuffix": "Client"}
apiPackage
Section titled “apiPackage”- Type:
string
- Default:
undefined
- Description: Package name for API classes
Example:
{ "apiPackage": "com.example.api"}
packageName
Section titled “packageName”- Type:
string
- Default:
undefined
- Description: Package name for the generated client library
Example:
{ "packageName": "@my-org/api-client"}
modelNamePrefix
Section titled “modelNamePrefix”- Type:
string
- Default:
undefined
- Description: Prefix for generated model class names
Example:
{ "modelNamePrefix": "Api"}
modelNameSuffix
Section titled “modelNameSuffix”- Type:
string
- Default:
undefined
- Description: Suffix for generated model class names
Example:
{ "modelNameSuffix": "Model"}
modelPackage
Section titled “modelPackage”- Type:
string
- Default:
undefined
- Description: Package name for model classes
Example:
{ "modelPackage": "com.example.models"}
Project Metadata
Section titled “Project Metadata”artifactId
Section titled “artifactId”- Type:
string
- Default:
undefined
- Description: Artifact ID for the generated code
Example:
{ "artifactId": "my-api-client"}
artifactVersion
Section titled “artifactVersion”- Type:
string
- Default:
undefined
- Description: Version of the generated artifact
Example:
{ "artifactVersion": "1.0.0"}
groupId
Section titled “groupId”- Type:
string
- Default:
undefined
- Description: Group ID for the generated code
Example:
{ "groupId": "com.example"}
Generation Behavior
Section titled “Generation Behavior”dryRun
Section titled “dryRun”- Type:
boolean
- Default:
false
- Description: Perform a dry run without actually generating files
Useful for testing configuration without creating files.
Example:
{ "dryRun": true}
enablePostProcessFile
Section titled “enablePostProcessFile”- Type:
boolean
- Default:
false
- Description: Enable post-processing of generated files
Example:
{ "enablePostProcessFile": true}
minimalUpdate
Section titled “minimalUpdate”- Type:
boolean
- Default:
false
- Description: Only update files that have actually changed
Example:
{ "minimalUpdate": true}
skipOverwrite
Section titled “skipOverwrite”- Type:
boolean
- Default:
false
- Description: Skip overwriting existing files
Example:
{ "skipOverwrite": true}
removeOperationIdPrefix
Section titled “removeOperationIdPrefix”- Type:
boolean
- Default:
false
- Description: Remove operation ID prefixes from generated method names
Example:
{ "removeOperationIdPrefix": true}
skipOperationExample
Section titled “skipOperationExample”- Type:
boolean
- Default:
false
- Description: Skip generating operation examples in the code
Example:
{ "skipOperationExample": true}
strictSpec
Section titled “strictSpec”- Type:
boolean
- Default:
false
- Description: Use strict specification validation
Example:
{ "strictSpec": true}
Templates & Customization
Section titled “Templates & Customization”templateDirectory
Section titled “templateDirectory”- Type:
string
- Default:
undefined
- Description: Directory containing custom templates for code generation
Example:
{ "templateDirectory": "apps/my-app/templates"}
ignoreFileOverride
Section titled “ignoreFileOverride”- Type:
string
- Default:
undefined
- Description: Path to a custom ignore file
Example:
{ "ignoreFileOverride": "apps/my-app/.openapi-generator-ignore"}
Advanced Configuration
Section titled “Advanced Configuration”globalProperties
Section titled “globalProperties”- 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" }}
httpUserAgent
Section titled “httpUserAgent”- Type:
string
- Default:
undefined
- Description: Custom HTTP user agent string
Example:
{ "httpUserAgent": "MyApp/1.0.0"}
releaseNote
Section titled “releaseNote”- Type:
string
- Default:
undefined
- Description: Release notes for the generated code
Example:
{ "releaseNote": "Initial release of the API client"}
inputSpecRootDirectory
Section titled “inputSpecRootDirectory”- Type:
string
- Default:
undefined
- Description: Root directory for input specifications
Example:
{ "inputSpecRootDirectory": "specs/"}
invokerPackage
Section titled “invokerPackage”- Type:
string
- Default:
undefined
- Description: Package name for invoker classes
Example:
{ "invokerPackage": "com.example.invoker"}
Git Integration
Section titled “Git Integration”gitHost
Section titled “gitHost”- Type:
string
- Default:
undefined
- Description: Git host for the repository
Example:
{ "gitHost": "github.com"}
gitUserId
Section titled “gitUserId”- Type:
string
- Default:
undefined
- Description: Git user ID
Example:
{ "gitUserId": "my-username"}
gitRepoId
Section titled “gitRepoId”- Type:
string
- Default:
undefined
- Description: Git repository ID
Example:
{ "gitRepoId": "my-api-client"}
Logging & Debugging
Section titled “Logging & Debugging”logToStderr
Section titled “logToStderr”- Type:
boolean
- Default:
false
- Description: Log output to stderr instead of stdout
Example:
{ "logToStderr": true}
Complete Example
Section titled “Complete Example”Here’s a comprehensive example showing many options:
{ "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}"] } }}
Environment-Specific Configuration
Section titled “Environment-Specific Configuration”Use configurations for different environments:
{ "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:
nx run demo:generate-api:development