@@ -111,7 +111,7 @@ const errorHandlers = [
111
111
if ( ! normalizedErrors [ "https://json-schema.org/keyword/minLength" ] [ schemaLocation ] ) {
112
112
const keyword = await getSchema ( schemaLocation ) ;
113
113
errors . push ( {
114
- message : `The instance should be at least ${ Schema . value ( keyword ) } characters` ,
114
+ message : localization . getMinLengthErrorMessage ( Schema . value ( keyword ) ) ,
115
115
instanceLocation : Instance . uri ( instance ) ,
116
116
schemaLocation : schemaLocation
117
117
} ) ;
@@ -131,7 +131,7 @@ const errorHandlers = [
131
131
if ( ! normalizedErrors [ "https://json-schema.org/keyword/maxLength" ] [ schemaLocation ] ) {
132
132
const keyword = await getSchema ( schemaLocation ) ;
133
133
errors . push ( {
134
- message : `The instance should be atmost ${ Schema . value ( keyword ) } characters long.` ,
134
+ message : localization . getMaxLengthErrorMessage ( Schema . value ( keyword ) ) ,
135
135
instanceLocation : Instance . uri ( instance ) ,
136
136
schemaLocation : schemaLocation
137
137
} ) ;
@@ -171,7 +171,7 @@ const errorHandlers = [
171
171
if ( ! normalizedErrors [ "https://json-schema.org/keyword/maximum" ] [ schemaLocation ] ) {
172
172
const keyword = await getSchema ( schemaLocation ) ;
173
173
errors . push ( {
174
- message : `The instance should be less than or equal to ${ Schema . value ( keyword ) } .` ,
174
+ message : localization . getMaximumErrorMessage ( Schema . value ( keyword ) ) ,
175
175
instanceLocation : Instance . uri ( instance ) ,
176
176
schemaLocation : schemaLocation
177
177
} ) ;
@@ -191,7 +191,7 @@ const errorHandlers = [
191
191
if ( ! normalizedErrors [ "https://json-schema.org/keyword/minimum" ] [ schemaLocation ] ) {
192
192
const keyword = await getSchema ( schemaLocation ) ;
193
193
errors . push ( {
194
- message : `The instance should be greater than or equal to ${ Schema . value ( keyword ) } .` ,
194
+ message : localization . getMinimumErrorMessage ( Schema . value ( keyword ) ) ,
195
195
instanceLocation : Instance . uri ( instance ) ,
196
196
schemaLocation : schemaLocation
197
197
} ) ;
@@ -211,7 +211,7 @@ const errorHandlers = [
211
211
if ( ! normalizedErrors [ "https://json-schema.org/keyword/exclusiveMinimum" ] [ schemaLocation ] ) {
212
212
const keyword = await getSchema ( schemaLocation ) ;
213
213
errors . push ( {
214
- message : `The instance should be greater than ${ Schema . value ( keyword ) } .` ,
214
+ message : localization . getExclusiveMinimumErrorMessage ( Schema . value ( keyword ) ) ,
215
215
instanceLocation : Instance . uri ( instance ) ,
216
216
schemaLocation : schemaLocation
217
217
} ) ;
@@ -231,7 +231,7 @@ const errorHandlers = [
231
231
if ( ! normalizedErrors [ "https://json-schema.org/keyword/exclusiveMaximum" ] [ schemaLocation ] ) {
232
232
const keyword = await getSchema ( schemaLocation ) ;
233
233
errors . push ( {
234
- message : `The instance should be less than ${ Schema . value ( keyword ) } .` ,
234
+ message : localization . getExclusiveMaximumErrorMessage ( Schema . value ( keyword ) ) ,
235
235
instanceLocation : Instance . uri ( instance ) ,
236
236
schemaLocation : schemaLocation
237
237
} ) ;
@@ -256,7 +256,7 @@ const errorHandlers = [
256
256
required . delete ( propertyName ) ;
257
257
}
258
258
errors . push ( {
259
- message : `" ${ Instance . uri ( instance ) } " is missing required property(s): ${ [ ...required ] . join ( ", " ) } .` ,
259
+ message : localization . getRequiredErrorMessage ( Instance . uri ( instance ) , [ ...required ] ) ,
260
260
instanceLocation : Instance . uri ( instance ) ,
261
261
schemaLocation : schemaLocation
262
262
} ) ;
@@ -276,7 +276,7 @@ const errorHandlers = [
276
276
if ( ! normalizedErrors [ "https://json-schema.org/keyword/multipleOf" ] [ schemaLocation ] ) {
277
277
const keyword = await getSchema ( schemaLocation ) ;
278
278
errors . push ( {
279
- message : `The instance should be of multiple of ${ Schema . value ( keyword ) } .` ,
279
+ message : localization . getMultipleOfErrorMessage ( Schema . value ( keyword ) ) ,
280
280
instanceLocation : Instance . uri ( instance ) ,
281
281
schemaLocation : schemaLocation
282
282
} ) ;
@@ -296,7 +296,7 @@ const errorHandlers = [
296
296
if ( ! normalizedErrors [ "https://json-schema.org/keyword/maxProperties" ] [ schemaLocation ] ) {
297
297
const keyword = await getSchema ( schemaLocation ) ;
298
298
errors . push ( {
299
- message : `The instance should have maximum ${ Schema . value ( keyword ) } properties.` ,
299
+ message : localization . getMaxPropertiesErrorMessage ( Schema . value ( keyword ) ) ,
300
300
instanceLocation : Instance . uri ( instance ) ,
301
301
schemaLocation : schemaLocation
302
302
} ) ;
@@ -316,7 +316,7 @@ const errorHandlers = [
316
316
if ( ! normalizedErrors [ "https://json-schema.org/keyword/minProperties" ] [ schemaLocation ] ) {
317
317
const keyword = await getSchema ( schemaLocation ) ;
318
318
errors . push ( {
319
- message : `The instance should have minimum ${ Schema . value ( keyword ) } properties.` ,
319
+ message : localization . getMinPropertiesErrorMessage ( Schema . value ( keyword ) ) ,
320
320
instanceLocation : Instance . uri ( instance ) ,
321
321
schemaLocation : schemaLocation
322
322
} ) ;
@@ -336,7 +336,7 @@ const errorHandlers = [
336
336
if ( ! normalizedErrors [ "https://json-schema.org/keyword/const" ] [ schemaLocation ] ) {
337
337
const keyword = await getSchema ( schemaLocation ) ;
338
338
errors . push ( {
339
- message : `The instance should be equal to ${ Schema . value ( keyword ) } .` ,
339
+ message : localization . getConstErrorMessage ( Schema . value ( keyword ) ) ,
340
340
instanceLocation : Instance . uri ( instance ) ,
341
341
schemaLocation : schemaLocation
342
342
} ) ;
@@ -366,23 +366,25 @@ const errorHandlers = [
366
366
weight : leven ( value , currentValue )
367
367
} ) )
368
368
. sort ( ( a , b ) => a . weight - b . weight ) [ 0 ] ;
369
-
370
- let suggestion = "" ;
369
+ let message ;
371
370
if (
372
371
allowedValues . length === 1
373
372
|| ( bestMatch && bestMatch . weight < bestMatch . value . length )
374
373
) {
375
- suggestion = ` Did you mean "${ bestMatch . value } "?` ;
376
- errors . push ( {
377
- message : `Unexpected value "${ currentValue } ". ${ suggestion } ` ,
378
- instanceLocation : Instance . uri ( instance ) ,
379
- schemaLocation : schemaLocation
374
+ message = localization . getEnumErrorMessage ( {
375
+ variant : "suggestion" ,
376
+ instanceValue : currentValue ,
377
+ suggestion : bestMatch . value
378
+ } ) ;
379
+ } else {
380
+ message = localization . getEnumErrorMessage ( {
381
+ variant : "fallback" ,
382
+ instanceValue : currentValue ,
383
+ allowedValues : allowedValues
380
384
} ) ;
381
- continue ;
382
385
}
383
-
384
386
errors . push ( {
385
- message : `Unexpected value " ${ currentValue } ". Expected one of: ${ allowedValues . join ( "," ) } .` ,
387
+ message,
386
388
instanceLocation : Instance . uri ( instance ) ,
387
389
schemaLocation : schemaLocation
388
390
} ) ;
@@ -402,7 +404,7 @@ const errorHandlers = [
402
404
if ( ! normalizedErrors [ "https://json-schema.org/keyword/maxItems" ] [ schemaLocation ] ) {
403
405
const keyword = await getSchema ( schemaLocation ) ;
404
406
errors . push ( {
405
- message : `The instance should contain maximum ${ Schema . value ( keyword ) } items in the array.` ,
407
+ message : localization . getMaxItemsErrorMessage ( Schema . value ( keyword ) ) ,
406
408
instanceLocation : Instance . uri ( instance ) ,
407
409
schemaLocation : schemaLocation
408
410
} ) ;
@@ -422,7 +424,7 @@ const errorHandlers = [
422
424
if ( ! normalizedErrors [ "https://json-schema.org/keyword/minItems" ] [ schemaLocation ] ) {
423
425
const keyword = await getSchema ( schemaLocation ) ;
424
426
errors . push ( {
425
- message : `The instance should contain minimum ${ Schema . value ( keyword ) } items in the array.` ,
427
+ message : localization . getMinItemsErrorMessage ( Schema . value ( keyword ) ) ,
426
428
instanceLocation : Instance . uri ( instance ) ,
427
429
schemaLocation : schemaLocation
428
430
} ) ;
@@ -442,7 +444,7 @@ const errorHandlers = [
442
444
for ( const schemaLocation in normalizedErrors [ "https://json-schema.org/keyword/uniqueItems" ] ) {
443
445
if ( ! normalizedErrors [ "https://json-schema.org/keyword/uniqueItems" ] [ schemaLocation ] ) {
444
446
errors . push ( {
445
- message : `The instance should have unique items in the array.` ,
447
+ message : localization . getUniqueItemsErrorMessage ( ) ,
446
448
instanceLocation : Instance . uri ( instance ) ,
447
449
schemaLocation : schemaLocation
448
450
} ) ;
@@ -462,7 +464,7 @@ const errorHandlers = [
462
464
if ( ! normalizedErrors [ "https://json-schema.org/keyword/format" ] [ schemaLocation ] ) {
463
465
const keyword = await getSchema ( schemaLocation ) ;
464
466
errors . push ( {
465
- message : `The instance should match the format: ${ Schema . value ( keyword ) } .` ,
467
+ message : localization . getFormatErrorMessage ( Schema . value ( keyword ) ) ,
466
468
instanceLocation : Instance . uri ( instance ) ,
467
469
schemaLocation : schemaLocation
468
470
} ) ;
@@ -482,7 +484,7 @@ const errorHandlers = [
482
484
if ( ! normalizedErrors [ "https://json-schema.org/keyword/pattern" ] [ schemaLocation ] ) {
483
485
const keyword = await getSchema ( schemaLocation ) ;
484
486
errors . push ( {
485
- message : `The instance should match the pattern: ${ Schema . value ( keyword ) } .` ,
487
+ message : localization . getPatternErrorMessage ( Schema . value ( keyword ) ) ,
486
488
instanceLocation : Instance . uri ( instance ) ,
487
489
schemaLocation : schemaLocation
488
490
} ) ;
@@ -499,7 +501,7 @@ const errorHandlers = [
499
501
if ( normalizedErrors [ "https://json-schema.org/keyword/contains" ] ) {
500
502
for ( const schemaLocation in normalizedErrors [ "https://json-schema.org/keyword/contains" ] ) {
501
503
errors . push ( {
502
- message : `A required value is missing from the list` ,
504
+ message : localization . getContainsErrorMessage ( ) ,
503
505
instanceLocation : Instance . uri ( instance ) ,
504
506
schemaLocation : schemaLocation
505
507
} ) ;
@@ -522,7 +524,7 @@ const errorHandlers = [
522
524
if ( normalizedErrors [ "https://json-schema.org/keyword/not" ] ) {
523
525
for ( const schemaLocation in normalizedErrors [ "https://json-schema.org/keyword/not" ] ) {
524
526
errors . push ( {
525
- message : `The instance is not allowed to be used in this schema.` ,
527
+ message : localization . getNotErrorMessage ( ) ,
526
528
instanceLocation : Instance . uri ( instance ) ,
527
529
schemaLocation : schemaLocation
528
530
} ) ;
@@ -539,9 +541,9 @@ const errorHandlers = [
539
541
if ( normalizedErrors [ "https://json-schema.org/validation" ] ) {
540
542
for ( const schemaLocation in normalizedErrors [ "https://json-schema.org/validation" ] ) {
541
543
if ( ! normalizedErrors [ "https://json-schema.org/validation" ] [ schemaLocation ] && schemaLocation . endsWith ( "/additionalProperties" ) ) {
542
- const notAllowedValue = Instance . uri ( instance ) . split ( "/" ) . pop ( ) ;
544
+ const notAllowedValue = /** @type string */ ( Instance . uri ( instance ) . split ( "/" ) . pop ( ) ) ;
543
545
errors . push ( {
544
- message : `The property " ${ notAllowedValue } " is not allowed.` ,
546
+ message : localization . getAdditionalPropertiesErrorMessage ( notAllowedValue ) ,
545
547
instanceLocation : Instance . uri ( instance ) ,
546
548
schemaLocation : schemaLocation
547
549
} ) ;
@@ -567,7 +569,7 @@ const errorHandlers = [
567
569
568
570
if ( missing . length > 0 ) {
569
571
errors . push ( {
570
- message : `Property " ${ propertyName } " requires property(s): ${ missing . join ( ", " ) } .` ,
572
+ message : localization . getDependentRequiredErrorMessage ( propertyName , [ ... missing ] ) ,
571
573
instanceLocation : Instance . uri ( instance ) ,
572
574
schemaLocation : schemaLocation
573
575
} ) ;
0 commit comments