fix swagger json

This commit is contained in:
Mamadou Khoussa [028918 DSI/DAC/DIF/DS] 2025-12-01 22:51:21 +00:00
parent bc47bca6b5
commit ca698e1c8a

View File

@ -1,3 +1,5 @@
/* eslint-disable @typescript-eslint/no-unsafe-call */
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
import { NestFactory } from '@nestjs/core'; import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module'; import { AppModule } from './app.module';
import { ValidationPipe, Logger } from '@nestjs/common'; import { ValidationPipe, Logger } from '@nestjs/common';
@ -15,24 +17,30 @@ async function bootstrap() {
app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true })); app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));
app.setGlobalPrefix('api/v1'); app.setGlobalPrefix('api/v1');
// Swagger Configuration // Swagger Configuration
const config = new DocumentBuilder() const config = new DocumentBuilder()
.setTitle('DCB User Service API') .setTitle('DCB User Service API')
.setDescription('API de gestion des utilisateurs pour le système DCB') .setDescription('API de gestion des utilisateurs pour le système DCB')
.setVersion('1.0') .setVersion('1.0')
.addTag('users', 'Gestion des utilisateurs') .addTag('users', 'Gestion des utilisateurs')
.addBearerAuth() .addBearerAuth()
//.addServer('http://localhost:3000', 'Développement local') //.addServer('http://localhost:3000', 'Développement local')
// .addServer('https://api.example.com', 'Production') // .addServer('https://api.example.com', 'Production')
.build(); .build();
const document = SwaggerModule.createDocument(app, config); const document = SwaggerModule.createDocument(app, config);
SwaggerModule.setup('api-docs', app, document); SwaggerModule.setup('api-docs', app, document);
app.enableCors({ origin: '*' }) app.enableCors({ origin: '*' });
app.getHttpAdapter().get('/api/swagger-json', (req, res) => {
res.json(document);
});
const port = process.env.PORT || 3000; const port = process.env.PORT || 3000;
await app.listen(port); await app.listen(port);
logger.log(`Application running on http://localhost:${port}`); logger.log(`Application running on http://localhost:${port}`);
logger.log(`Swagger documentation available at http://localhost:${port}/api/docs`); logger.log(
`Swagger documentation available at http://localhost:${port}/api-docs`,
);
console.log(`Swagger docs: http://localhost:${port}/api/swagger-json`);
} }
bootstrap(); bootstrap();