File tree 2 files changed +13
-8
lines changed
2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change 1
1
{
2
- "name" : " @rjsf/ core" ,
3
- "version" : " 4.2.0" ,
2
+ "name" : " @imtf/rjsf- core" ,
3
+ "version" : " 4.2.0-fix2 " ,
4
4
"description" : " A simple React component capable of building HTML forms out of a JSON schema." ,
5
5
"scripts" : {
6
6
"build" : " npm run dist:build:umd && npm run build:cjs && npm run build:es && npm run build:es:lib" ,
Original file line number Diff line number Diff line change @@ -305,19 +305,24 @@ export function withIdRefPrefix(schemaNode) {
305
305
* false otherwise. If the schema is invalid, then this function will return
306
306
* false.
307
307
*/
308
+ const validators = new Map ( ) ;
309
+
308
310
export function isValid ( schema , data , rootSchema ) {
311
+ let validator = validators . get ( rootSchema ) ;
312
+
313
+ if ( ! validator ) {
314
+ validator = createAjvInstance ( ) . addSchema ( rootSchema , ROOT_SCHEMA_PREFIX ) ;
315
+
316
+ validators . set ( rootSchema , validator ) ;
317
+ }
318
+
309
319
try {
310
320
// add the rootSchema ROOT_SCHEMA_PREFIX as id.
311
321
// then rewrite the schema ref's to point to the rootSchema
312
322
// this accounts for the case where schema have references to models
313
323
// that lives in the rootSchema but not in the schema in question.
314
- return ajv
315
- . addSchema ( rootSchema , ROOT_SCHEMA_PREFIX )
316
- . validate ( withIdRefPrefix ( schema ) , data ) ;
324
+ return validator . validate ( withIdRefPrefix ( schema ) , data ) ;
317
325
} catch ( e ) {
318
326
return false ;
319
- } finally {
320
- // make sure we remove the rootSchema from the global ajv instance
321
- ajv . removeSchema ( ROOT_SCHEMA_PREFIX ) ;
322
327
}
323
328
}
You can’t perform that action at this time.
0 commit comments