Skip to content

ng-openapi-gen

An OpenAPI 3.0 and 3.1 code generator for Angular 16+.

Generates TypeScript model interfaces, typed API functions, and Angular @Injectable services directly from your OpenAPI specification.


Why ng-openapi-gen?

  • Type-safe API clients — Models, parameters, and responses are fully typed
  • OpenAPI 3.0 & 3.1 — Supports both versions in JSON and YAML
  • Promise & Observable — Choose your preferred async model
  • Tree-shakeable — Only the functions you use end up in your bundle
  • Customizable templates — Override any generated file with Go templates
  • Works with Angular CLI — Easy integration into existing projects

Quick start

# Install
go install github.com/czemar/ng-openapi-gen/cmd/ng-openapi-gen@latest

# Generate code from your OpenAPI spec
ng-openapi-gen --input my-api.yaml --output src/app/api

Then in your Angular component:

import { inject } from '@angular/core';
import { Api } from './api/api';
import { listPets } from './api/fn/pets/list-pets';

export class MyComponent {
  private api = inject(Api);

  async ngOnInit() {
    const pets = await this.api.invoke(listPets, { limit: 10 });
  }
}

Key features

FeatureDescription
Functional APIEach operation is a standalone function — only bundle what you use
Services (optional)Traditional @Injectable services per API tag
ModelsTypeScript interfaces for all schemas, with prefix/suffix support
EnumsConfigurable enum styles: alias, upper, pascal, ignorecase
Content negotiationMultiple request/response content types generate distinct variants
Promise or ObservableDefaults to Promise; switch to Observable with one flag
Tag filteringInclude or exclude operations by tag
Custom templatesOverride any output file with your own Go template
Strict TypeScriptGenerated code compiles with noUnusedLocals, noUnusedParameters

Next steps