view models
This commit is contained in:
@@ -36,18 +36,19 @@ async function generateTypes() {
|
||||
await fs.mkdir(outputDir, { recursive: true });
|
||||
|
||||
try {
|
||||
// Skip generating monolithic api.ts file
|
||||
// Use openapi-typescript to generate types
|
||||
console.log('📝 Running openapi-typescript...');
|
||||
execSync(`npx openapi-typescript "${openapiPath}" -o "${outputFile}"`, {
|
||||
stdio: 'inherit',
|
||||
cwd: path.join(__dirname, '..')
|
||||
});
|
||||
// console.log('📝 Running openapi-typescript...');
|
||||
// execSync(`npx openapi-typescript "${openapiPath}" -o "${outputFile}"`, {
|
||||
// stdio: 'inherit',
|
||||
// cwd: path.join(__dirname, '..')
|
||||
// });
|
||||
|
||||
// console.log(`✅ TypeScript types generated at: ${outputFile}`);
|
||||
|
||||
console.log(`✅ TypeScript types generated at: ${outputFile}`);
|
||||
|
||||
// Generate individual DTO files
|
||||
await generateIndividualDtoFiles(openapiPath, outputDir);
|
||||
|
||||
|
||||
} catch (error) {
|
||||
console.error('❌ Failed to generate types:', error);
|
||||
process.exit(1);
|
||||
@@ -68,33 +69,13 @@ async function generateIndividualDtoFiles(openapiPath: string, outputDir: string
|
||||
const schema = schemas[schemaName];
|
||||
const fileName = `${schemaName}.ts`;
|
||||
const filePath = path.join(outputDir, fileName);
|
||||
|
||||
|
||||
const fileContent = generateDtoFileContent(schemaName, schema, schemas);
|
||||
await fs.writeFile(filePath, fileContent);
|
||||
console.log(` ✅ Generated ${fileName}`);
|
||||
}
|
||||
|
||||
// Generate index file that re-exports all DTOs
|
||||
let indexContent = `/**
|
||||
* Auto-generated DTO type exports
|
||||
* This file is generated by scripts/generate-api-types.ts
|
||||
* Do not edit manually - regenerate using: npm run api:sync-types
|
||||
*/
|
||||
|
||||
// Re-export all schema types from the generated OpenAPI types
|
||||
export type { components, paths, operations } from './api';
|
||||
|
||||
// Re-export individual DTO types
|
||||
`;
|
||||
|
||||
for (const schemaName of schemaNames) {
|
||||
indexContent += `export type { ${schemaName} } from './${schemaName}';\n`;
|
||||
}
|
||||
|
||||
const indexPath = path.join(outputDir, 'index.ts');
|
||||
await fs.writeFile(indexPath, indexContent);
|
||||
|
||||
console.log(`✅ Generated ${schemaNames.length} individual DTO files and index at: ${outputDir}`);
|
||||
console.log(`✅ Generated ${schemaNames.length} individual DTO files at: ${outputDir}`);
|
||||
}
|
||||
|
||||
function generateDtoFileContent(schemaName: string, schema: any, allSchemas: Record<string, any>): string {
|
||||
|
||||
Reference in New Issue
Block a user