You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Expand ValidatorMessageFormatSpec to cover all JSON Schema v4 validators
Added tests for 6 additional JSON Schema v4 validation keywords:
- exclusiveMinimum/exclusiveMaximum (numeric bounds)
- additionalItems (tuple validation)
- patternProperties (property name patterns)
- dependencies (property dependencies)
- anyOf (at least one schema match)
Renumbered all test methods (e1-e26) to match their sequential order
in the spec definition for better readability and maintainability.
Replaced all `contain` assertions with `beEqualTo` for exact error
message matching, providing higher confidence that error messages
remain unchanged after the validator upgrade.
Test coverage is now complete for all JSON Schema Draft 4 validation
keywords supported by json-schema-validator 1.0.76.
All 26 tests pass with validator 1.0.76, providing comprehensive
baseline coverage for backward compatibility verification after
upgrading to 1.5.8.
report.message must contain("does not have a value in the enumeration")
391
+
report.message must beEqualTo(
392
+
"$: does not have a value in the enumeration [red, green, blue]"
393
+
)
306
394
case other => ko(s"Expected InvalidData with enum error, got: $other")
307
395
}
308
396
}
309
397
310
398
// Composition validators
311
399
312
-
defe17= {
400
+
defe22= {
313
401
valschema=json"""{
314
402
"allOf": [
315
403
{ "type": "string" },
@@ -326,7 +414,26 @@ class ValidatorMessageFormatSpec extends Specification {
326
414
}
327
415
}
328
416
329
-
defe18= {
417
+
defe23= {
418
+
valschema=json"""{
419
+
"anyOf": [
420
+
{ "type": "string" },
421
+
{ "type": "number" }
422
+
]
423
+
}"""
424
+
valinput=json"""true"""
425
+
CirceValidator.validate(input, schema) match {
426
+
caseLeft(ValidatorError.InvalidData(errors)) =>
427
+
// anyOf typically reports sub-validator failures, not anyOf itself
428
+
// Look for the first error which should be a type error
429
+
valreport= errors.head
430
+
report.keyword must beSome("type")
431
+
report.message must beEqualTo("$: boolean found, string expected")
432
+
case other => ko(s"Expected InvalidData with type error from anyOf, got: $other")
433
+
}
434
+
}
435
+
436
+
defe24= {
330
437
valschema=json"""{
331
438
"oneOf": [
332
439
{ "type": "number", "multipleOf": 5 },
@@ -338,12 +445,14 @@ class ValidatorMessageFormatSpec extends Specification {
338
445
caseLeft(ValidatorError.InvalidData(errors)) =>
339
446
valreport= errors.head
340
447
report.keyword must beSome("oneOf")
341
-
report.message must contain("should be valid to one and only one of schema")
448
+
report.message must beEqualTo(
449
+
"$: should be valid to one and only one of schema, but more than one are valid: {\"type\":\"number\",\"multipleOf\":5}{\"type\":\"number\",\"multipleOf\":3}"
450
+
)
342
451
case other => ko(s"Expected InvalidData with oneOf error, got: $other")
343
452
}
344
453
}
345
454
346
-
defe19= {
455
+
defe25= {
347
456
valschema=json"""{
348
457
"not": { "type": "string" }
349
458
}"""
@@ -352,21 +461,25 @@ class ValidatorMessageFormatSpec extends Specification {
352
461
caseLeft(ValidatorError.InvalidData(errors)) =>
353
462
valreport= errors.head
354
463
report.keyword must beSome("not")
355
-
report.message must contain("should not be valid to the schema")
464
+
report.message must beEqualTo(
465
+
"$: should not be valid to the schema \"not\" : {\"type\":\"string\"}"
466
+
)
356
467
case other => ko(s"Expected InvalidData with not error, got: $other")
357
468
}
358
469
}
359
470
360
471
// Format validators
361
472
362
-
defe20= {
473
+
defe26= {
363
474
valschema=json"""{ "format": "ipv4" }"""
364
475
valinput=json""""not-an-ip""""
365
476
CirceValidator.validate(input, schema) match {
366
477
caseLeft(ValidatorError.InvalidData(errors)) =>
367
478
valreport= errors.head
368
479
report.keyword must beSome("format")
369
-
report.message must contain("does not match the ipv4 pattern")
480
+
report.message must beEqualTo(
481
+
"""$: does not match the ipv4 pattern ^(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])$"""
482
+
)
370
483
report.targets.headOption must beSome("ipv4")
371
484
case other => ko(s"Expected InvalidData with format error, got: $other")
0 commit comments