Docs are a work in progress - contributions welcome
nestjs-openapi logo

NestJS to OpenAPI. Types in, types out.

Generates OpenAPI specs from your NestJS code. Better output, less decorators, and your types actually make it through.

$npm install -D nestjs-openapi

Why bother with this?

The official swagger module uses runtime reflection, which loses type info. Unions become object, generics disappear, you know the drill.

This tool reads your TypeScript directly, so your types actually show up in the spec. Less decorators to maintain, fewer surprises.

input.ts
export class OrderDto {  status: 'pending' | 'shipped' | 'delivered';}
nestjs-openapi
{  "status": {    "type": "string",    "enum": ["pending", "shipped", "delivered"]  }}
@nestjs/swagger
{ "status": { "type": "object" } }

What you get

No runtime required

Generate specs without compiling TypeScript or bootstrapping your application.

CI/CD friendly

Run in pipelines without spinning up your app or services.

Full type fidelity

Preserves unions, generics, and import aliases that reflect-metadata loses.

Security schemes

Full support for Bearer, API Key, OAuth2, and custom security schemes.

class-validator support

Extracts validation rules and converts them to JSON Schema constraints.

Spec validation warnings

Detects broken $refs and highlights missing schemas before you ship.

Flexible filtering

Filter endpoints by decorator or path pattern for subset specs.

How they compare

@nestjs/swagger

  • Runtime reflection loses types
  • Unions become object
  • Requires app bootstrap
  • Environment setup needed
  • Decorators fill the gaps

nestjs-openapi

  • Reads source directly
  • Unions stay intact
  • No bootstrap needed
  • Runs anywhere, no setup
  • Types are the source of truth

A quick example

Create a config file, run the CLI, done.

import { defineConfig } from 'nestjs-openapi';export default defineConfig({  output: 'openapi.json',  files: {    entry: 'src/app.module.ts',  },  openapi: {    info: {      title: 'My API',      version: '1.0.0',    },  },});
npx nestjs-openapi generate

Give it a try

One config file, one CLI command. See what your spec actually looks like.

nestjs-openapiMIT License