43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import { NestFactory } from '@nestjs/core';
|
|
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';
|
|
import { AppModule } from './src/app.module';
|
|
import * as fs from 'fs';
|
|
import * as path from 'path';
|
|
|
|
async function generateOpenApi() {
|
|
// Create app without starting the server
|
|
const app = await NestFactory.create(AppModule, {
|
|
logger: false, // Suppress logs during generation
|
|
});
|
|
|
|
app.setGlobalPrefix('api');
|
|
|
|
const config = new DocumentBuilder()
|
|
.setTitle('DreamChat API')
|
|
.setDescription('The DreamChat API documentation')
|
|
.setVersion('1.0.0')
|
|
.addBearerAuth()
|
|
.build();
|
|
|
|
const document = SwaggerModule.createDocument(app, config);
|
|
|
|
// Ensure the output directory exists
|
|
const outputDir = path.join(__dirname, '..', '..', 'openapi');
|
|
if (!fs.existsSync(outputDir)) {
|
|
fs.mkdirSync(outputDir, { recursive: true });
|
|
}
|
|
|
|
// Write the spec file
|
|
const outputPath = path.join(outputDir, 'openapi.json');
|
|
fs.writeFileSync(outputPath, JSON.stringify(document, null, 2));
|
|
console.log(`📄 OpenAPI spec written to: ${outputPath}`);
|
|
|
|
await app.close();
|
|
process.exit(0);
|
|
}
|
|
|
|
generateOpenApi().catch((err) => {
|
|
console.error('Failed to generate OpenAPI spec:', err);
|
|
process.exit(1);
|
|
});
|