@@ -12,22 +12,22 @@ import { ApiInfo } from '../model/ApiInfo.js';
1212import { validationRules } from '../model/validationRules.js' ;
1313import { ExcelReportProcessor } from '../util/excelReportProcessor.js' ;
1414import { DiagnosticReport , RapLPDiagnostic } from '../util/RapLPDiagnostic.js' ;
15- import { Issue } from '../util/Issue.js' ;
1615import * as IssueHelper from '../util/RapLPIssueHelpers.js' ;
1716import { parseApiSpecInput , detectSpecFormatPreference , ParseResult } from '../util/validateUtil.js' ;
18- import { SpecParseError } from '../util/RapLPSpecParseError.js' ;
1917import { ProblemDetailsDTO } from '../model/ProblemDetailsDto.js' ;
2018import { SpecValidationRequestDto } from '../model/SpecValidationRequestDto.js' ;
2119import { ERROR_TYPE , RapLPBaseApiError } from '../util/RapLPBaseApiErrorHandling.js' ;
2220import type { IParser } from '@stoplight/spectral-parsers' ;
2321import { stringify } from 'node:querystring' ;
22+ import { RuleExecutionContext } from '../util/RuleExecutionContext.js' ;
2423
2524
2625
2726export const registerValidationRoutes = ( app : Express ) => {
2827 // Route for raw content upload.
2928 app . post ( '/api/v1/validation/validate' , async ( req , res , next ) => {
3029 try {
30+ const context = new RuleExecutionContext ( ) ;
3131 const yamlContent : YamlContentDto = req . body ;
3232
3333 let yamlContentString : string ;
@@ -37,9 +37,9 @@ export const registerValidationRoutes = (app: Express) => {
3737
3838 const apiSpecDocument = new Document ( yamlContentString , Parsers . Yaml , '' ) ;
3939
40- const rules = await importAndCreateRuleInstances ( yamlContent . categories ) ;
40+ const rules = await importAndCreateRuleInstances ( context , yamlContent . categories ) ;
4141
42- const result = await processApiSpec ( rules , apiSpecDocument ) ;
42+ const result = await processApiSpec ( context , rules , apiSpecDocument ) ;
4343 res . send ( result ) ;
4444 } catch ( e ) {
4545 next ( e ) ;
@@ -59,6 +59,7 @@ export const registerValidationRoutes = (app: Express) => {
5959 app . post ( '/api/v1/validation/generate-report' , async ( req , res , next ) : Promise < any > => {
6060 try {
6161 const data = req . body ;
62+ const context = new RuleExecutionContext ( ) ;
6263
6364 if ( ! data || ! data . result || ! Array . isArray ( data . result ) ) {
6465 return res . status ( 400 ) . json ( { error : 'Invalid data format. Expected an object with a "result" array.' } ) ;
@@ -70,7 +71,7 @@ export const registerValidationRoutes = (app: Express) => {
7071 const ruleCategories = data . categories && data . categories . length > 0 ? data . categories : undefined ;
7172
7273 const enabledRulesAndCategorys = await importAndCreateRuleInstances ( ruleCategories ) ;
73- const customDiagnostic = new RapLPDiagnostic ( ) ;
74+ const customDiagnostic = new RapLPDiagnostic ( context ) ;
7475 customDiagnostic . processRuleExecutionInformation ( data . result , enabledRulesAndCategorys . instanceCategoryMap ) ;
7576 const diagnosticReports : DiagnosticReport [ ] = customDiagnostic . processDiagnosticInformation ( ) ;
7677
@@ -93,6 +94,7 @@ export const registerValidationRoutes = (app: Express) => {
9394 */
9495 app . post ( '/api/v1/validation/validatespec' , async ( req , res , next ) => {
9596 try {
97+ const context = new RuleExecutionContext ( ) ;
9698 const body : SpecValidationRequestDto = req . body ;
9799
98100 //0.5 Check input
@@ -146,8 +148,8 @@ export const registerValidationRoutes = (app: Express) => {
146148 // 5. No strict-errors → run raplp ruleengine
147149 const parser : IParser < any > = ( parseResult . format === 'json' ? Parsers . Json : Parsers . Yaml ) as unknown as IParser < any > ;
148150 const apiSpecDocument = new Document ( parseResult . raw , parser , '' ) ;
149- const rules = await importAndCreateRuleInstances ( categories ) ;
150- const result = await processApiSpec ( rules , apiSpecDocument ) ;
151+ const rules = await importAndCreateRuleInstances ( context , categories ) ;
152+ const result = await processApiSpec ( context , rules , apiSpecDocument ) ;
151153
152154 const hasRuleViolations = result . result . some (
153155 d => d . allvarlighetsgrad === 'ERROR' || d . allvarlighetsgrad === 'WARNING'
0 commit comments