diff --git a/src/apps/cli/internal/flags/validate.flags.ts b/src/apps/cli/internal/flags/validate.flags.ts index 95a2268a..40cdbd0a 100644 --- a/src/apps/cli/internal/flags/validate.flags.ts +++ b/src/apps/cli/internal/flags/validate.flags.ts @@ -24,5 +24,10 @@ export const validateFlags = () => { required: false, default: false, }), + ruleset: Flags.string({ + char: 'r', + description: 'Path to a custom Spectral ruleset file for validation.', + required: false, + }), }; }; diff --git a/src/domains/services/validation.service.ts b/src/domains/services/validation.service.ts index 11ac45fc..2c3737b4 100644 --- a/src/domains/services/validation.service.ts +++ b/src/domains/services/validation.service.ts @@ -290,7 +290,9 @@ export class ValidationService extends BaseService { const suppressedWarnings = options.suppressWarnings ?? []; let activeParser: Parser; - if (suppressAllWarnings || suppressedWarnings.length) { + if (options.ruleset) { + activeParser = this.buildParserWithCustomRuleset(options.ruleset); + } else if (suppressAllWarnings || suppressedWarnings.length) { activeParser = await this.buildAndRegisterCustomParser( specFile, suppressedWarnings, @@ -342,6 +344,23 @@ export class ValidationService extends BaseService { }); } + /** + * Creates a parser with a custom ruleset file. + */ + private buildParserWithCustomRuleset(rulesetPath: string): Parser { + const parser = new Parser({ + ruleset: rulesetPath, + __unstable: { + resolver: { + cache: false, + resolvers: [createHttpWithAuthResolver()], + }, + }, + }); + this.registerSchemaParsers(parser); + return parser; + } + /** * Registers all schema parsers for the given parser instance. */ diff --git a/src/interfaces/index.ts b/src/interfaces/index.ts index 6f6aa102..4c5c6bf8 100644 --- a/src/interfaces/index.ts +++ b/src/interfaces/index.ts @@ -90,6 +90,7 @@ export interface ValidationOptions { output?: string; suppressWarnings?: string[]; suppressAllWarnings?: boolean; + ruleset?: string; } /**