Skip to main content

Installation

Prerequisites

  • Node.js 18+
  • Angular 19+ project
  • NgRx Signals (@ngrx/signals)
  • Angular Architects NgRx Toolkit (@angular-architects/ngrx-toolkit)

Install Dependencies

First, ensure your Angular project has the required dependencies:

npm install @ngrx/signals @angular-architects/ngrx-toolkit

Install the Generator

The generator can be run directly via npx or installed globally:

# Run directly (recommended)
npx ngrx-openapi-gen -i ./api.yaml -o ./src/app/generated --api-name MyApi

# Or install globally
npm install -g ngrx-openapi-gen
ngrx-openapi-gen -i ./api.yaml -o ./src/app/generated --api-name MyApi

CLI Options

OptionAliasDescriptionRequired
--input-iPath to OpenAPI spec (YAML or JSON)Yes
--output-oOutput directory for generated filesYes
--api-nameName for the API (used for tokens and folder structure)Yes
--zodGenerate Zod schemas for runtime validationNo
--prefer-entity-namesUse entity-based mutation names instead of operationIdNo
--dry-runPreview generated files without writing to diskNo

Project Setup

After generating, configure your Angular application to provide the base path token:

// app.config.ts
import { ApplicationConfig } from '@angular/core';
import { provideHttpClient } from '@angular/common/http';
import { MY_API_BASE_PATH } from './generated/my-api/api-base-path.token';

export const appConfig: ApplicationConfig = {
providers: [
provideHttpClient(),
{ provide: MY_API_BASE_PATH, useValue: 'https://api.example.com' },
],
};

Nx Workspace Integration

For Nx workspaces, add a target to your project.json:

{
"targets": {
"generate-stores": {
"executor": "nx:run-commands",
"options": {
"commands": [
"npx ngrx-openapi-gen -i apps/my-app/src/api.yaml -o apps/my-app/src/app/generated --api-name MyApi"
]
}
}
}
}

Then run:

npx nx run my-app:generate-stores