@@ -63,16 +63,18 @@ export class SchemaValidationException extends BaseException {
63
63
64
64
const messages = errors . map ( ( err ) => {
65
65
let message = `Data path ${ JSON . stringify ( err . instancePath ) } ${ err . message } ` ;
66
- switch ( err . keyword ) {
67
- case 'additionalProperties' :
68
- message += `(${ err . params . additionalProperty } )` ;
69
- break ;
70
-
71
- case 'enum' :
72
- message += `. Allowed values are: ${ ( err . params . allowedValues as string [ ] | undefined )
73
- ?. map ( ( v ) => `"${ v } "` )
74
- . join ( ', ' ) } `;
75
- break ;
66
+ if ( err . params ) {
67
+ switch ( err . keyword ) {
68
+ case 'additionalProperties' :
69
+ message += `(${ err . params . additionalProperty } )` ;
70
+ break ;
71
+
72
+ case 'enum' :
73
+ message += `. Allowed values are: ${ ( err . params . allowedValues as string [ ] | undefined )
74
+ ?. map ( ( v ) => `"${ v } "` )
75
+ . join ( ', ' ) } `;
76
+ break ;
77
+ }
76
78
}
77
79
78
80
return message + '.' ;
@@ -300,12 +302,17 @@ export class CoreSchemaRegistry implements SchemaRegistry {
300
302
} ;
301
303
302
304
this . _ajv . removeSchema ( schema ) ;
303
-
304
305
let validator : ValidateFunction ;
306
+
305
307
try {
306
308
this . _currentCompilationSchemaInfo = schemaInfo ;
307
309
validator = this . _ajv . compile ( schema ) ;
308
- } catch {
310
+ } catch ( e ) {
311
+ // This should eventually be refactored so that we we handle race condition where the same schema is validated at the same time.
312
+ if ( ! ( e instanceof Ajv . MissingRefError ) ) {
313
+ throw e ;
314
+ }
315
+
309
316
validator = await this . _ajv . compileAsync ( schema ) ;
310
317
} finally {
311
318
this . _currentCompilationSchemaInfo = undefined ;
@@ -361,9 +368,18 @@ export class CoreSchemaRegistry implements SchemaRegistry {
361
368
}
362
369
363
370
// Validate using ajv
364
- const success = await validator . call ( validationContext , data ) ;
365
- if ( ! success ) {
366
- return { data, success, errors : validator . errors ?? [ ] } ;
371
+ try {
372
+ const success = await validator . call ( validationContext , data ) ;
373
+
374
+ if ( ! success ) {
375
+ return { data, success, errors : validator . errors ?? [ ] } ;
376
+ }
377
+ } catch ( error ) {
378
+ if ( error instanceof Ajv . ValidationError ) {
379
+ return { data, success : false , errors : error . errors } ;
380
+ }
381
+
382
+ throw error ;
367
383
}
368
384
369
385
// Apply post-validation transforms
0 commit comments