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:
parent
ec0fa5d2d3
commit
41b5a395ee
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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: { /* ? */ },
|
||||
|
|
Loading…
Reference in New Issue