Skip to content

Commit 7058145

Browse files
committed
feat: add req body validation & auth for swagger
1 parent 43384ca commit 7058145

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/main.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
77

88
import { AppModule } from './app.module';
9+
import { ValidationPipe } from '@nestjs/common';
910

1011
async function bootstrap() {
1112
const fastifyAdapter = new FastifyAdapter();
@@ -14,11 +15,20 @@ async function bootstrap() {
1415
fastifyAdapter,
1516
);
1617

18+
app.useGlobalPipes(
19+
new ValidationPipe({
20+
whitelist: true,
21+
forbidNonWhitelisted: true,
22+
}),
23+
);
24+
1725
const config = new DocumentBuilder()
1826
.setTitle('SOS - Rio Grande do Sul')
1927
.setDescription('...')
2028
.setVersion('1.0')
29+
.addBearerAuth()
2130
.build();
31+
2232
const document = SwaggerModule.createDocument(app, config);
2333
SwaggerModule.setup('api', app, document);
2434

0 commit comments

Comments
 (0)