1
0
Fork 0

feat: update Ajv, schema rule usage thereof

BREAKING CHANGE: updates Ajv from v6 to v8, with the breaking
changes included there (https://ajv.js.org/v6-to-v8-migration.html).
This removes support for JSON-Schema draft-04 and adds new
drafts and keywords.
This commit is contained in:
ssube 2021-04-06 08:47:52 -05:00
parent ec0fa5d2d3
commit 41b5a395ee
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
3 changed files with 7 additions and 7 deletions

View File

@ -71,7 +71,7 @@ export class SchemaRule implements Rule, RuleData, Visitor {
if (doesExist(this.filter)) {
return ctx.compile(this.filter);
} else {
return DEFAULT_FILTER;
return DEFAULT_FILTER as any; // TODO: return something with schema/schemaEnv props
}
}
}
@ -87,7 +87,7 @@ export function friendlyError(ctx: VisitorContext, err: ErrorObject): VisitorErr
}
export function friendlyErrorMessage(ctx: VisitorContext, err: ErrorObject): string {
const msg = [err.dataPath];
const msg = [err.instancePath];
if (doesExist(err.message)) {
msg.push(err.message);
} else {

View File

@ -1,5 +1,5 @@
import { doesExist, hasItems } from '@apextoaster/js-utils';
import Ajv from 'ajv';
import Ajv, { ValidateFunction } from 'ajv';
import { JSONPath } from 'jsonpath-plus';
import { Logger } from 'noicejs';
@ -22,7 +22,7 @@ export class VisitorContext implements VisitorContextOptions, VisitorResult {
public readonly logger: Logger;
public readonly schemaOptions: RuleOptions;
protected readonly ajv: Ajv.Ajv;
protected readonly ajv: Ajv;
protected readonly changeBuffer: Array<any>;
protected readonly errorBuffer: Array<VisitorError>;
protected data: any;
@ -61,7 +61,7 @@ export class VisitorContext implements VisitorContextOptions, VisitorResult {
});
}
public compile(schema: any): Ajv.ValidateFunction {
public compile(schema: any): ValidateFunction {
return this.ajv.compile(schema);
}

View File

@ -211,7 +211,7 @@ describe('friendly errors', () => {
it('should have a message', () => {
const { ctx } = createErrorContext();
const err = friendlyError(ctx, {
dataPath: 'test-path',
instancePath: 'test-path',
keyword: TEST_NAME,
params: { /* ? */ },
schemaPath: 'test-path',
@ -223,7 +223,7 @@ describe('friendly errors', () => {
const { ctx } = createErrorContext();
const TEST_MESSAGE = 'test-message';
const err = friendlyError(ctx, {
dataPath: 'test-path',
instancePath: 'test-path',
keyword: TEST_NAME,
message: TEST_MESSAGE,
params: { /* ? */ },