@@ -20,6 +20,8 @@ import { ERROR_TYPE, RapLPBaseApiError } from '../util/RapLPBaseApiErrorHandling
2020import type { IParser } from '@stoplight/spectral-parsers' ;
2121import { stringify } from 'node:querystring' ;
2222import { RuleExecutionContext } from '../util/RuleExecutionContext.js' ;
23+ import { parseRuleCategories , resolveRuleCategories , RULE_REGISTRY } from '../rulesets/util/ruleModules.js' ;
24+
2325
2426
2527
@@ -28,16 +30,24 @@ export const registerValidationRoutes = (app: Express) => {
2830 app . post ( '/api/v1/validation/validate' , async ( req , res , next ) => {
2931 try {
3032 const context = new RuleExecutionContext ( ) ;
33+
34+ const body : SpecValidationRequestDto = req . body ;
35+ const strict = body . strict ?? true ;
36+ const categories = body . categories ?? [ ] ;
37+
3138 const yamlContent : YamlContentDto = req . body ;
3239
33- let yamlContentString : string ;
34- yamlContentString = decodeBase64String ( yamlContent . yaml ) ;
40+ //let yamlContentString: string;
41+ //yamlContentString = decodeBase64String(yamlContent.yaml);
42+ const raw = decodeBase64String ( body . spec ) ;
3543
36- validateYamlInput ( yamlContentString ) ;
44+ validateYamlInput ( raw ) ; // Do we need this ?
3745
38- const apiSpecDocument = new Document ( yamlContentString , Parsers . Yaml , '' ) ;
46+ const apiSpecDocument = new Document ( raw , Parsers . Yaml , 'payload.yaml' ) ;
47+ const ruleCategories = parseRuleCategories ( categories ) ;
48+ const resolvedCategories = resolveRuleCategories ( ruleCategories ) ;
3949
40- const rules = await importAndCreateRuleInstances ( context , yamlContent . categories ) ;
50+ const rules = await importAndCreateRuleInstances ( context , resolvedCategories ) ;
4151
4252 const result = await processApiSpec ( context , rules , apiSpecDocument ) ;
4353 res . send ( result ) ;
@@ -47,7 +57,7 @@ export const registerValidationRoutes = (app: Express) => {
4757 } ) ;
4858
4959 app . get ( '/api/v1/validation/rules' , ( req , res ) => {
50- res . send ( validationRules ) ;
60+ res . send ( RULE_REGISTRY ) ;
5161 } ) ;
5262
5363 app . get ( '/api/v1/api-info' , async ( req , res , next ) => {
@@ -68,9 +78,11 @@ export const registerValidationRoutes = (app: Express) => {
6878 const reportHandler = new ExcelReportProcessor ( ) ;
6979 let buffer : Buffer ;
7080
71- const ruleCategories = data . categories && data . categories . length > 0 ? data . categories : undefined ;
81+ const categories = data . categories && data . categories . length > 0 ? data . categories : undefined ;
82+ const ruleCategories = parseRuleCategories ( categories ) ;
83+ const resolvedCategories = resolveRuleCategories ( ruleCategories ) ;
7284
73- const enabledRulesAndCategorys = await importAndCreateRuleInstances ( ruleCategories ) ;
85+ const enabledRulesAndCategorys = await importAndCreateRuleInstances ( context , resolvedCategories ) ;
7486 const customDiagnostic = new RapLPDiagnostic ( context ) ;
7587 customDiagnostic . processRuleExecutionInformation ( data . result , enabledRulesAndCategorys . rules , enabledRulesAndCategorys . instanceCategoryMap ) ;
7688 const diagnosticReports : DiagnosticReport [ ] = customDiagnostic . processDiagnosticInformation ( ) ;
@@ -147,8 +159,12 @@ export const registerValidationRoutes = (app: Express) => {
147159
148160 // 5. No strict-errors → run raplp ruleengine
149161 const parser : IParser < any > = ( parseResult . format === 'json' ? Parsers . Json : Parsers . Yaml ) as unknown as IParser < any > ;
150- const apiSpecDocument = new Document ( parseResult . raw , parser , 'payload.yaml' ) ; // In-memory-file to calculate correct positions when parsing
151- const rules = await importAndCreateRuleInstances ( context , categories ) ;
162+ const apiSpecDocument = new Document ( parseResult . raw , parser , 'payload.yaml' ) ; // In-memory-file to calculate correct positions when parsing
163+
164+ const ruleCategories = parseRuleCategories ( categories ) ;
165+ const resolvedCategories = resolveRuleCategories ( ruleCategories ) ;
166+
167+ const rules = await importAndCreateRuleInstances ( context , resolvedCategories ) ;
152168 const result = await processApiSpec ( context , rules , apiSpecDocument ) ;
153169
154170 const hasRuleViolations = result . result . some (
0 commit comments