Skip to content

Commit

Permalink
feat: upgraded json schema version to 2019-09 (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
CptSchnitz committed Sep 24, 2024
1 parent 4502f67 commit 684e7d4
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/configs/models/configValidator.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ajv, { AnySchemaObject, ErrorObject, ValidateFunction } from 'ajv';
import { readFileSync } from 'node:fs';
import Ajv, { AnySchemaObject, ErrorObject, ValidateFunction } from 'ajv/dist/2019';
import { injectable } from 'tsyringe';
import addFormats from 'ajv-formats';
import betterAjvErrors, { type IOutputError } from '@sidvind/better-ajv-errors';
Expand All @@ -11,17 +12,21 @@ export class Validator {
private readonly ajvRefValidator: ValidateFunction;

public constructor(private readonly schemaManager: SchemaManager) {
const draft7MetaSchema = JSON.parse(
readFileSync(require.resolve('ajv/dist/refs/json-schema-draft-07.json'), { encoding: 'utf-8' })
) as AnySchemaObject;
this.ajv = addFormats(
new Ajv({
loadSchema: async (uri): Promise<AnySchemaObject> => {
return this.schemaManager.getSchema(uri);
},
keywords: ['x-env-value'],
useDefaults: true,
}),
['date-time', 'time', 'date', 'email', 'hostname', 'ipv4', 'ipv6', 'uri', 'uuid', 'regex', 'uri-template']
})
);

this.ajv.addMetaSchema(draft7MetaSchema, 'http://json-schema.org/draft-07/schema#');

this.ajvRefValidator = this.ajv.compile(configReferenceSchema);
}

Expand Down

0 comments on commit 684e7d4

Please sign in to comment.