Skip to content

Commit 3cb1e28

Browse files
authored
Merge pull request #3573 from mikhin/nestjs
feat: add NestJS plugin
2 parents 27e01aa + e596edb commit 3cb1e28

61 files changed

Lines changed: 9860 additions & 410 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.changeset/bright-wasps-invite.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@hey-api/openapi-ts": patch
3+
---
4+
5+
**plugin(nestjs)**: initial release

docs/.vitepress/config/en.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,10 @@ export default defineConfig({
227227
link: '/openapi-ts/plugins/fastify',
228228
text: 'Fastify',
229229
},
230+
{
231+
link: '/openapi-ts/plugins/nest',
232+
text: 'Nest',
233+
},
230234
{
231235
link: '/openapi-ts/plugins/adonis',
232236
text: 'Adonis <span data-soon>soon</span>',
@@ -247,10 +251,6 @@ export default defineConfig({
247251
link: '/openapi-ts/plugins/koa',
248252
text: 'Koa <span data-soon>soon</span>',
249253
},
250-
{
251-
link: '/openapi-ts/plugins/nest',
252-
text: 'Nest <span data-soon>soon</span>',
253-
},
254254
],
255255
link: '/openapi-ts/web-frameworks',
256256
text: 'Web Frameworks',
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<script setup lang="ts">
2+
const props = defineProps<{
3+
githubExamplePath?: string;
4+
}>();
5+
</script>
6+
7+
<template>
8+
<h2 id="examples" tabindex="-1">
9+
Examples
10+
<a class="header-anchor" href="#examples" aria-label="Permalink to “Examples”">​</a>
11+
</h2>
12+
<p>
13+
You can view live examples on
14+
<a
15+
href="https://stackblitz.com/orgs/github/hey-api/collections/openapi-ts-examples"
16+
target="_blank"
17+
rel="noreferrer"
18+
>StackBlitz</a
19+
>
20+
or on
21+
<a
22+
:href="`https://github.com/hey-api/openapi-ts/tree/main/examples${props.githubExamplePath ? props.githubExamplePath : ''}`"
23+
target="_blank"
24+
rel="noreferrer"
25+
>GitHub</a
26+
>.
27+
</p>
28+
</template>

docs/data/people.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,8 @@ export const sebastiaanWouters: Person = {
2727
github: 'https://github.com/SebastiaanWouters',
2828
name: 'Sebastiaan Wouters',
2929
};
30+
31+
export const yuriMikhin: Person = {
32+
github: 'https://github.com/mikhin',
33+
name: 'Yuri Mikhin',
34+
};

docs/openapi-ts/plugins/fastify.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ description: Generate Fastify v5 route handlers from OpenAPI with the Fastify pl
55

66
<script setup lang="ts">
77
import AuthorsList from '@components/AuthorsList.vue';
8+
import Examples from '@components/Examples.vue';
89
import Heading from '@components/Heading.vue';
910
import { jacobCohen } from '@data/people.js';
1011
import VersionLabel from '@components/VersionLabel.vue';
@@ -99,5 +100,6 @@ export default {
99100

100101
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/fastify/types.ts) interface.
101102

102-
<!--@include: ../../partials/examples.md-->
103+
<Examples githubExamplePath="/openapi-ts-fastify" />
104+
103105
<!--@include: ../../partials/sponsors.md-->

docs/openapi-ts/plugins/nest.md

Lines changed: 94 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,107 @@
11
---
2-
title: Nest
3-
description: Nest plugin for Hey API. Compatible with all our features.
2+
title: NestJS v11 Plugin
3+
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
---
55

66
<script setup lang="ts">
7-
import FeatureStatus from '@components/FeatureStatus.vue';
7+
import AuthorsList from '@components/AuthorsList.vue';
8+
import Examples from '@components/Examples.vue';
9+
import Heading from '@components/Heading.vue';
10+
import { yuriMikhin } from '@data/people.js';
11+
import VersionLabel from '@components/VersionLabel.vue';
812
</script>
913

10-
# Nest <span data-soon>soon</span>
14+
<Heading>
15+
<h1>NestJS<span class="sr-only"> v11</span></h1>
16+
<VersionLabel value="v11" />
17+
</Heading>
1118

12-
<FeatureStatus issueNumber=1481 name="Nest" />
19+
::: warning
20+
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).
21+
:::
1322

1423
### About
1524

1625
[Nest](https://nestjs.com) is a progressive Node.js framework for building efficient, reliable and scalable server-side applications.
1726

27+
The NestJS plugin for Hey API generates type-safe controller method signatures from your OpenAPI spec, fully compatible with all core features.
28+
29+
### Collaborators
30+
31+
<AuthorsList :people="[yuriMikhin]" />
32+
33+
## Features
34+
35+
- NestJS v11 support
36+
- seamless integration with `@hey-api/openapi-ts` ecosystem
37+
- type-safe controller methods
38+
- minimal learning curve thanks to extending the underlying technology
39+
40+
## Installation
41+
42+
In your [configuration](/openapi-ts/get-started), add `nestjs` to your plugins and you'll be ready to generate NestJS artifacts. :tada:
43+
44+
```js
45+
export default {
46+
input: 'hey-api/backend', // sign up at app.heyapi.dev
47+
output: 'src/client',
48+
plugins: [
49+
// ...other plugins
50+
'nestjs', // [!code ++]
51+
],
52+
};
53+
```
54+
55+
## Output
56+
57+
The NestJS plugin will generate the following artifacts, depending on the input specification.
58+
59+
## Controller Methods
60+
61+
Operations are grouped by their first tag into separate types.
62+
63+
::: code-group
64+
65+
```ts [example]
66+
export type PetsControllerMethods = {
67+
createPet: (body: CreatePetData['body']) => Promise<CreatePetResponse>;
68+
listPets: (query?: ListPetsData['query']) => Promise<ListPetsResponse>;
69+
showPetById: (path: ShowPetByIdData['path']) => Promise<ShowPetByIdResponse>;
70+
};
71+
72+
export type StoreControllerMethods = {
73+
getInventory: () => Promise<GetInventoryResponse>;
74+
};
75+
```
76+
77+
```ts [usage]
78+
import { Body, Controller, Get, Param, Post, Query } from '@nestjs/common';
79+
80+
import type { PetsControllerMethods } from '../client/nestjs.gen';
81+
import type { CreatePetData, ListPetsData, ShowPetByIdData } from '../client/types.gen';
82+
83+
@Controller('pets')
84+
export class PetsController implements Pick<
85+
PetsControllerMethods,
86+
'createPet' | 'listPets' | 'showPetById'
87+
> {
88+
@Post()
89+
async createPet(@Body() body: CreatePetData['body']) {}
90+
91+
@Get()
92+
async listPets(@Query() query?: ListPetsData['query']) {}
93+
94+
@Get(':petId')
95+
async showPetById(@Param() path: ShowPetByIdData['path']) {}
96+
}
97+
```
98+
99+
:::
100+
101+
## API
102+
103+
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.
104+
105+
<Examples githubExamplePath="/openapi-ts-nestjs" />
106+
18107
<!--@include: ../../partials/sponsors.md-->

docs/openapi-ts/web-frameworks.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,12 @@ Hey API natively supports the following frameworks.
1313

1414
- [Angular](/openapi-ts/plugins/angular)
1515
- [Fastify](/openapi-ts/plugins/fastify)
16+
- [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>
21-
- [Nest](/openapi-ts/plugins/nest) <span data-soon>Soon</span>
2222

2323
Don't see your framework? Let us know your interest by [opening an issue](https://github.com/hey-api/openapi-ts/issues).
2424

eslint.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ export default tseslint.config(
5959
'**/node_modules/',
6060
'temp/',
6161
'dev/.gen/',
62+
'examples/openapi-ts-nestjs/src/client/**/*.ts',
6263
'examples/openapi-ts-openai/src/client/**/*.ts',
6364
'**/test/generated/',
6465
'**/__snapshots__/',
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineConfig } from '@hey-api/openapi-ts';
2+
3+
export default defineConfig({
4+
input: './openapi.json',
5+
logs: {
6+
path: './logs',
7+
},
8+
output: {
9+
path: './src/client',
10+
postProcess: ['oxfmt', 'eslint'],
11+
},
12+
plugins: ['nestjs', '@hey-api/sdk'],
13+
});

0 commit comments

Comments
 (0)