feat: add example validation and mismatch reporting for OpenAPI schemas
This commit is contained in:
27
main.ts
27
main.ts
@@ -27,6 +27,7 @@ import {
|
||||
import { generateReport } from './src/generators/report.generator';
|
||||
import { lintGeneratedFiles } from './src/generators/lint.generator';
|
||||
import { findEnvironmentFile, parseApiKeys } from './src/utils/environment-finder';
|
||||
import { getExampleMismatches, clearExampleMismatches } from './src/utils/example-validator';
|
||||
import { askApiKeysForTags, askSelectionFilter } from './src/utils/prompt';
|
||||
import {
|
||||
loadConfig,
|
||||
@@ -146,6 +147,7 @@ async function main(): Promise<void> {
|
||||
}
|
||||
|
||||
createDirectoryStructure(options.output);
|
||||
clearExampleMismatches();
|
||||
|
||||
// ── SELECTION: tags and endpoints ─────────────────────────────────────────
|
||||
let selectionFilter: SelectionFilter = {};
|
||||
@@ -216,6 +218,26 @@ async function main(): Promise<void> {
|
||||
);
|
||||
cleanup(tempDir);
|
||||
|
||||
// ── EXAMPLE/TYPE MISMATCH WARNINGS ─────────────────────────────────────────
|
||||
const mismatches = getExampleMismatches();
|
||||
if (mismatches.length > 0) {
|
||||
console.log('');
|
||||
logWarning(`${mismatches.length} example/type mismatch(es) detected in OpenAPI schemas:`);
|
||||
for (const m of mismatches) {
|
||||
const action =
|
||||
m.action === 'coerced'
|
||||
? `→ coerced to ${JSON.stringify(m.coercedValue)}`
|
||||
: '→ example ignored, using type default';
|
||||
logWarning(
|
||||
` ${m.schemaName}.${m.propertyName}: type '${m.declaredType}' but example is ${m.exampleJsType} (${JSON.stringify(m.exampleValue)}) ${action}`
|
||||
);
|
||||
logDetail(
|
||||
'VALIDATE',
|
||||
`${m.schemaName}.${m.propertyName}: declared=${m.declaredType} example=${JSON.stringify(m.exampleValue)} (${m.exampleJsType}) action=${m.action}`
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
const noLintResult: LintResult = {
|
||||
prettier: { ran: false, filesFormatted: 0 },
|
||||
eslint: { ran: false, filesFixed: 0 }
|
||||
@@ -234,6 +256,11 @@ async function main(): Promise<void> {
|
||||
console.log(` - Use Cases: ${report.structure.useCases}`);
|
||||
console.log(` - Providers: ${report.structure.providers}`);
|
||||
console.log(` - Mocks: ${report.structure.mocks}`);
|
||||
if (report.warnings.total > 0) {
|
||||
console.log(
|
||||
`\n ${colors.yellow}⚠️ ${report.warnings.total} example/type mismatch(es) (see above)${colors.reset}`
|
||||
);
|
||||
}
|
||||
console.log(`\n📁 Files generated in: ${colors.cyan}${options.output}${colors.reset}\n`);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user