···5566<script setup lang="ts">
77import AuthorsList from '@components/AuthorsList.vue';
88+import Examples from '@components/Examples.vue';
89import Heading from '@components/Heading.vue';
910import { jacobCohen } from '@data/people.js';
1011import VersionLabel from '@components/VersionLabel.vue';
···99100100101You can view the complete list of options in the [UserConfig](https://github.com/hey-api/openapi-ts/blob/main/packages/openapi-ts/src/plugins/fastify/types.ts) interface.
101102102102-<!--@include: ../../partials/examples.md-->
103103+<Examples githubExamplePath="/openapi-ts-fastify" />
104104+103105<!--@include: ../../partials/sponsors.md-->
+94-5
docs/openapi-ts/plugins/nest.md
···11---
22-title: Nest
33-description: Nest plugin for Hey API. Compatible with all our features.
22+title: NestJS v11 Plugin
33+description: Generate NestJS v11 controller methods from OpenAPI with the NestJS plugin for openapi-ts. Fully compatible with validators, transformers, and all core features.
44---
5566<script setup lang="ts">
77-import FeatureStatus from '@components/FeatureStatus.vue';
77+import AuthorsList from '@components/AuthorsList.vue';
88+import Examples from '@components/Examples.vue';
99+import Heading from '@components/Heading.vue';
1010+import { yuriMikhin } from '@data/people.js';
1111+import VersionLabel from '@components/VersionLabel.vue';
812</script>
9131010-# Nest <span data-soon>soon</span>
1414+<Heading>
1515+ <h1>NestJS<span class="sr-only"> v11</span></h1>
1616+ <VersionLabel value="v11" />
1717+</Heading>
11181212-<FeatureStatus issueNumber=1481 name="Nest" />
1919+::: warning
2020+NestJS plugin is currently in beta. The interface might change before it becomes stable. We encourage you to leave feedback on [GitHub](https://github.com/hey-api/openapi-ts/issues).
2121+:::
13221423### About
15241625[Nest](https://nestjs.com) is a progressive Node.js framework for building efficient, reliable and scalable server-side applications.
2626+2727+The NestJS plugin for Hey API generates type-safe controller method signatures from your OpenAPI spec, fully compatible with all core features.
2828+2929+### Collaborators
3030+3131+<AuthorsList :people="[yuriMikhin]" />
3232+3333+## Features
3434+3535+- NestJS v11 support
3636+- seamless integration with `@hey-api/openapi-ts` ecosystem
3737+- type-safe controller methods
3838+- minimal learning curve thanks to extending the underlying technology
3939+4040+## Installation
4141+4242+In your [configuration](/openapi-ts/get-started), add `nestjs` to your plugins and you'll be ready to generate NestJS artifacts. :tada:
4343+4444+```js
4545+export default {
4646+ input: 'hey-api/backend', // sign up at app.heyapi.dev
4747+ output: 'src/client',
4848+ plugins: [
4949+ // ...other plugins
5050+ 'nestjs', // [!code ++]
5151+ ],
5252+};
5353+```
5454+5555+## Output
5656+5757+The NestJS plugin will generate the following artifacts, depending on the input specification.
5858+5959+## Controller Methods
6060+6161+Operations are grouped by their first tag into separate types.
6262+6363+::: code-group
6464+6565+```ts [example]
6666+export type PetsControllerMethods = {
6767+ createPet: (body: CreatePetData['body']) => Promise<CreatePetResponse>;
6868+ listPets: (query?: ListPetsData['query']) => Promise<ListPetsResponse>;
6969+ showPetById: (path: ShowPetByIdData['path']) => Promise<ShowPetByIdResponse>;
7070+};
7171+7272+export type StoreControllerMethods = {
7373+ getInventory: () => Promise<GetInventoryResponse>;
7474+};
7575+```
7676+7777+```ts [usage]
7878+import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common';
7979+8080+import type { PetsControllerMethods } from '../client/nestjs.gen';
8181+import type { CreatePetData, ListPetsData, ShowPetByIdData } from '../client/types.gen';
8282+8383+@Controller('pets')
8484+export class PetsController implements Pick<
8585+ PetsControllerMethods,
8686+ 'createPet' | 'listPets' | 'showPetById'
8787+> {
8888+ @Post()
8989+ async createPet(@Body() body: CreatePetData['body']) {}
9090+9191+ @Get()
9292+ async listPets(@Query() query?: ListPetsData['query']) {}
9393+9494+ @Get(':petId')
9595+ async showPetById(@Param() path: ShowPetByIdData['path']) {}
9696+}
9797+```
9898+9999+:::
100100+101101+## API
102102+103103+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.
104104+105105+<Examples githubExamplePath="/openapi-ts-nestjs" />
1710618107<!--@include: ../../partials/sponsors.md-->
+1-1
docs/openapi-ts/web-frameworks.md
···13131414- [Angular](/openapi-ts/plugins/angular)
1515- [Fastify](/openapi-ts/plugins/fastify)
1616+- [Nest](/openapi-ts/plugins/nest)
1617- [Adonis](/openapi-ts/plugins/adonis) <span data-soon>Soon</span>
1718- [Elysia](/openapi-ts/plugins/elysia) <span data-soon>Soon</span>
1819- [Express](/openapi-ts/plugins/express) <span data-soon>Soon</span>
1920- [Hono](/openapi-ts/plugins/hono) <span data-soon>Soon</span>
2021- [Koa](/openapi-ts/plugins/koa) <span data-soon>Soon</span>
2121-- [Nest](/openapi-ts/plugins/nest) <span data-soon>Soon</span>
22222323Don't see your framework? Let us know your interest by [opening an issue](https://github.com/hey-api/openapi-ts/issues).
2424
···11+// This file is auto-generated by @hey-api/openapi-ts
22+33+import { type ClientOptions, type Config, createClient, createConfig } from './client';
44+import type { ClientOptions as ClientOptions2 } from './types.gen';
55+66+/**
77+ * The `createClientConfig()` function will be called on client initialization
88+ * and the returned object will become the client's initial configuration.
99+ *
1010+ * You may want to initialize your client this way instead of calling
1111+ * `setConfig()`. This is useful for example if you're using Next.js
1212+ * to ensure your client always has the correct values.
1313+ */
1414+export type CreateClientConfig<T extends ClientOptions = ClientOptions2> = (
1515+ override?: Config<ClientOptions & T>,
1616+) => Config<Required<ClientOptions> & T>;
1717+1818+export const client = createClient(
1919+ createConfig<ClientOptions2>({ baseUrl: 'http://localhost:3000/v3' }),
2020+);
···11+// This file is auto-generated by @hey-api/openapi-ts
22+33+import type { Auth, AuthToken } from './auth.gen';
44+import type { BodySerializer, QuerySerializer, QuerySerializerOptions } from './bodySerializer.gen';
55+66+export type HttpMethod =
77+ | 'connect'
88+ | 'delete'
99+ | 'get'
1010+ | 'head'
1111+ | 'options'
1212+ | 'patch'
1313+ | 'post'
1414+ | 'put'
1515+ | 'trace';
1616+1717+export type Client<
1818+ RequestFn = never,
1919+ Config = unknown,
2020+ MethodFn = never,
2121+ BuildUrlFn = never,
2222+ SseFn = never,
2323+> = {
2424+ /**
2525+ * Returns the final request URL.
2626+ */
2727+ buildUrl: BuildUrlFn;
2828+ getConfig: () => Config;
2929+ request: RequestFn;
3030+ setConfig: (config: Config) => Config;
3131+} & {
3232+ [K in HttpMethod]: MethodFn;
3333+} & ([SseFn] extends [never] ? { sse?: never } : { sse: { [K in HttpMethod]: SseFn } });
3434+3535+export interface Config {
3636+ /**
3737+ * Auth token or a function returning auth token. The resolved value will be
3838+ * added to the request payload as defined by its `security` array.
3939+ */
4040+ auth?: ((auth: Auth) => Promise<AuthToken> | AuthToken) | AuthToken;
4141+ /**
4242+ * A function for serializing request body parameter. By default,
4343+ * {@link JSON.stringify()} will be used.
4444+ */
4545+ bodySerializer?: BodySerializer | null;
4646+ /**
4747+ * An object containing any HTTP headers that you want to pre-populate your
4848+ * `Headers` object with.
4949+ *
5050+ * {@link https://developer.mozilla.org/docs/Web/API/Headers/Headers#init See more}
5151+ */
5252+ headers?:
5353+ | RequestInit['headers']
5454+ | Record<
5555+ string,
5656+ string | number | boolean | (string | number | boolean)[] | null | undefined | unknown
5757+ >;
5858+ /**
5959+ * The request method.
6060+ *
6161+ * {@link https://developer.mozilla.org/docs/Web/API/fetch#method See more}
6262+ */
6363+ method?: Uppercase<HttpMethod>;
6464+ /**
6565+ * A function for serializing request query parameters. By default, arrays
6666+ * will be exploded in form style, objects will be exploded in deepObject
6767+ * style, and reserved characters are percent-encoded.
6868+ *
6969+ * This method will have no effect if the native `paramsSerializer()` Axios
7070+ * API function is used.
7171+ *
7272+ * {@link https://swagger.io/docs/specification/serialization/#query View examples}
7373+ */
7474+ querySerializer?: QuerySerializer | QuerySerializerOptions;
7575+ /**
7676+ * A function validating request data. This is useful if you want to ensure
7777+ * the request conforms to the desired shape, so it can be safely sent to
7878+ * the server.
7979+ */
8080+ requestValidator?: (data: unknown) => Promise<unknown>;
8181+ /**
8282+ * A function transforming response data before it's returned. This is useful
8383+ * for post-processing data, e.g. converting ISO strings into Date objects.
8484+ */
8585+ responseTransformer?: (data: unknown) => Promise<unknown>;
8686+ /**
8787+ * A function validating response data. This is useful if you want to ensure
8888+ * the response conforms to the desired shape, so it can be safely passed to
8989+ * the transformers and returned to the user.
9090+ */
9191+ responseValidator?: (data: unknown) => Promise<unknown>;
9292+}
9393+9494+type IsExactlyNeverOrNeverUndefined<T> = [T] extends [never]
9595+ ? true
9696+ : [T] extends [never | undefined]
9797+ ? [undefined] extends [T]
9898+ ? false
9999+ : true
100100+ : false;
101101+102102+export type OmitNever<T extends Record<string, unknown>> = {
103103+ [K in keyof T as IsExactlyNeverOrNeverUndefined<T[K]> extends true ? never : K]: T[K];
104104+};