1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-02-04 00:18:01 +01:00

Refactor: use the ajv options object instead of add* methods

This commit is contained in:
Thomas Heartman 2022-09-14 11:52:34 +02:00
parent d29400d59a
commit 40b7d2c6e4

View File

@ -1,5 +1,4 @@
import Ajv, { ErrorObject } from 'ajv';
import addFormats from 'ajv-formats';
import { SchemaId, schemas } from './index';
import { omitKeys } from '../util/omit-keys';
@ -12,14 +11,16 @@ const ajv = new Ajv({
schemas: Object.values(schemas).map((schema) =>
omitKeys(schema, 'components'),
),
// example was superseded by examples in openapi 3.1, but we're still on 3.0, so
// let's add it back in!
keywords: ['example'],
formats: {
'date-time': true,
uri: true,
},
});
addFormats(ajv, ['date-time', 'uri', 'uri-reference']);
// example was superseded by examples in openapi 3.1, but we're still on 3.0, so
// let's add it back in!
ajv.addKeyword('example');
export const validateSchema = (
schema: SchemaId,
data: unknown,