Phase 1 complete
This commit is contained in:
42
apps/backend/generate-openapi.ts
Normal file
42
apps/backend/generate-openapi.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
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);
|
||||
});
|
||||
Reference in New Issue
Block a user