fix: ajv related tranistive build errors

This commit is contained in:
Rainer Killinger
2021-12-17 10:17:53 +01:00
parent f602d6fe41
commit e82f4e9209
3 changed files with 25 additions and 28 deletions

View File

@@ -14,7 +14,7 @@
*/
import {Logger} from '@openstapps/logger';
import Ajv from 'ajv';
import betterAjvErrors from 'better-ajv-errors';
import betterAjvErrors, {IOutputError} from 'better-ajv-errors';
import {PathLike} from 'fs';
import {JSONSchema7} from 'json-schema';
import * as mustache from 'mustache';
@@ -34,7 +34,6 @@ export class Validator {
*/
private readonly ajv = new Ajv({
verbose: true,
ignoreKeywordsWithRef: true,
code: {regExp: re2},
});
@@ -134,8 +133,7 @@ function fromAjvResult(
instance: unknown,
ajvInstance: Ajv,
): ValidationResult {
// @ts-expect-error function can return void, which at runtime will be undefined. TS doesn't allow to assign void to undefined
const betterErrorObject: betterAjvErrors.IOutputError[] | undefined = betterAjvErrors(
const betterErrorObject: IOutputError[] | undefined = betterAjvErrors(
schema,
instance,
ajvInstance.errors ?? [],
@@ -149,8 +147,7 @@ function fromAjvResult(
const error: ValidationError = {
dataPath: ajvError.instancePath,
instance: instance,
// eslint-disable-next-line @typescript-eslint/no-non-null-asserted-optional-chain
message: betterErrorObject?.[index]?.error! ?? ajvError.message,
message: betterErrorObject?.[index]?.error ?? ajvError.message,
name: ajvError.keyword,
schemaPath: ajvError.schemaPath,
suggestion: betterErrorObject?.[index]?.suggestion,