OpenAPI ↔ Angular
cdd-web-ng is a powerful code generator that creates a modern, type-safe Angular client library and a feature-rich,
production-ready Admin UI directly from an OpenAPI v3 or Swagger v2 specification.
It leverages modern Angular features like standalone components, inject(), and Signals to produce clean, maintainable,
and high-quality code with minimal runtime dependencies.
- Type-Safe Angular Client: Generates Injectableservices and TypeScriptinterfacemodels for all API operations and schemas.
- Automatic Admin UI: Creates a complete, production-ready Angular Material CRUD interface for your API resources, including forms, tables, pagination, validation, and more.
- Modern Angular Architecture:
- Outputs standalone components, directives, and pipes.
- Uses inject()for dependency injection, eliminating constructors.
- Leverages Signals for state management in generated components.
 
- Robust & Maintainable:
- Uses ts-morph for AST-based code generation, ensuring syntactic correctness.
- Core generation logic has 100% test coverage.
 
- Flexible Configuration:
- Usable as a CLI tool or programmatically in build scripts.
- Supports configuration via a config file (cdd-web-ng.config.js) or command-line flags.
 
npm install -g cdd-web-ngThe easiest way to use the generator is via the cdd_web_ng command.
Generate a Client Library and an Admin UI:
cdd_web_ng from_openapi --input ./path/to/spec.yaml --output ./src/app/client --adminGenerate Only the Client Library:
cdd_web_ng from_openapi --input https://petstore3.swagger.io/api/v3/openapi.json --output ./src/app/clientIntegrate the generator into your own build scripts for more advanced control.
// your-build-script.ts
import { generateFromConfig } from 'cdd-web-ng';
await generateFromConfig({
    input: 'path/to/spec.json',
    output: './src/generated/client',
    options: {
        // Generate the client library
        generateServices: true,
        // Also generate the admin UI
        admin: true,
        // Use native Date objects for date-time formats
        dateType: 'Date',
        // Generate string union types instead of enums
        enumStyle: 'union',
    }
});
console.log('Client and Admin UI generated successfully!');The generator creates a provide...Client() function for easy integration into your standalone Angular application.
In your app.config.ts:
import { ApplicationConfig } from '@angular/core';
import { provideRouter } from '@angular/router';
import { provideHttpClient, withInterceptorsFromDi } from '@angular/common/http';
import { provideYourApiNameClient } from '../client'; // <-- Import the generated provider
import { adminRoutes } from '../client/admin/admin.routes'; // <-- Import the generated admin routes
export const appConfig: ApplicationConfig = {
    providers: [
        provideRouter([
            { path: 'admin', children: adminRoutes }, // <-- Add admin routes
            // ... your other app routes
        ]),
        provideHttpClient(withInterceptorsFromDi()),
        // Provide the API client configuration
        provideYourApiNameClient({
            basePath: 'https://api.example.com',
            // Optionally provide an API Key, Bearer Token, or custom interceptors
            // apiKey: 'YOUR_API_KEY',
        }),
    ],
};| Feature | Details | 
|---|---|
| OpenAPI Parsing | Supports OpenAPI 3.x & Swagger 2.0. Parses JSON & YAML from local files or remote URLs. | 
| Code Generation | Uses ts-morph for robust AST manipulation, ensuring syntactically correct TypeScript. | 
| CLI | cdd_web_ngexecutable for easy script integration. Supports config files or direct flags. | 
| Project Structure | Generates a clean output with directories for models,services,admin,utils,auth, andtokens. | 
| Feature | Details | 
|---|---|
| Model Generation | Creates TypeScript interfaces for schemas andenums or union types for enumerations. | 
| Service Generation | Generates one Angular Injectableservice per tag (UsersService, etc.) with methods for each operation. | 
| Method Signatures | Strongly-typed method parameters and full HttpResponseoverloads (observe: 'response'). | 
| Authentication | Generates an AuthInterceptorforapiKey,http(Bearer), andoauth2. UsesInjectionTokens for providing credentials. | 
| Dependency Injection | Generates provide...Clientfunctions for tree-shakable, multi-client setup via uniqueInjectionTokens. | 
| Utilities | Includes helpers for file downloads and an optional DateInterceptorfor automatic date string conversion. | 
The generator can create a complete CRUD interface for your API resources with zero manual configuration.
| Feature Category | Details | 
|---|---|
| Core Admin | Resource Discovery: Auto-identifies RESTful resources from API paths and tags. Component Generation: Creates standalone Angular Material List and Form views for each resource. Routing: Generates lazy-loaded feature routes for each resource. | 
| Form Generation | Dynamic Controls: Maps schema properties to MatInput,MatSelect,MatRadioGroup,MatDatepicker,MatChipList, etc.Complex Structures: Handles nested FormGroups andFormArrays. IgnoresreadOnlyproperties.Validation: Maps keywords like required,minLength,patternto AngularValidators. IncludesCustomValidatorsforexclusiveMinimum,uniqueItems, etc.Polymorphism: Creates dynamic forms for oneOf/discriminatorschemas.File Uploads: Generates file input controls for format: 'binary'. | 
| List View Generation | Data Table: Generates a mat-tablewith columns for model properties.Pagination & Sorting: Implements full server-side support using MatPaginatorandMatSort.Actions: Includes "Edit", "Delete", and custom action buttons. | 
cdd_web_ng from_openapi --help
Usage: cdd_web_ng from_openapi [options]Generate Angular services and admin UI from an OpenAPI specification
Options: -c, --config Path to a configuration file (e.g., cdd-web-ng.config.js) -i, --input Path or URL to the OpenAPI spec (overrides config) -o, --output Output directory for generated files (overrides config) --clientName Name for the generated client (used for DI tokens) --dateType Date type to use (choices: "string", "Date") --enumStyle <style> Style for enums (choices: "enum", "union") --admin Generate an Angular Material admin UI --no-generate-services Disable generation of Angular services -h, --help display help for command
cdd_web_ng to_openapi --help
Usage: cdd_web_ng to_openapi [options]Generate an OpenAPI specification from TypeScript code (Not yet implemented)
Options: -f, --file Path to the input TypeScript source file or directory --format Output format for the OpenAPI spec (choices: "json", "yaml", default: "yaml") -h, --help display help for command
- Clone the repository.
- Install dependencies: npm install
- Run tests: npm test
- Build the project: npm run build
This project extends upon foundational ideas for Angular client generation (Services only; no tests; no auto-admin)
from the MIT-licensed ng-openapi-gen project. Thanks
to Tareq Jami (@Mr-Jami).