feat: add example validation and mismatch reporting for OpenAPI schemas

This commit is contained in:
2026-03-27 15:27:03 +01:00
parent aab9bf01bb
commit e0446d4939
7 changed files with 261 additions and 10 deletions

View File

@@ -3,7 +3,7 @@ import path from 'path';
import mustache from 'mustache';
import { logStep, logSuccess, logDetail } from '../utils/logger';
import { mapSwaggerTypeToTs } from '../utils/type-mapper';
import { toCamelCase, toPascalCase } from '../utils/name-formatter';
import { toCamelCase, toPascalCase, safePropertyName } from '../utils/name-formatter';
import { resolveMockValue } from '../utils/mock-value-resolver';
import type {
SwaggerAnalysis,
@@ -253,7 +253,8 @@ export function generateCleanArchitecture(
tsType = `${rawProperties[k].items.$ref.split('/').pop()}[]`;
}
return {
name: k,
name: safePropertyName(k),
originalName: k,
dataType: tsType,
description: rawProperties[k].description || '',
required: requiredProps.includes(k)
@@ -343,8 +344,8 @@ export function generateCleanArchitecture(
// DTO mock — values resolved from raw schema (example, format, type)
const dtoMockVarsMap = Object.keys(rawProperties).map((k) => ({
name: k,
mockValue: resolveMockValue(k, rawProperties[k], 'dto')
name: safePropertyName(k),
mockValue: resolveMockValue(k, rawProperties[k], 'dto', schemaName)
}));
const dtoMockImports = [...referencedTypes].filter(Boolean).map((name) => ({
classname: name,

View File

@@ -1,6 +1,7 @@
import fs from 'fs-extra';
import path from 'path';
import { logStep, logSuccess } from '../utils/logger';
import { getExampleMismatches } from '../utils/example-validator';
import type { SwaggerAnalysis, GenerationReport, LintResult } from '../types';
/** Counts files ending with `.mock.ts` in a directory (returns 0 if directory does not exist). */
@@ -41,6 +42,8 @@ export function generateReport(
return { name: t.name, description: t.description || '', endpoints: endpointCount };
});
const exampleMismatches = getExampleMismatches();
const report: GenerationReport = {
timestamp: new Date().toISOString(),
tags: analysis.tags.length,
@@ -48,6 +51,10 @@ export function generateReport(
tagDetails,
outputDirectory: outputDir,
linting: lintResult,
warnings: {
exampleMismatches: exampleMismatches.map((m) => ({ ...m })),
total: exampleMismatches.length
},
structure: {
dtos: fs.readdirSync(path.join(outputDir, 'data/dtos')).length,
repositories: fs.readdirSync(path.join(outputDir, 'data/repositories')).length,