feat: add Swagger API documentation setup in main application bootstrap

This commit is contained in:
Mathis HERRIOT 2025-05-16 19:10:12 +02:00
parent 2f9d2d1df1
commit b61f297497
No known key found for this signature in database
GPG Key ID: E7EB4A211D8D4907

View File

@ -1,6 +1,7 @@
import { NestFactory } from '@nestjs/core'; import { NestFactory } from '@nestjs/core';
import { ValidationPipe } from '@nestjs/common'; import { ValidationPipe } from '@nestjs/common';
import { ConfigService } from '@nestjs/config'; import { ConfigService } from '@nestjs/config';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
import { AppModule } from './app.module'; import { AppModule } from './app.module';
async function bootstrap() { async function bootstrap() {
@ -54,10 +55,22 @@ async function bootstrap() {
} }
// Préfixe global pour les routes API // Préfixe global pour les routes API
app.setGlobalPrefix(configService.get<string>('API_PREFIX', 'api')); const apiPrefix = configService.get<string>('API_PREFIX', 'api');
app.setGlobalPrefix(apiPrefix);
// Configuration de Swagger
const config = new DocumentBuilder()
.setTitle('Group Maker API')
.setDescription('API documentation for the Group Maker application')
.setVersion('1.0')
.addBearerAuth()
.build();
const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api/docs', app, document);
const port = configService.get<number>('PORT', 3000); const port = configService.get<number>('PORT', 3000);
await app.listen(port); await app.listen(port);
console.log(`Application is running on: http://localhost:${port}`); console.log(`Application is running on: http://localhost:${port}`);
console.log(`Swagger documentation is available at: http://localhost:${port}/api/docs`);
} }
bootstrap(); bootstrap();