Merge pull request #13787 from mitchhentgesspotify/mhentges/defer-schema-compilation
Defer schema validation to improve test performance
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
'@backstage/catalog-model': patch
|
||||
---
|
||||
|
||||
Defer `ajv` compilation of schema validators to improve module-import performance
|
||||
@@ -22,9 +22,12 @@ import { KindValidator } from './types';
|
||||
// exported kind validators have the `KindValidator` signature which is
|
||||
// different. So let's postpone that change until a later time.
|
||||
export function ajvCompiledJsonSchemaValidator(schema: unknown): KindValidator {
|
||||
const validator = entityKindSchemaValidator(schema);
|
||||
let validator: undefined | ((data: unknown) => any);
|
||||
return {
|
||||
async check(data) {
|
||||
if (!validator) {
|
||||
validator = entityKindSchemaValidator(schema);
|
||||
}
|
||||
return validator(data) === data;
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user