diff --git a/packages/core/src/reducers/core.ts b/packages/core/src/reducers/core.ts index 17eee09dc..aaffcf7da 100644 --- a/packages/core/src/reducers/core.ts +++ b/packages/core/src/reducers/core.ts @@ -90,16 +90,6 @@ const initState: JsonFormsCore = { additionalErrors: [], }; -const reuseAjvForSchema = (ajv: Ajv, schema: JsonSchema): Ajv => { - if ( - Object.prototype.hasOwnProperty.call(schema, 'id') || - Object.prototype.hasOwnProperty.call(schema, '$id') - ) { - ajv.removeSchema(schema); - } - return ajv; -}; - const getOrCreateAjv = ( state: JsonFormsCore, action?: InitAction | UpdateCoreAction @@ -115,12 +105,7 @@ const getOrCreateAjv = ( } } } - if (state.ajv) { - return action?.schema - ? reuseAjvForSchema(state.ajv, action.schema) - : state.ajv; - } - return createAjv(); + return state.ajv ? state.ajv : createAjv(); }; const hasAjvOption = (option: any): option is InitActionOptions => { @@ -255,7 +240,7 @@ export const coreReducer: Reducer = ( const needsNewValidator = action.schema && state.ajv && state.validationMode !== 'NoValidation'; const v = needsNewValidator - ? reuseAjvForSchema(state.ajv, action.schema).compile(action.schema) + ? state.ajv.compile(action.schema) : state.validator; const errors = validate(v, state.data); return { @@ -326,9 +311,7 @@ export const coreReducer: Reducer = ( }; } if (state.validationMode === 'NoValidation') { - const validator = reuseAjvForSchema(state.ajv, state.schema).compile( - state.schema - ); + const validator = state.ajv.compile(state.schema); const errors = validate(validator, state.data); return { ...state, diff --git a/packages/core/src/util/validator.ts b/packages/core/src/util/validator.ts index c3628a0f9..51003c5ca 100644 --- a/packages/core/src/util/validator.ts +++ b/packages/core/src/util/validator.ts @@ -31,6 +31,7 @@ export const createAjv = (options?: Options) => { allErrors: true, verbose: true, strict: false, + addUsedSchema: false, ...options, }); addFormats(ajv);