patternProperties.json 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. [
  2. {
  3. "description":
  4. "patternProperties validates properties matching a regex",
  5. "schema": {
  6. "patternProperties": {
  7. "f.*o": {"type": "integer"}
  8. }
  9. },
  10. "tests": [
  11. {
  12. "description": "a single valid match is valid",
  13. "data": {"foo": 1},
  14. "valid": true
  15. },
  16. {
  17. "description": "multiple valid matches is valid",
  18. "data": {"foo": 1, "foooooo" : 2},
  19. "valid": true
  20. },
  21. {
  22. "description": "a single invalid match is invalid",
  23. "data": {"foo": "bar", "fooooo": 2},
  24. "valid": false
  25. },
  26. {
  27. "description": "multiple invalid matches is invalid",
  28. "data": {"foo": "bar", "foooooo" : "baz"},
  29. "valid": false
  30. },
  31. {
  32. "description": "ignores non-objects",
  33. "data": 12,
  34. "valid": true
  35. }
  36. ]
  37. },
  38. {
  39. "description": "multiple simultaneous patternProperties are validated",
  40. "schema": {
  41. "patternProperties": {
  42. "a*": {"type": "integer"},
  43. "aaa*": {"maximum": 20}
  44. }
  45. },
  46. "tests": [
  47. {
  48. "description": "a single valid match is valid",
  49. "data": {"a": 21},
  50. "valid": true
  51. },
  52. {
  53. "description": "a simultaneous match is valid",
  54. "data": {"aaaa": 18},
  55. "valid": true
  56. },
  57. {
  58. "description": "multiple matches is valid",
  59. "data": {"a": 21, "aaaa": 18},
  60. "valid": true
  61. },
  62. {
  63. "description": "an invalid due to one is invalid",
  64. "data": {"a": "bar"},
  65. "valid": false
  66. },
  67. {
  68. "description": "an invalid due to the other is invalid",
  69. "data": {"aaaa": 31},
  70. "valid": false
  71. },
  72. {
  73. "description": "an invalid due to both is invalid",
  74. "data": {"aaa": "foo", "aaaa": 31},
  75. "valid": false
  76. }
  77. ]
  78. },
  79. {
  80. "description": "regexes are not anchored by default and are case sensitive",
  81. "schema": {
  82. "patternProperties": {
  83. "[0-9]{2,}": { "type": "boolean" },
  84. "X_": { "type": "string" }
  85. }
  86. },
  87. "tests": [
  88. {
  89. "description": "non recognized members are ignored",
  90. "data": { "answer 1": "42" },
  91. "valid": true
  92. },
  93. {
  94. "description": "recognized members are accounted for",
  95. "data": { "a31b": null },
  96. "valid": false
  97. },
  98. {
  99. "description": "regexes are case sensitive",
  100. "data": { "a_x_3": 3 },
  101. "valid": true
  102. },
  103. {
  104. "description": "regexes are case sensitive, 2",
  105. "data": { "a_X_3": 3 },
  106. "valid": false
  107. }
  108. ]
  109. }
  110. ]