···11---
22title: NestJS Plugin
33-description: Generate NestJS controller interfaces from OpenAPI with type safety. Fully compatible with all core features.
33+description: Generate NestJS controller method types from OpenAPI specs. Type-safe controllers via implements.
44---
5566<script setup lang="ts">
···10101111<Heading>
1212 <h1>NestJS</h1>
1313- <VersionLabel value="v10" />
1313+ <VersionLabel value="v11" />
1414</Heading>
15151616::: warning
···19192020### About
21212222-[NestJS](https://nestjs.com) is a progressive Node.js framework for building efficient, reliable and scalable server-side applications.
2323-2424-The NestJS plugin for Hey API generates type-safe controller method signatures from your OpenAPI spec, fully compatible with all core features.
2222+The NestJS plugin generates type-safe controller method signatures from your OpenAPI spec.
25232624## Features
27252828-- NestJS support
2929-- seamless integration with `@hey-api/openapi-ts` ecosystem
3026- type-safe controller methods via `implements`
3127- tag-based grouping for per-controller types
3228- incremental adoption with `Pick<ControllerMethods, ...>`
3329- zero runtime coupling — pure TypeScript types
3434-- minimal learning curve thanks to extending the underlying technology
35303631## Installation
37323838-In your [configuration](/openapi-ts/get-started), add `nestjs` to your plugins and you'll be ready to generate NestJS artifacts. :tada:
3333+In your [configuration](/openapi-ts/get-started), add `nestjs` to your plugins.
39344035```js
4136export default {
···50455146## Output
52475353-The NestJS plugin generates per-tag controller method types from your OpenAPI spec. Operations are grouped by their first OpenAPI tag into separate types like `PetsControllerMethods`, `StoreControllerMethods`, etc.
5454-5555-::: code-group
4848+Operations are grouped by their first OpenAPI tag into separate types like `PetsControllerMethods`, `StoreControllerMethods`, etc.
56495757-```ts [output]
5050+```ts
5851export type PetsControllerMethods = {
5959- createPet: (body: CreatePetData['body']) => Promise<CreatePetResponse>;
6052 listPets: (query?: ListPetsData['query']) => Promise<ListPetsResponse>;
5353+ createPet: (body: CreatePetData['body']) => Promise<CreatePetResponse>;
6154 showPetById: (path: ShowPetByIdData['path']) => Promise<ShowPetByIdResponse>;
6255};
6356···6659};
6760```
68616969-```js [config]
7070-export default {
7171- input: 'hey-api/backend', // sign up at app.heyapi.dev
7272- output: 'src/client',
7373- plugins: [
7474- // ...other plugins
7575- 'nestjs',
7676- ],
7777-};
7878-```
7979-8080-:::
8181-8262## Usage
8383-8484-Use `Pick<ControllerMethods, ...>` with `implements` to enforce the contract on your controllers.
85638664```ts
8787-import { Controller, Get, Post, Param, Query, Body } from '@nestjs/common';
6565+import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common';
8866import type { PetsControllerMethods } from '../client/nestjs.gen';
8989-import type { ListPetsData, ShowPetByIdData, CreatePetData } from '../client/types.gen';
6767+import type { CreatePetData, ListPetsData, ShowPetByIdData } from '../client/types.gen';
90689169@Controller('pets')
9270export class PetsController implements Pick<
9371 PetsControllerMethods,
9494- 'listPets' | 'createPet' | 'showPetById'
7272+ 'createPet' | 'listPets' | 'showPetById'
9573> {
9674 @Get()
9775 async listPets(@Query() query?: ListPetsData['query']) {
···9977 }
1007810179 @Post()
102102- async createPet(@Body() body: CreatePetDto) {
8080+ async createPet(@Body() body: CreatePetData['body']) {
10381 // ...
10482 }
10583···11088}
11189```
11290113113-## Production Example
114114-115115-The [openapi-ts-nestjs example](https://github.com/hey-api/openapi-ts/tree/main/examples/openapi-ts-nestjs) demonstrates a production-quality NestJS app with:
9191+## Example
11692117117-- `class-validator` DTOs for request validation
118118-- `ValidationPipe` with `forbidNonWhitelisted: true`
119119-- `@darraghor/eslint-plugin-nestjs-typed` for NestJS-specific linting
9393+The [openapi-ts-nestjs example](https://github.com/hey-api/openapi-ts/tree/main/examples/openapi-ts-nestjs) demonstrates the plugin with a minimal NestJS v11 app featuring two controllers and integration tests.
1209412195## Constraints
12296···132106async showPetById(@Param('petId') petId: string) { ... }
133107```
134108135135-Methods using `@Res()` for raw response access are incompatible with `implements` because the extra parameter breaks assignability.
136136-137137-Operations without tags are grouped under `DefaultControllerMethods`.
138138-139139-Cookie parameters defined in the OpenAPI spec are not included in generated method signatures. NestJS handles cookies separately via `@Req()` or dedicated cookie middleware.
140140-141141-## API
142142-143143-You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/nestjs/types.ts) interface.
109109+- Methods using `@Res()` for raw response access are incompatible — the extra parameter breaks assignability
110110+- Operations without tags are grouped under `DefaultControllerMethods`
111111+- Cookie parameters are not included in generated signatures — NestJS handles cookies via `@Req()` or dedicated middleware
144112145113<!--@include: ../../partials/examples.md-->
146114<!--@include: ../../partials/sponsors.md-->