diff --git a/src/cli-mode.ts b/src/cli-mode.ts index f525257a..14e498a1 100644 --- a/src/cli-mode.ts +++ b/src/cli-mode.ts @@ -142,7 +142,7 @@ export async function execCLI(argv: T) { const result = await customSpectral.run(apiSpecDocument); const customDiagnostic = new RapLPDiagnostic(context); - customDiagnostic.processRuleExecutionInformation(result, enabledRulesAndCategorys.instanceCategoryMap); + customDiagnostic.processRuleExecutionInformation(result, enabledRulesAndCategorys.rules,enabledRulesAndCategorys.instanceCategoryMap); const diagnosticReports: DiagnosticReport[] = customDiagnostic.processDiagnosticInformation(); if (argv.dex != null) { const reportHandler = new ExcelReportProcessor({ diff --git a/src/routes/validate.ts b/src/routes/validate.ts index 8cce3f06..9d9dad19 100644 --- a/src/routes/validate.ts +++ b/src/routes/validate.ts @@ -72,7 +72,7 @@ export const registerValidationRoutes = (app: Express) => { const enabledRulesAndCategorys = await importAndCreateRuleInstances(ruleCategories); const customDiagnostic = new RapLPDiagnostic(context); - customDiagnostic.processRuleExecutionInformation(data.result, enabledRulesAndCategorys.instanceCategoryMap); + customDiagnostic.processRuleExecutionInformation(data.result, enabledRulesAndCategorys.rules,enabledRulesAndCategorys.instanceCategoryMap); const diagnosticReports: DiagnosticReport[] = customDiagnostic.processDiagnosticInformation(); try { diff --git a/src/util/RapLPDiagnostic.ts b/src/util/RapLPDiagnostic.ts index 810b3e19..af18fd2a 100644 --- a/src/util/RapLPDiagnostic.ts +++ b/src/util/RapLPDiagnostic.ts @@ -18,25 +18,27 @@ class RapLPDiagnostic { constructor(private context: RuleExecutionContext) {} processRuleExecutionInformation( raplpCustomResult: RapLPCustomSpectralDiagnostic[], + rules: Record, instanceCategoryMap: Map, ): void { - this.processRuleExecutionLog(this.context.ruleExecutionLogDictionary, raplpCustomResult, instanceCategoryMap); + this.processRuleExecutionLog(this.context.ruleExecutionLogDictionary, raplpCustomResult, instanceCategoryMap,rules); } private processRuleExecutionLog( log: RuleExecutionLog, spectralResults: RapLPCustomSpectralDiagnostic[], instanceCategoryMap: Map, + rules: Record, ) { let executedRuleIds = new Set(); // Set to track executed rule IDs let executedRuleIdsWithError = new Set(); // Set to track executed rule IDs with error let ruleIdsNotApplicable = new Set(); // Set to track rules that are not applicable, that is the (Δ) between the two above sets - + const ruleIdToMessage = new Map(); + for (const key in log) { const rules = log[key]; const { moduleName, className } = rules[0]; // Get module and class name from the first entry - //console.log(`Rule execution status for ${moduleName}:${className}:`); - + rules.forEach((rule) => { const { customProperties, severity, passed, targetVal } = rule; const status = passed ? 'PASSED' : 'FAILED'; @@ -52,6 +54,7 @@ class RapLPDiagnostic { this._ruleSets.executedUniqueRulesWithError.push({ id: customProperties.id, // Store some more diagnostic info (Duplicate NOT OK) område: customProperties.område, + krav: rules[key]?.message ?? '', }); } } @@ -64,6 +67,7 @@ class RapLPDiagnostic { this._ruleSets.executedUniqueRules.push({ id: customProperties.id, // Store some more diagnostic info (Duplicate OK) område: customProperties.område, + krav:rules[key]?.message ?? '', }); } executedRuleIds.add(customProperties.id); // Store current ID of rule with NO error @@ -78,7 +82,7 @@ class RapLPDiagnostic { }); if (!ruleIdsNotApplicable.has(customProperties.id) && !exists) { // If not present, store the id and område in the not applicableRules - this._ruleSets.notApplicableRules.push({ id: customProperties.id, område: customProperties.område }); // Rules + this._ruleSets.notApplicableRules.push({ id: customProperties.id, område: customProperties.område, krav: rules[key]?.message ?? ''}); // Rules } } } @@ -94,7 +98,7 @@ class RapLPDiagnostic { 'N/A', 'Godkända regler - RAP-LP', ), - ); + ); } if ( this.diagnosticInformation.executedUniqueRulesWithError && @@ -156,6 +160,7 @@ interface DiagnosticRuleinfoSet { interface DiagnosticRuleInfo { id: string; område: string; + krav: string; } interface PopulatedDiagnosticRuleInfo extends DiagnosticRuleInfo { status: string; diff --git a/src/util/apiUtil.ts b/src/util/apiUtil.ts index 98dbfee3..08f92c0c 100644 --- a/src/util/apiUtil.ts +++ b/src/util/apiUtil.ts @@ -48,7 +48,7 @@ export async function processApiSpec( const customDiagnostic = new RapLPDiagnostic(context); - customDiagnostic.processRuleExecutionInformation(result, enabledRulesAndCategorys.instanceCategoryMap); + customDiagnostic.processRuleExecutionInformation(result, enabledRulesAndCategorys.rules,enabledRulesAndCategorys.instanceCategoryMap); const diagnosticReports: DiagnosticReport[] = customDiagnostic.processDiagnosticInformation(); return { result, report: diagnosticReports }; }