Skip to content

Commit

Permalink
feat(core): expose x-internal to annotate internal opts (#1993)
Browse files Browse the repository at this point in the history
  • Loading branch information
P0lip committed Dec 9, 2021
1 parent 3f31633 commit 0287319
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
30 changes: 24 additions & 6 deletions packages/core/src/ruleset/rulesetFunction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { printPath, PrintStyle, printValue } from '@stoplight/spectral-runtime';
import { RulesetValidationError } from './validation';
import { IFunctionResult, JSONSchema, RulesetFunction, RulesetFunctionWithValidator } from '../types';

const ajv = new Ajv({ allErrors: true, allowUnionTypes: true, strict: true });
const ajv = new Ajv({ allErrors: true, allowUnionTypes: true, strict: true, keywords: ['x-internal'] });
ajvErrors(ajv);
addFormats(ajv);

Expand Down Expand Up @@ -61,14 +61,32 @@ export class RulesetFunctionValidationError extends RulesetValidationError {
}
}

type Schema = JSONSchema & { errorMessage?: string | { [key in keyof JSONSchema]: string } } & {
properties?: {
[key: string]: SchemaDefinition;
};
patternProperties?: {
type SchemaKeyedFragmentKeyword = 'properties' | 'patternProperties' | 'definitions';
type SchemaFragmentKeyword = 'additionalItems' | 'propertyNames' | 'if' | 'then' | 'else' | 'not';
type SchemaCompoundKeyword = 'allOf' | 'anyOf' | 'oneOf';

type Schema = (
| (Omit<
JSONSchema,
SchemaKeyedFragmentKeyword | SchemaFragmentKeyword | SchemaCompoundKeyword | 'items' | 'dependencies'
> & {
'x-internal'?: boolean;
errorMessage?: string | { [key in keyof JSONSchema]: string };
})
| { 'x-internal': boolean }
) & {
[key in SchemaKeyedFragmentKeyword]?: {
[key: string]: SchemaDefinition;
};
} & {
[key in SchemaFragmentKeyword]?: SchemaDefinition;
} & {
[key in SchemaCompoundKeyword]?: SchemaDefinition[];
} & {
items?: SchemaDefinition | SchemaDefinition[];
dependencies?: SchemaDefinition | string[];
};

type SchemaDefinition = Schema | boolean;

const DEFAULT_OPTIONS_VALIDATOR = (o: unknown): boolean => o === null;
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/ruleset/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import type { FileRuleDefinition, RuleDefinition, RulesetDefinition } from './ty

const message = _`'spectral-message'`;

const ajv = new Ajv({ allErrors: true, strict: true, strictRequired: false, keywords: ['$anchor'] });
const ajv = new Ajv({ allErrors: true, strict: true, strictRequired: false, keywords: ['$anchor', 'x-internal'] });
addFormats(ajv);
addErrors(ajv);
ajv.addKeyword({
Expand Down

0 comments on commit 0287319

Please sign in to comment.