mirror of
https://github.com/LukeHagar/redocly-cli.git
synced 2025-12-06 12:47:48 +00:00
refactor: split in two packages: core and cli (#223)
This commit is contained in:
31
packages/core/src/benchmark/utils.ts
Normal file
31
packages/core/src/benchmark/utils.ts
Normal file
@@ -0,0 +1,31 @@
|
||||
import * as yaml from 'js-yaml';
|
||||
import { Document, Source } from '../resolve';
|
||||
import { Oas3RuleSet } from '../validate';
|
||||
import { RuleConfig, LintConfig, Plugin } from '../config/config';
|
||||
|
||||
export function parseYamlToDocument(body: string, absoluteRef: string = ''): Document {
|
||||
return {
|
||||
source: new Source(absoluteRef, body),
|
||||
parsed: yaml.safeLoad(body, { filename: absoluteRef }),
|
||||
};
|
||||
}
|
||||
|
||||
export function makeConfigForRuleset(rules: Oas3RuleSet, plugin?: Partial<Plugin>) {
|
||||
const rulesConf: Record<string, RuleConfig> = {};
|
||||
const ruleId = 'test';
|
||||
Object.keys(rules).forEach((name) => {
|
||||
rulesConf[`${ruleId}/${name}`] = 'error';
|
||||
});
|
||||
|
||||
return new LintConfig({
|
||||
plugins: [
|
||||
{
|
||||
...plugin,
|
||||
id: ruleId,
|
||||
rules: { oas3: rules },
|
||||
},
|
||||
],
|
||||
extends: [],
|
||||
rules: rulesConf,
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user