Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit 754495e

Browse files
✨ Add OpenAPI docs
1 parent e8e14c3 commit 754495e

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/main.ts

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,29 @@
11
import { ValidationPipe } from '@nestjs/common';
22
import { NestFactory } from '@nestjs/core';
3-
import { AppModule } from './app.module';
43
import helmet from 'helmet';
4+
import { AppModule } from './app.module';
5+
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
6+
import { promises } from 'fs';
7+
import { join } from 'path';
58

69
async function bootstrap() {
710
const app = await NestFactory.create(AppModule);
11+
812
app.useGlobalPipes(new ValidationPipe());
913
app.use(helmet());
14+
15+
const pkg = JSON.parse(
16+
await promises.readFile(join('.', 'package.json'), 'utf8'),
17+
);
18+
19+
const options = new DocumentBuilder()
20+
.setTitle('API')
21+
.setDescription('API description')
22+
.setVersion(pkg.version)
23+
.build();
24+
const document = SwaggerModule.createDocument(app, options);
25+
SwaggerModule.setup('api', app, document);
26+
1027
await app.listen(3000);
1128
}
1229
bootstrap();

0 commit comments

Comments
 (0)