Skip to content

Commit 70cc689

Browse files
fix: add missing message to rules in diagnostic info (#510)
Signed-off-by: Fredrik Nordlander <fredrik.nordlander@digg.se>
1 parent d37749c commit 70cc689

File tree

4 files changed

+14
-9
lines changed

4 files changed

+14
-9
lines changed

src/cli-mode.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ export async function execCLI<T extends CliArgs>(argv: T) {
142142
const result = await customSpectral.run(apiSpecDocument);
143143

144144
const customDiagnostic = new RapLPDiagnostic(context);
145-
customDiagnostic.processRuleExecutionInformation(result, enabledRulesAndCategorys.instanceCategoryMap);
145+
customDiagnostic.processRuleExecutionInformation(result, enabledRulesAndCategorys.rules,enabledRulesAndCategorys.instanceCategoryMap);
146146
const diagnosticReports: DiagnosticReport[] = customDiagnostic.processDiagnosticInformation();
147147
if (argv.dex != null) {
148148
const reportHandler = new ExcelReportProcessor({

src/routes/validate.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const registerValidationRoutes = (app: Express) => {
7272

7373
const enabledRulesAndCategorys = await importAndCreateRuleInstances(ruleCategories);
7474
const customDiagnostic = new RapLPDiagnostic(context);
75-
customDiagnostic.processRuleExecutionInformation(data.result, enabledRulesAndCategorys.instanceCategoryMap);
75+
customDiagnostic.processRuleExecutionInformation(data.result, enabledRulesAndCategorys.rules,enabledRulesAndCategorys.instanceCategoryMap);
7676
const diagnosticReports: DiagnosticReport[] = customDiagnostic.processDiagnosticInformation();
7777

7878
try {

src/util/RapLPDiagnostic.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,27 @@ class RapLPDiagnostic {
1818
constructor(private context: RuleExecutionContext) {}
1919
processRuleExecutionInformation(
2020
raplpCustomResult: RapLPCustomSpectralDiagnostic[],
21+
rules: Record<string, any>,
2122
instanceCategoryMap: Map<string, any>,
2223
): void {
23-
this.processRuleExecutionLog(this.context.ruleExecutionLogDictionary, raplpCustomResult, instanceCategoryMap);
24+
this.processRuleExecutionLog(this.context.ruleExecutionLogDictionary, raplpCustomResult, instanceCategoryMap,rules);
2425
}
2526
private processRuleExecutionLog(
2627
log: RuleExecutionLog,
2728
spectralResults: RapLPCustomSpectralDiagnostic[],
2829
instanceCategoryMap: Map<string, any>,
30+
rules: Record<string, any>,
2931
) {
3032
let executedRuleIds = new Set<string>(); // Set to track executed rule IDs
3133
let executedRuleIdsWithError = new Set<string>(); // Set to track executed rule IDs with error
3234
let ruleIdsNotApplicable = new Set<string>(); // Set to track rules that are not applicable, that is the (Δ) between the two above sets
33-
35+
const ruleIdToMessage = new Map<string, string>();
36+
3437
for (const key in log) {
3538
const rules = log[key];
3639
const { moduleName, className } = rules[0]; // Get module and class name from the first entry
37-
3840
//console.log(`Rule execution status for ${moduleName}:${className}:`);
39-
41+
4042
rules.forEach((rule) => {
4143
const { customProperties, severity, passed, targetVal } = rule;
4244
const status = passed ? 'PASSED' : 'FAILED';
@@ -52,6 +54,7 @@ class RapLPDiagnostic {
5254
this._ruleSets.executedUniqueRulesWithError.push({
5355
id: customProperties.id, // Store some more diagnostic info (Duplicate NOT OK)
5456
område: customProperties.område,
57+
krav: rules[key]?.message ?? '',
5558
});
5659
}
5760
}
@@ -64,6 +67,7 @@ class RapLPDiagnostic {
6467
this._ruleSets.executedUniqueRules.push({
6568
id: customProperties.id, // Store some more diagnostic info (Duplicate OK)
6669
område: customProperties.område,
70+
krav:rules[key]?.message ?? '',
6771
});
6872
}
6973
executedRuleIds.add(customProperties.id); // Store current ID of rule with NO error
@@ -78,7 +82,7 @@ class RapLPDiagnostic {
7882
});
7983
if (!ruleIdsNotApplicable.has(customProperties.id) && !exists) {
8084
// If not present, store the id and område in the not applicableRules
81-
this._ruleSets.notApplicableRules.push({ id: customProperties.id, område: customProperties.område }); // Rules
85+
this._ruleSets.notApplicableRules.push({ id: customProperties.id, område: customProperties.område, krav: rules[key]?.message ?? ''}); // Rules
8286
}
8387
}
8488
}
@@ -94,7 +98,7 @@ class RapLPDiagnostic {
9498
'N/A',
9599
'Godkända regler - RAP-LP',
96100
),
97-
);
101+
);
98102
}
99103
if (
100104
this.diagnosticInformation.executedUniqueRulesWithError &&
@@ -156,6 +160,7 @@ interface DiagnosticRuleinfoSet {
156160
interface DiagnosticRuleInfo {
157161
id: string;
158162
område: string;
163+
krav: string;
159164
}
160165
interface PopulatedDiagnosticRuleInfo extends DiagnosticRuleInfo {
161166
status: string;

src/util/apiUtil.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export async function processApiSpec(
4848

4949

5050
const customDiagnostic = new RapLPDiagnostic(context);
51-
customDiagnostic.processRuleExecutionInformation(result, enabledRulesAndCategorys.instanceCategoryMap);
51+
customDiagnostic.processRuleExecutionInformation(result, enabledRulesAndCategorys.rules,enabledRulesAndCategorys.instanceCategoryMap);
5252
const diagnosticReports: DiagnosticReport[] = customDiagnostic.processDiagnosticInformation();
5353
return { result, report: diagnosticReports };
5454
}

0 commit comments

Comments
 (0)