contract testing

This commit is contained in:
2025-12-24 00:01:01 +01:00
parent 43a8afe7a9
commit 5e491d9724
52 changed files with 2058 additions and 612 deletions

View File

@@ -64,18 +64,42 @@ async function generateIndividualDtoFiles(openapiPath: string, outputDir: string
const schemaNames = Object.keys(schemas);
// Get existing files in output directory
let existingFiles: string[] = [];
try {
existingFiles = await fs.readdir(outputDir);
existingFiles = existingFiles.filter(f => f.endsWith('.ts'));
} catch (error) {
// Directory doesn't exist yet
}
// Generate individual files for each schema
const generatedFileNames: string[] = [];
for (const schemaName of schemaNames) {
const schema = schemas[schemaName];
// File name should match the schema name exactly
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}`);
generatedFileNames.push(fileName);
}
// Clean up files that are no longer in the spec
const filesToRemove = existingFiles.filter(f => !generatedFileNames.includes(f));
for (const file of filesToRemove) {
const filePath = path.join(outputDir, file);
await fs.unlink(filePath);
console.log(` 🗑️ Removed obsolete file: ${file}`);
}
console.log(`✅ Generated ${schemaNames.length} individual DTO files at: ${outputDir}`);
if (filesToRemove.length > 0) {
console.log(`🧹 Cleaned up ${filesToRemove.length} obsolete files`);
}
}
function generateDtoFileContent(schemaName: string, schema: any, allSchemas: Record<string, any>): string {
@@ -101,7 +125,7 @@ function generateDtoFileContent(schemaName: string, schema: any, allSchemas: Rec
content += '\n';
}
// Generate interface
// Generate interface - use the schema name directly
content += `export interface ${schemaName} {\n`;
const properties = schema.properties || {};