Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/apps/cli/internal/flags/validate.flags.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}),
};
};
21 changes: 20 additions & 1 deletion src/domains/services/validation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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.
*/
Expand Down
1 change: 1 addition & 0 deletions src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ export interface ValidationOptions {
output?: string;
suppressWarnings?: string[];
suppressAllWarnings?: boolean;
ruleset?: string;
}

/**
Expand Down
Loading