rj_schema 0.2.4 → 1.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (627) hide show
  1. checksums.yaml +4 -4
  2. data/ext/rj_schema/rapidjson/CHANGELOG.md +158 -0
  3. data/ext/rj_schema/rapidjson/CMakeLists.txt +248 -0
  4. data/ext/rj_schema/rapidjson/CMakeModules/FindGTestSrc.cmake +30 -0
  5. data/ext/rj_schema/rapidjson/RapidJSON.pc.in +7 -0
  6. data/ext/rj_schema/rapidjson/RapidJSONConfig.cmake.in +25 -0
  7. data/ext/rj_schema/rapidjson/RapidJSONConfigVersion.cmake.in +10 -0
  8. data/ext/rj_schema/rapidjson/appveyor.yml +102 -0
  9. data/ext/rj_schema/rapidjson/bin/data/abcde.txt +1 -0
  10. data/ext/rj_schema/rapidjson/bin/data/glossary.json +22 -0
  11. data/ext/rj_schema/rapidjson/bin/data/menu.json +27 -0
  12. data/ext/rj_schema/rapidjson/bin/data/readme.txt +1 -0
  13. data/ext/rj_schema/rapidjson/bin/data/sample.json +3315 -0
  14. data/ext/rj_schema/rapidjson/bin/data/webapp.json +88 -0
  15. data/ext/rj_schema/rapidjson/bin/data/widget.json +26 -0
  16. data/ext/rj_schema/rapidjson/bin/draft-04/schema +150 -0
  17. data/ext/rj_schema/rapidjson/bin/encodings/utf16be.json +0 -0
  18. data/ext/rj_schema/rapidjson/bin/encodings/utf16bebom.json +0 -0
  19. data/ext/rj_schema/rapidjson/bin/encodings/utf16le.json +0 -0
  20. data/ext/rj_schema/rapidjson/bin/encodings/utf16lebom.json +0 -0
  21. data/ext/rj_schema/rapidjson/bin/encodings/utf32be.json +0 -0
  22. data/ext/rj_schema/rapidjson/bin/encodings/utf32bebom.json +0 -0
  23. data/ext/rj_schema/rapidjson/bin/encodings/utf32le.json +0 -0
  24. data/ext/rj_schema/rapidjson/bin/encodings/utf32lebom.json +0 -0
  25. data/ext/rj_schema/rapidjson/bin/encodings/utf8.json +7 -0
  26. data/ext/rj_schema/rapidjson/bin/encodings/utf8bom.json +7 -0
  27. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail1.json +1 -0
  28. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail10.json +1 -0
  29. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail11.json +1 -0
  30. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail12.json +1 -0
  31. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail13.json +1 -0
  32. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail14.json +1 -0
  33. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail15.json +1 -0
  34. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail16.json +1 -0
  35. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail17.json +1 -0
  36. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail18.json +1 -0
  37. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail19.json +1 -0
  38. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail2.json +1 -0
  39. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail20.json +1 -0
  40. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail21.json +1 -0
  41. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail22.json +1 -0
  42. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail23.json +1 -0
  43. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail24.json +1 -0
  44. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail25.json +1 -0
  45. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail26.json +1 -0
  46. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail27.json +2 -0
  47. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail28.json +2 -0
  48. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail29.json +1 -0
  49. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail3.json +1 -0
  50. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail30.json +1 -0
  51. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail31.json +1 -0
  52. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail32.json +1 -0
  53. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail33.json +1 -0
  54. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail4.json +1 -0
  55. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail5.json +1 -0
  56. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail6.json +1 -0
  57. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail7.json +1 -0
  58. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail8.json +1 -0
  59. data/ext/rj_schema/rapidjson/bin/jsonchecker/fail9.json +1 -0
  60. data/ext/rj_schema/rapidjson/bin/jsonchecker/pass1.json +58 -0
  61. data/ext/rj_schema/rapidjson/bin/jsonchecker/pass2.json +1 -0
  62. data/ext/rj_schema/rapidjson/bin/jsonchecker/pass3.json +6 -0
  63. data/ext/rj_schema/rapidjson/bin/jsonchecker/readme.txt +3 -0
  64. data/ext/rj_schema/rapidjson/bin/jsonschema/LICENSE +19 -0
  65. data/ext/rj_schema/rapidjson/bin/jsonschema/README.md +148 -0
  66. data/ext/rj_schema/rapidjson/bin/jsonschema/bin/jsonschema_suite +283 -0
  67. data/ext/rj_schema/rapidjson/bin/jsonschema/remotes/folder/folderInteger.json +3 -0
  68. data/ext/rj_schema/rapidjson/bin/jsonschema/remotes/integer.json +3 -0
  69. data/ext/rj_schema/rapidjson/bin/jsonschema/remotes/subSchemas.json +8 -0
  70. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/additionalItems.json +82 -0
  71. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/additionalProperties.json +88 -0
  72. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/default.json +49 -0
  73. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/dependencies.json +108 -0
  74. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/disallow.json +80 -0
  75. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/divisibleBy.json +60 -0
  76. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/enum.json +71 -0
  77. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/extends.json +94 -0
  78. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/items.json +46 -0
  79. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/maxItems.json +28 -0
  80. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/maxLength.json +33 -0
  81. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/maximum.json +42 -0
  82. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/minItems.json +28 -0
  83. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/minLength.json +33 -0
  84. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/minimum.json +42 -0
  85. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/bignum.json +107 -0
  86. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/format.json +222 -0
  87. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/jsregex.json +18 -0
  88. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/optional/zeroTerminatedFloats.json +15 -0
  89. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/pattern.json +34 -0
  90. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/patternProperties.json +110 -0
  91. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/properties.json +92 -0
  92. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/ref.json +159 -0
  93. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/refRemote.json +74 -0
  94. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/required.json +53 -0
  95. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/type.json +474 -0
  96. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft3/uniqueItems.json +79 -0
  97. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/additionalItems.json +82 -0
  98. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/additionalProperties.json +88 -0
  99. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/allOf.json +112 -0
  100. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/anyOf.json +68 -0
  101. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/default.json +49 -0
  102. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/definitions.json +32 -0
  103. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/dependencies.json +113 -0
  104. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/enum.json +72 -0
  105. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/items.json +46 -0
  106. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maxItems.json +28 -0
  107. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maxLength.json +33 -0
  108. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maxProperties.json +28 -0
  109. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/maximum.json +42 -0
  110. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minItems.json +28 -0
  111. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minLength.json +33 -0
  112. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minProperties.json +28 -0
  113. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/minimum.json +42 -0
  114. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/multipleOf.json +60 -0
  115. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/not.json +96 -0
  116. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/oneOf.json +68 -0
  117. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/optional/bignum.json +107 -0
  118. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/optional/format.json +148 -0
  119. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/optional/zeroTerminatedFloats.json +15 -0
  120. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/pattern.json +34 -0
  121. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/patternProperties.json +110 -0
  122. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/properties.json +92 -0
  123. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/ref.json +159 -0
  124. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/refRemote.json +74 -0
  125. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/required.json +39 -0
  126. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/type.json +330 -0
  127. data/ext/rj_schema/rapidjson/bin/jsonschema/tests/draft4/uniqueItems.json +79 -0
  128. data/ext/rj_schema/rapidjson/bin/jsonschema/tox.ini +8 -0
  129. data/ext/rj_schema/rapidjson/bin/types/alotofkeys.json +502 -0
  130. data/ext/rj_schema/rapidjson/bin/types/booleans.json +102 -0
  131. data/ext/rj_schema/rapidjson/bin/types/floats.json +102 -0
  132. data/ext/rj_schema/rapidjson/bin/types/guids.json +102 -0
  133. data/ext/rj_schema/rapidjson/bin/types/integers.json +102 -0
  134. data/ext/rj_schema/rapidjson/bin/types/mixed.json +592 -0
  135. data/ext/rj_schema/rapidjson/bin/types/nulls.json +102 -0
  136. data/ext/rj_schema/rapidjson/bin/types/paragraphs.json +102 -0
  137. data/ext/rj_schema/rapidjson/bin/types/readme.txt +1 -0
  138. data/ext/rj_schema/rapidjson/bin/unittestschema/address.json +139 -0
  139. data/ext/rj_schema/rapidjson/bin/unittestschema/allOf_address.json +7 -0
  140. data/ext/rj_schema/rapidjson/bin/unittestschema/anyOf_address.json +7 -0
  141. data/ext/rj_schema/rapidjson/bin/unittestschema/idandref.json +69 -0
  142. data/ext/rj_schema/rapidjson/bin/unittestschema/oneOf_address.json +7 -0
  143. data/ext/rj_schema/rapidjson/contrib/natvis/LICENSE +45 -0
  144. data/ext/rj_schema/rapidjson/contrib/natvis/README.md +7 -0
  145. data/ext/rj_schema/rapidjson/contrib/natvis/rapidjson.natvis +38 -0
  146. data/ext/rj_schema/rapidjson/doc/CMakeLists.txt +27 -0
  147. data/ext/rj_schema/rapidjson/doc/Doxyfile.in +2369 -0
  148. data/ext/rj_schema/rapidjson/doc/Doxyfile.zh-cn.in +2369 -0
  149. data/ext/rj_schema/rapidjson/doc/diagram/architecture.dot +50 -0
  150. data/ext/rj_schema/rapidjson/doc/diagram/architecture.png +0 -0
  151. data/ext/rj_schema/rapidjson/doc/diagram/insituparsing.dot +65 -0
  152. data/ext/rj_schema/rapidjson/doc/diagram/insituparsing.png +0 -0
  153. data/ext/rj_schema/rapidjson/doc/diagram/iterative-parser-states-diagram.dot +62 -0
  154. data/ext/rj_schema/rapidjson/doc/diagram/iterative-parser-states-diagram.png +0 -0
  155. data/ext/rj_schema/rapidjson/doc/diagram/makefile +8 -0
  156. data/ext/rj_schema/rapidjson/doc/diagram/move1.dot +47 -0
  157. data/ext/rj_schema/rapidjson/doc/diagram/move1.png +0 -0
  158. data/ext/rj_schema/rapidjson/doc/diagram/move2.dot +62 -0
  159. data/ext/rj_schema/rapidjson/doc/diagram/move2.png +0 -0
  160. data/ext/rj_schema/rapidjson/doc/diagram/move3.dot +60 -0
  161. data/ext/rj_schema/rapidjson/doc/diagram/move3.png +0 -0
  162. data/ext/rj_schema/rapidjson/doc/diagram/normalparsing.dot +56 -0
  163. data/ext/rj_schema/rapidjson/doc/diagram/normalparsing.png +0 -0
  164. data/ext/rj_schema/rapidjson/doc/diagram/simpledom.dot +54 -0
  165. data/ext/rj_schema/rapidjson/doc/diagram/simpledom.png +0 -0
  166. data/ext/rj_schema/rapidjson/doc/diagram/tutorial.dot +58 -0
  167. data/ext/rj_schema/rapidjson/doc/diagram/tutorial.png +0 -0
  168. data/ext/rj_schema/rapidjson/doc/diagram/utilityclass.dot +73 -0
  169. data/ext/rj_schema/rapidjson/doc/diagram/utilityclass.png +0 -0
  170. data/ext/rj_schema/rapidjson/doc/dom.md +281 -0
  171. data/ext/rj_schema/rapidjson/doc/dom.zh-cn.md +285 -0
  172. data/ext/rj_schema/rapidjson/doc/encoding.md +146 -0
  173. data/ext/rj_schema/rapidjson/doc/encoding.zh-cn.md +152 -0
  174. data/ext/rj_schema/rapidjson/doc/faq.md +289 -0
  175. data/ext/rj_schema/rapidjson/doc/faq.zh-cn.md +290 -0
  176. data/ext/rj_schema/rapidjson/doc/features.md +104 -0
  177. data/ext/rj_schema/rapidjson/doc/features.zh-cn.md +103 -0
  178. data/ext/rj_schema/rapidjson/doc/internals.md +368 -0
  179. data/ext/rj_schema/rapidjson/doc/internals.zh-cn.md +363 -0
  180. data/ext/rj_schema/rapidjson/doc/logo/rapidjson.png +0 -0
  181. data/ext/rj_schema/rapidjson/doc/logo/rapidjson.svg +119 -0
  182. data/ext/rj_schema/rapidjson/doc/misc/DoxygenLayout.xml +194 -0
  183. data/ext/rj_schema/rapidjson/doc/misc/doxygenextra.css +274 -0
  184. data/ext/rj_schema/rapidjson/doc/misc/footer.html +11 -0
  185. data/ext/rj_schema/rapidjson/doc/misc/header.html +24 -0
  186. data/ext/rj_schema/rapidjson/doc/npm.md +31 -0
  187. data/ext/rj_schema/rapidjson/doc/performance.md +26 -0
  188. data/ext/rj_schema/rapidjson/doc/performance.zh-cn.md +26 -0
  189. data/ext/rj_schema/rapidjson/doc/pointer.md +234 -0
  190. data/ext/rj_schema/rapidjson/doc/pointer.zh-cn.md +234 -0
  191. data/ext/rj_schema/rapidjson/doc/sax.md +509 -0
  192. data/ext/rj_schema/rapidjson/doc/sax.zh-cn.md +487 -0
  193. data/ext/rj_schema/rapidjson/doc/schema.md +505 -0
  194. data/ext/rj_schema/rapidjson/doc/schema.zh-cn.md +237 -0
  195. data/ext/rj_schema/rapidjson/doc/stream.md +429 -0
  196. data/ext/rj_schema/rapidjson/doc/stream.zh-cn.md +429 -0
  197. data/ext/rj_schema/rapidjson/doc/tutorial.md +536 -0
  198. data/ext/rj_schema/rapidjson/doc/tutorial.zh-cn.md +535 -0
  199. data/ext/rj_schema/rapidjson/docker/debian/Dockerfile +8 -0
  200. data/ext/rj_schema/rapidjson/example/CMakeLists.txt +46 -0
  201. data/ext/rj_schema/rapidjson/example/archiver/archiver.cpp +292 -0
  202. data/ext/rj_schema/rapidjson/example/archiver/archiver.h +145 -0
  203. data/ext/rj_schema/rapidjson/example/archiver/archivertest.cpp +287 -0
  204. data/ext/rj_schema/rapidjson/example/capitalize/capitalize.cpp +67 -0
  205. data/ext/rj_schema/rapidjson/example/condense/condense.cpp +32 -0
  206. data/ext/rj_schema/rapidjson/example/filterkey/filterkey.cpp +135 -0
  207. data/ext/rj_schema/rapidjson/example/filterkeydom/filterkeydom.cpp +170 -0
  208. data/ext/rj_schema/rapidjson/example/jsonx/jsonx.cpp +207 -0
  209. data/ext/rj_schema/rapidjson/example/lookaheadparser/lookaheadparser.cpp +350 -0
  210. data/ext/rj_schema/rapidjson/example/messagereader/messagereader.cpp +105 -0
  211. data/ext/rj_schema/rapidjson/example/parsebyparts/parsebyparts.cpp +176 -0
  212. data/ext/rj_schema/rapidjson/example/pretty/pretty.cpp +30 -0
  213. data/ext/rj_schema/rapidjson/example/prettyauto/prettyauto.cpp +56 -0
  214. data/ext/rj_schema/rapidjson/example/schemavalidator/schemavalidator.cpp +198 -0
  215. data/ext/rj_schema/rapidjson/example/serialize/serialize.cpp +173 -0
  216. data/ext/rj_schema/rapidjson/example/simpledom/simpledom.cpp +29 -0
  217. data/ext/rj_schema/rapidjson/example/simplepullreader/simplepullreader.cpp +53 -0
  218. data/ext/rj_schema/rapidjson/example/simplereader/simplereader.cpp +42 -0
  219. data/ext/rj_schema/rapidjson/example/simplewriter/simplewriter.cpp +36 -0
  220. data/ext/rj_schema/rapidjson/example/sortkeys/sortkeys.cpp +62 -0
  221. data/ext/rj_schema/rapidjson/example/traverseaspointer.cpp +39 -0
  222. data/ext/rj_schema/rapidjson/example/tutorial/tutorial.cpp +151 -0
  223. data/ext/rj_schema/rapidjson/include/rapidjson/allocators.h +692 -0
  224. data/ext/rj_schema/rapidjson/include/rapidjson/cursorstreamwrapper.h +78 -0
  225. data/ext/rj_schema/rapidjson/include/rapidjson/document.h +3027 -0
  226. data/ext/rj_schema/rapidjson/include/rapidjson/encodedstream.h +299 -0
  227. data/ext/rj_schema/rapidjson/include/rapidjson/encodings.h +716 -0
  228. data/ext/rj_schema/rapidjson/include/rapidjson/error/en.h +122 -0
  229. data/ext/rj_schema/rapidjson/include/rapidjson/error/error.h +216 -0
  230. data/ext/rj_schema/rapidjson/include/rapidjson/filereadstream.h +99 -0
  231. data/ext/rj_schema/rapidjson/include/rapidjson/filewritestream.h +104 -0
  232. data/ext/rj_schema/rapidjson/include/rapidjson/fwd.h +151 -0
  233. data/ext/rj_schema/rapidjson/include/rapidjson/internal/biginteger.h +290 -0
  234. data/ext/rj_schema/rapidjson/include/rapidjson/internal/clzll.h +71 -0
  235. data/ext/rj_schema/rapidjson/include/rapidjson/internal/diyfp.h +257 -0
  236. data/ext/rj_schema/rapidjson/include/rapidjson/internal/dtoa.h +245 -0
  237. data/ext/rj_schema/rapidjson/include/rapidjson/internal/ieee754.h +78 -0
  238. data/ext/rj_schema/rapidjson/include/rapidjson/internal/itoa.h +308 -0
  239. data/ext/rj_schema/rapidjson/include/rapidjson/internal/meta.h +186 -0
  240. data/ext/rj_schema/rapidjson/include/rapidjson/internal/pow10.h +55 -0
  241. data/ext/rj_schema/rapidjson/include/rapidjson/internal/regex.h +739 -0
  242. data/ext/rj_schema/rapidjson/include/rapidjson/internal/stack.h +232 -0
  243. data/ext/rj_schema/rapidjson/include/rapidjson/internal/strfunc.h +83 -0
  244. data/ext/rj_schema/rapidjson/include/rapidjson/internal/strtod.h +290 -0
  245. data/ext/rj_schema/rapidjson/include/rapidjson/internal/swap.h +46 -0
  246. data/ext/rj_schema/rapidjson/include/rapidjson/istreamwrapper.h +128 -0
  247. data/ext/rj_schema/rapidjson/include/rapidjson/memorybuffer.h +70 -0
  248. data/ext/rj_schema/rapidjson/include/rapidjson/memorystream.h +71 -0
  249. data/ext/rj_schema/rapidjson/include/rapidjson/msinttypes/inttypes.h +316 -0
  250. data/ext/rj_schema/rapidjson/include/rapidjson/msinttypes/stdint.h +300 -0
  251. data/ext/rj_schema/rapidjson/include/rapidjson/ostreamwrapper.h +81 -0
  252. data/ext/rj_schema/rapidjson/include/rapidjson/pointer.h +1482 -0
  253. data/ext/rj_schema/rapidjson/include/rapidjson/prettywriter.h +277 -0
  254. data/ext/rj_schema/rapidjson/include/rapidjson/rapidjson.h +741 -0
  255. data/ext/rj_schema/rapidjson/include/rapidjson/reader.h +2244 -0
  256. data/ext/rj_schema/rapidjson/include/rapidjson/schema.h +2795 -0
  257. data/ext/rj_schema/rapidjson/include/rapidjson/stream.h +223 -0
  258. data/ext/rj_schema/rapidjson/include/rapidjson/stringbuffer.h +121 -0
  259. data/ext/rj_schema/rapidjson/include/rapidjson/uri.h +466 -0
  260. data/ext/rj_schema/rapidjson/include/rapidjson/writer.h +710 -0
  261. data/ext/rj_schema/rapidjson/include_dirs.js +2 -0
  262. data/ext/rj_schema/rapidjson/library.json +15 -0
  263. data/ext/rj_schema/rapidjson/license.txt +57 -0
  264. data/ext/rj_schema/rapidjson/package.json +24 -0
  265. data/ext/rj_schema/rapidjson/rapidjson.autopkg +77 -0
  266. data/ext/rj_schema/rapidjson/readme.md +210 -0
  267. data/ext/rj_schema/rapidjson/readme.zh-cn.md +152 -0
  268. data/ext/rj_schema/rapidjson/test/CMakeLists.txt +20 -0
  269. data/ext/rj_schema/rapidjson/test/perftest/CMakeLists.txt +28 -0
  270. data/ext/rj_schema/rapidjson/test/perftest/misctest.cpp +974 -0
  271. data/ext/rj_schema/rapidjson/test/perftest/perftest.cpp +24 -0
  272. data/ext/rj_schema/rapidjson/test/perftest/perftest.h +186 -0
  273. data/ext/rj_schema/rapidjson/test/perftest/platformtest.cpp +166 -0
  274. data/ext/rj_schema/rapidjson/test/perftest/rapidjsontest.cpp +564 -0
  275. data/ext/rj_schema/rapidjson/test/perftest/schematest.cpp +223 -0
  276. data/ext/rj_schema/rapidjson/test/unittest/CMakeLists.txt +95 -0
  277. data/ext/rj_schema/rapidjson/test/unittest/allocatorstest.cpp +292 -0
  278. data/ext/rj_schema/rapidjson/test/unittest/bigintegertest.cpp +138 -0
  279. data/ext/rj_schema/rapidjson/test/unittest/clzlltest.cpp +34 -0
  280. data/ext/rj_schema/rapidjson/test/unittest/cursorstreamwrappertest.cpp +115 -0
  281. data/ext/rj_schema/rapidjson/test/unittest/documenttest.cpp +674 -0
  282. data/ext/rj_schema/rapidjson/test/unittest/dtoatest.cpp +98 -0
  283. data/ext/rj_schema/rapidjson/test/unittest/encodedstreamtest.cpp +313 -0
  284. data/ext/rj_schema/rapidjson/test/unittest/encodingstest.cpp +451 -0
  285. data/ext/rj_schema/rapidjson/test/unittest/filestreamtest.cpp +155 -0
  286. data/ext/rj_schema/rapidjson/test/unittest/fwdtest.cpp +230 -0
  287. data/ext/rj_schema/rapidjson/test/unittest/istreamwrappertest.cpp +181 -0
  288. data/ext/rj_schema/rapidjson/test/unittest/itoatest.cpp +160 -0
  289. data/ext/rj_schema/rapidjson/test/unittest/jsoncheckertest.cpp +143 -0
  290. data/ext/rj_schema/rapidjson/test/unittest/namespacetest.cpp +70 -0
  291. data/ext/rj_schema/rapidjson/test/unittest/ostreamwrappertest.cpp +92 -0
  292. data/ext/rj_schema/rapidjson/test/unittest/platformtest.cpp +40 -0
  293. data/ext/rj_schema/rapidjson/test/unittest/pointertest.cpp +1730 -0
  294. data/ext/rj_schema/rapidjson/test/unittest/prettywritertest.cpp +373 -0
  295. data/ext/rj_schema/rapidjson/test/unittest/readertest.cpp +2228 -0
  296. data/ext/rj_schema/rapidjson/test/unittest/regextest.cpp +639 -0
  297. data/ext/rj_schema/rapidjson/test/unittest/schematest.cpp +2952 -0
  298. data/ext/rj_schema/rapidjson/test/unittest/simdtest.cpp +219 -0
  299. data/ext/rj_schema/rapidjson/test/unittest/strfunctest.cpp +30 -0
  300. data/ext/rj_schema/rapidjson/test/unittest/stringbuffertest.cpp +192 -0
  301. data/ext/rj_schema/rapidjson/test/unittest/strtodtest.cpp +132 -0
  302. data/ext/rj_schema/rapidjson/test/unittest/unittest.cpp +51 -0
  303. data/ext/rj_schema/rapidjson/test/unittest/unittest.h +143 -0
  304. data/ext/rj_schema/rapidjson/test/unittest/uritest.cpp +718 -0
  305. data/ext/rj_schema/rapidjson/test/unittest/valuetest.cpp +1861 -0
  306. data/ext/rj_schema/rapidjson/test/unittest/writertest.cpp +598 -0
  307. data/ext/rj_schema/rapidjson/test/valgrind.supp +17 -0
  308. data/ext/rj_schema/rapidjson/thirdparty/gtest/BUILD.bazel +175 -0
  309. data/ext/rj_schema/rapidjson/thirdparty/gtest/CMakeLists.txt +33 -0
  310. data/ext/rj_schema/rapidjson/thirdparty/gtest/CONTRIBUTING.md +160 -0
  311. data/ext/rj_schema/rapidjson/thirdparty/gtest/LICENSE +28 -0
  312. data/ext/rj_schema/rapidjson/thirdparty/gtest/Makefile.am +14 -0
  313. data/ext/rj_schema/rapidjson/thirdparty/gtest/README.md +122 -0
  314. data/ext/rj_schema/rapidjson/thirdparty/gtest/WORKSPACE +8 -0
  315. data/ext/rj_schema/rapidjson/thirdparty/gtest/appveyor.yml +104 -0
  316. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/build-linux-autotools.sh +44 -0
  317. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/build-linux-bazel.sh +36 -0
  318. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/env-linux.sh +41 -0
  319. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/env-osx.sh +40 -0
  320. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/get-nprocessors.sh +48 -0
  321. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/install-linux.sh +49 -0
  322. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/install-osx.sh +39 -0
  323. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/log-config.sh +51 -0
  324. data/ext/rj_schema/rapidjson/thirdparty/gtest/ci/travis.sh +44 -0
  325. data/ext/rj_schema/rapidjson/thirdparty/gtest/configure.ac +16 -0
  326. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/CHANGES +126 -0
  327. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/CMakeLists.txt +242 -0
  328. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/CONTRIBUTORS +40 -0
  329. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/LICENSE +28 -0
  330. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/Makefile.am +224 -0
  331. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/README.md +344 -0
  332. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/cmake/gmock.pc.in +9 -0
  333. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/cmake/gmock_main.pc.in +9 -0
  334. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/configure.ac +146 -0
  335. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/CheatSheet.md +564 -0
  336. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/CookBook.md +3660 -0
  337. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/DesignDoc.md +280 -0
  338. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/Documentation.md +15 -0
  339. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/ForDummies.md +447 -0
  340. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/FrequentlyAskedQuestions.md +627 -0
  341. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/docs/KnownIssues.md +19 -0
  342. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-actions.h +1262 -0
  343. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-cardinalities.h +147 -0
  344. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-actions.h +2571 -0
  345. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-actions.h.pump +833 -0
  346. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-function-mockers.h +1379 -0
  347. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-function-mockers.h.pump +347 -0
  348. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-matchers.h +2258 -0
  349. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-matchers.h.pump +675 -0
  350. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-nice-strict.h +458 -0
  351. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-generated-nice-strict.h.pump +178 -0
  352. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-matchers.h +5255 -0
  353. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-more-actions.h +246 -0
  354. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-more-matchers.h +91 -0
  355. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock-spec-builders.h +1918 -0
  356. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/gmock.h +95 -0
  357. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/custom/gmock-generated-actions.h +8 -0
  358. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/custom/gmock-generated-actions.h.pump +10 -0
  359. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/custom/gmock-matchers.h +38 -0
  360. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/custom/gmock-port.h +46 -0
  361. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/gmock-generated-internal-utils.h +286 -0
  362. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/gmock-generated-internal-utils.h.pump +136 -0
  363. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/gmock-internal-utils.h +574 -0
  364. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/include/gmock/internal/gmock-port.h +87 -0
  365. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/make/Makefile +101 -0
  366. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2005/gmock.sln +32 -0
  367. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2005/gmock.vcproj +191 -0
  368. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2005/gmock_config.vsprops +15 -0
  369. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2005/gmock_main.vcproj +187 -0
  370. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2005/gmock_test.vcproj +201 -0
  371. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2010/gmock.sln +46 -0
  372. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2010/gmock.vcxproj +145 -0
  373. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2010/gmock_config.props +19 -0
  374. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2010/gmock_main.vcxproj +151 -0
  375. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2010/gmock_test.vcxproj +176 -0
  376. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2015/gmock.sln +46 -0
  377. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2015/gmock.vcxproj +145 -0
  378. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2015/gmock_config.props +19 -0
  379. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2015/gmock_main.vcxproj +151 -0
  380. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/msvc/2015/gmock_test.vcxproj +176 -0
  381. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/fuse_gmock_files.py +240 -0
  382. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/LICENSE +203 -0
  383. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/README +34 -0
  384. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/README.cppclean +115 -0
  385. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/cpp/__init__.py +0 -0
  386. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/cpp/ast.py +1733 -0
  387. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/cpp/gmock_class.py +227 -0
  388. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/cpp/gmock_class_test.py +448 -0
  389. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/cpp/keywords.py +59 -0
  390. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/cpp/tokenize.py +287 -0
  391. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/cpp/utils.py +41 -0
  392. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/generator/gmock_gen.py +31 -0
  393. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/gmock-config.in +303 -0
  394. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/gmock_doctor.py +640 -0
  395. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/upload.py +1387 -0
  396. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/scripts/upload_gmock.py +78 -0
  397. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock-all.cc +47 -0
  398. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock-cardinalities.cc +156 -0
  399. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock-internal-utils.cc +204 -0
  400. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock-matchers.cc +573 -0
  401. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock-spec-builders.cc +883 -0
  402. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock.cc +205 -0
  403. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/src/gmock_main.cc +54 -0
  404. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/BUILD.bazel +123 -0
  405. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-actions_test.cc +1575 -0
  406. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-cardinalities_test.cc +428 -0
  407. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-generated-actions_test.cc +1230 -0
  408. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-generated-function-mockers_test.cc +647 -0
  409. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-generated-internal-utils_test.cc +129 -0
  410. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-generated-matchers_test.cc +1341 -0
  411. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-internal-utils_test.cc +718 -0
  412. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-matchers_test.cc +6767 -0
  413. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-more-actions_test.cc +710 -0
  414. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-nice-strict_test.cc +511 -0
  415. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-port_test.cc +43 -0
  416. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock-spec-builders_test.cc +2771 -0
  417. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_all_test.cc +51 -0
  418. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_ex_test.cc +81 -0
  419. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_leak_test.py +108 -0
  420. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_leak_test_.cc +100 -0
  421. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_link2_test.cc +40 -0
  422. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_link_test.cc +40 -0
  423. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_link_test.h +691 -0
  424. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_output_test.py +183 -0
  425. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_output_test_.cc +310 -0
  426. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_output_test_golden.txt +317 -0
  427. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_stress_test.cc +323 -0
  428. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_test.cc +262 -0
  429. data/ext/rj_schema/rapidjson/thirdparty/gtest/googlemock/test/gmock_test_utils.py +110 -0
  430. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/CHANGES +157 -0
  431. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/CMakeLists.txt +312 -0
  432. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/CONTRIBUTORS +37 -0
  433. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/LICENSE +28 -0
  434. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/Makefile.am +339 -0
  435. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/README.md +341 -0
  436. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/cmake/gtest.pc.in +9 -0
  437. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/cmake/gtest_main.pc.in +10 -0
  438. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/cmake/internal_utils.cmake +280 -0
  439. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/codegear/gtest.cbproj +138 -0
  440. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/codegear/gtest.groupproj +54 -0
  441. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/codegear/gtest_all.cc +38 -0
  442. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/codegear/gtest_link.cc +40 -0
  443. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/codegear/gtest_main.cbproj +82 -0
  444. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/codegear/gtest_unittest.cbproj +88 -0
  445. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/configure.ac +68 -0
  446. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/Pkgconfig.md +146 -0
  447. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/PumpManual.md +177 -0
  448. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/XcodeGuide.md +93 -0
  449. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/advanced.md +2416 -0
  450. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/faq.md +1092 -0
  451. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/primer.md +536 -0
  452. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/docs/samples.md +14 -0
  453. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-death-test.h +342 -0
  454. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-message.h +249 -0
  455. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-param-test.h +1438 -0
  456. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-param-test.h.pump +501 -0
  457. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-printers.h +1082 -0
  458. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-spi.h +231 -0
  459. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-test-part.h +179 -0
  460. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest-typed-test.h +264 -0
  461. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest.h +2332 -0
  462. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest_pred_impl.h +357 -0
  463. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/gtest_prod.h +61 -0
  464. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/custom/gtest-port.h +70 -0
  465. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/custom/gtest-printers.h +42 -0
  466. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/custom/gtest.h +45 -0
  467. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-death-test-internal.h +275 -0
  468. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-filepath.h +205 -0
  469. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-internal.h +1277 -0
  470. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-linked_ptr.h +243 -0
  471. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-param-util-generated.h +5139 -0
  472. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-param-util-generated.h.pump +279 -0
  473. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-param-util.h +723 -0
  474. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-port-arch.h +100 -0
  475. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-port.h +2687 -0
  476. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-string.h +167 -0
  477. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-tuple.h +1020 -0
  478. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-tuple.h.pump +347 -0
  479. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-type-util.h +3347 -0
  480. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/include/gtest/internal/gtest-type-util.h.pump +313 -0
  481. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/m4/acx_pthread.m4 +363 -0
  482. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/m4/gtest.m4 +74 -0
  483. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/make/Makefile +82 -0
  484. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest-md.sln +55 -0
  485. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest-md.vcxproj +149 -0
  486. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest-md.vcxproj.filters +18 -0
  487. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest.sln +55 -0
  488. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest.vcxproj +149 -0
  489. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest.vcxproj.filters +18 -0
  490. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_main-md.vcxproj +154 -0
  491. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_main-md.vcxproj.filters +18 -0
  492. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_main.vcxproj +162 -0
  493. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_main.vcxproj.filters +18 -0
  494. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_prod_test-md.vcxproj +199 -0
  495. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_prod_test-md.vcxproj.filters +26 -0
  496. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_prod_test.vcxproj +191 -0
  497. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_prod_test.vcxproj.filters +26 -0
  498. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_unittest-md.vcxproj +188 -0
  499. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_unittest-md.vcxproj.filters +18 -0
  500. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_unittest.vcxproj +180 -0
  501. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/msvc/2010/gtest_unittest.vcxproj.filters +18 -0
  502. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/prime_tables.h +127 -0
  503. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample1.cc +68 -0
  504. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample1.h +43 -0
  505. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample10_unittest.cc +140 -0
  506. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample1_unittest.cc +154 -0
  507. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample2.cc +56 -0
  508. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample2.h +85 -0
  509. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample2_unittest.cc +110 -0
  510. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample3-inl.h +172 -0
  511. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample3_unittest.cc +152 -0
  512. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample4.cc +46 -0
  513. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample4.h +53 -0
  514. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample4_unittest.cc +49 -0
  515. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample5_unittest.cc +199 -0
  516. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample6_unittest.cc +225 -0
  517. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample7_unittest.cc +118 -0
  518. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample8_unittest.cc +174 -0
  519. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/samples/sample9_unittest.cc +157 -0
  520. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/common.py +83 -0
  521. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/fuse_gtest_files.py +253 -0
  522. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/gen_gtest_pred_impl.py +730 -0
  523. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/gtest-config.in +274 -0
  524. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/pump.py +855 -0
  525. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/release_docs.py +158 -0
  526. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/test/Makefile +59 -0
  527. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/upload.py +1387 -0
  528. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/scripts/upload_gtest.py +78 -0
  529. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-all.cc +48 -0
  530. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-death-test.cc +1536 -0
  531. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-filepath.cc +385 -0
  532. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-internal-inl.h +1175 -0
  533. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-port.cc +1277 -0
  534. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-printers.cc +458 -0
  535. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-test-part.cc +102 -0
  536. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest-typed-test.cc +119 -0
  537. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest.cc +5846 -0
  538. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/src/gtest_main.cc +38 -0
  539. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/BUILD.bazel +396 -0
  540. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-death-test_ex_test.cc +93 -0
  541. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-death-test_test.cc +1424 -0
  542. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-filepath_test.cc +652 -0
  543. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-linked_ptr_test.cc +154 -0
  544. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-listener_test.cc +311 -0
  545. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-message_test.cc +159 -0
  546. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-options_test.cc +213 -0
  547. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-param-test2_test.cc +61 -0
  548. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-param-test_test.cc +1110 -0
  549. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-param-test_test.h +53 -0
  550. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-port_test.cc +1303 -0
  551. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-printers_test.cc +1737 -0
  552. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-test-part_test.cc +208 -0
  553. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-tuple_test.cc +320 -0
  554. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-typed-test2_test.cc +45 -0
  555. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-typed-test_test.cc +380 -0
  556. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-typed-test_test.h +66 -0
  557. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest-unittest-api_test.cc +341 -0
  558. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_all_test.cc +47 -0
  559. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_assert_by_exception_test.cc +119 -0
  560. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_break_on_failure_unittest.py +210 -0
  561. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_break_on_failure_unittest_.cc +87 -0
  562. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_catch_exceptions_test.py +235 -0
  563. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_catch_exceptions_test_.cc +311 -0
  564. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_color_test.py +129 -0
  565. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_color_test_.cc +63 -0
  566. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_env_var_test.py +119 -0
  567. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_env_var_test_.cc +124 -0
  568. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_environment_test.cc +189 -0
  569. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_filter_unittest.py +638 -0
  570. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_filter_unittest_.cc +138 -0
  571. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_help_test.py +172 -0
  572. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_help_test_.cc +46 -0
  573. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_json_outfiles_test.py +162 -0
  574. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_json_output_unittest.py +611 -0
  575. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_json_test_utils.py +60 -0
  576. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_list_tests_unittest.py +207 -0
  577. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_list_tests_unittest_.cc +157 -0
  578. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_main_unittest.cc +45 -0
  579. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_no_test_unittest.cc +56 -0
  580. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_output_test.py +344 -0
  581. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_output_test_.cc +1067 -0
  582. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_output_test_golden_lin.txt +781 -0
  583. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_pred_impl_unittest.cc +2427 -0
  584. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_premature_exit_test.cc +127 -0
  585. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_prod_test.cc +57 -0
  586. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_repeat_test.cc +236 -0
  587. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_shuffle_test.py +325 -0
  588. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_shuffle_test_.cc +103 -0
  589. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_sole_header_test.cc +57 -0
  590. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_stress_test.cc +250 -0
  591. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_test_utils.py +318 -0
  592. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_testbridge_test.py +65 -0
  593. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_testbridge_test_.cc +44 -0
  594. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_throw_on_failure_ex_test.cc +92 -0
  595. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_throw_on_failure_test.py +171 -0
  596. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_throw_on_failure_test_.cc +72 -0
  597. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_uninitialized_test.py +69 -0
  598. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_uninitialized_test_.cc +43 -0
  599. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_unittest.cc +7797 -0
  600. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_outfile1_test_.cc +48 -0
  601. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_outfile2_test_.cc +48 -0
  602. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_outfiles_test.py +140 -0
  603. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_output_unittest.py +378 -0
  604. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_output_unittest_.cc +179 -0
  605. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/gtest_xml_test_utils.py +196 -0
  606. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/production.cc +36 -0
  607. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/test/production.h +55 -0
  608. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Config/DebugProject.xcconfig +30 -0
  609. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Config/FrameworkTarget.xcconfig +17 -0
  610. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Config/General.xcconfig +41 -0
  611. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Config/ReleaseProject.xcconfig +32 -0
  612. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Config/StaticLibraryTarget.xcconfig +18 -0
  613. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Config/TestTarget.xcconfig +8 -0
  614. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Resources/Info.plist +30 -0
  615. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Samples/FrameworkSample/Info.plist +28 -0
  616. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Samples/FrameworkSample/WidgetFramework.xcodeproj/project.pbxproj +457 -0
  617. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Samples/FrameworkSample/runtests.sh +62 -0
  618. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Samples/FrameworkSample/widget.cc +63 -0
  619. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Samples/FrameworkSample/widget.h +59 -0
  620. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Samples/FrameworkSample/widget_test.cc +68 -0
  621. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Scripts/runtests.sh +65 -0
  622. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/Scripts/versiongenerate.py +100 -0
  623. data/ext/rj_schema/rapidjson/thirdparty/gtest/googletest/xcode/gtest.xcodeproj/project.pbxproj +1182 -0
  624. data/ext/rj_schema/rapidjson/travis-doxygen.sh +128 -0
  625. data/ext/rj_schema/rj_schema.cpp +162 -18
  626. data/lib/rj_schema.rb +1 -1
  627. metadata +626 -3
@@ -0,0 +1,2952 @@
1
+ // Tencent is pleased to support the open source community by making RapidJSON available.
2
+ //
3
+ // Copyright (C) 2015 THL A29 Limited, a Tencent company, and Milo Yip.
4
+ //
5
+ // Licensed under the MIT License (the "License"); you may not use this file except
6
+ // in compliance with the License. You may obtain a copy of the License at
7
+ //
8
+ // http://opensource.org/licenses/MIT
9
+ //
10
+ // Unless required by applicable law or agreed to in writing, software distributed
11
+ // under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
12
+ // CONDITIONS OF ANY KIND, either express or implied. See the License for the
13
+ // specific language governing permissions and limitations under the License.
14
+
15
+ #define RAPIDJSON_SCHEMA_VERBOSE 0
16
+ #define RAPIDJSON_HAS_STDSTRING 1
17
+
18
+ #include "unittest.h"
19
+ #include "rapidjson/schema.h"
20
+ #include "rapidjson/stringbuffer.h"
21
+ #include "rapidjson/writer.h"
22
+ #include "rapidjson/error/error.h"
23
+ #include "rapidjson/error/en.h"
24
+
25
+ #ifdef __clang__
26
+ RAPIDJSON_DIAG_PUSH
27
+ RAPIDJSON_DIAG_OFF(variadic-macros)
28
+ #elif defined(_MSC_VER)
29
+ RAPIDJSON_DIAG_PUSH
30
+ RAPIDJSON_DIAG_OFF(4822) // local class member function does not have a body
31
+ #endif
32
+
33
+ using namespace rapidjson;
34
+
35
+ #define TEST_HASHER(json1, json2, expected) \
36
+ {\
37
+ Document d1, d2;\
38
+ d1.Parse(json1);\
39
+ ASSERT_FALSE(d1.HasParseError());\
40
+ d2.Parse(json2);\
41
+ ASSERT_FALSE(d2.HasParseError());\
42
+ internal::Hasher<Value, CrtAllocator> h1, h2;\
43
+ d1.Accept(h1);\
44
+ d2.Accept(h2);\
45
+ ASSERT_TRUE(h1.IsValid());\
46
+ ASSERT_TRUE(h2.IsValid());\
47
+ /*printf("%s: 0x%016llx\n%s: 0x%016llx\n\n", json1, h1.GetHashCode(), json2, h2.GetHashCode());*/\
48
+ EXPECT_TRUE(expected == (h1.GetHashCode() == h2.GetHashCode()));\
49
+ }
50
+
51
+ TEST(SchemaValidator, Hasher) {
52
+ TEST_HASHER("null", "null", true);
53
+
54
+ TEST_HASHER("true", "true", true);
55
+ TEST_HASHER("false", "false", true);
56
+ TEST_HASHER("true", "false", false);
57
+ TEST_HASHER("false", "true", false);
58
+ TEST_HASHER("true", "null", false);
59
+ TEST_HASHER("false", "null", false);
60
+
61
+ TEST_HASHER("1", "1", true);
62
+ TEST_HASHER("2147483648", "2147483648", true); // 2^31 can only be fit in unsigned
63
+ TEST_HASHER("-2147483649", "-2147483649", true); // -2^31 - 1 can only be fit in int64_t
64
+ TEST_HASHER("2147483648", "2147483648", true); // 2^31 can only be fit in unsigned
65
+ TEST_HASHER("4294967296", "4294967296", true); // 2^32 can only be fit in int64_t
66
+ TEST_HASHER("9223372036854775808", "9223372036854775808", true); // 2^63 can only be fit in uint64_t
67
+ TEST_HASHER("1.5", "1.5", true);
68
+ TEST_HASHER("1", "1.0", true);
69
+ TEST_HASHER("1", "-1", false);
70
+ TEST_HASHER("0.0", "-0.0", false);
71
+ TEST_HASHER("1", "true", false);
72
+ TEST_HASHER("0", "false", false);
73
+ TEST_HASHER("0", "null", false);
74
+
75
+ TEST_HASHER("\"\"", "\"\"", true);
76
+ TEST_HASHER("\"\"", "\"\\u0000\"", false);
77
+ TEST_HASHER("\"Hello\"", "\"Hello\"", true);
78
+ TEST_HASHER("\"Hello\"", "\"World\"", false);
79
+ TEST_HASHER("\"Hello\"", "null", false);
80
+ TEST_HASHER("\"Hello\\u0000\"", "\"Hello\"", false);
81
+ TEST_HASHER("\"\"", "null", false);
82
+ TEST_HASHER("\"\"", "true", false);
83
+ TEST_HASHER("\"\"", "false", false);
84
+
85
+ TEST_HASHER("[]", "[ ]", true);
86
+ TEST_HASHER("[1, true, false]", "[1, true, false]", true);
87
+ TEST_HASHER("[1, true, false]", "[1, true]", false);
88
+ TEST_HASHER("[1, 2]", "[2, 1]", false);
89
+ TEST_HASHER("[[1], 2]", "[[1, 2]]", false);
90
+ TEST_HASHER("[1, 2]", "[1, [2]]", false);
91
+ TEST_HASHER("[]", "null", false);
92
+ TEST_HASHER("[]", "true", false);
93
+ TEST_HASHER("[]", "false", false);
94
+ TEST_HASHER("[]", "0", false);
95
+ TEST_HASHER("[]", "0.0", false);
96
+ TEST_HASHER("[]", "\"\"", false);
97
+
98
+ TEST_HASHER("{}", "{ }", true);
99
+ TEST_HASHER("{\"a\":1}", "{\"a\":1}", true);
100
+ TEST_HASHER("{\"a\":1}", "{\"b\":1}", false);
101
+ TEST_HASHER("{\"a\":1}", "{\"a\":2}", false);
102
+ TEST_HASHER("{\"a\":1, \"b\":2}", "{\"b\":2, \"a\":1}", true); // Member order insensitive
103
+ TEST_HASHER("{}", "null", false);
104
+ TEST_HASHER("{}", "false", false);
105
+ TEST_HASHER("{}", "true", false);
106
+ TEST_HASHER("{}", "0", false);
107
+ TEST_HASHER("{}", "0.0", false);
108
+ TEST_HASHER("{}", "\"\"", false);
109
+ }
110
+
111
+ // Test cases following http://spacetelescope.github.io/understanding-json-schema
112
+
113
+ #define VALIDATE(schema, json, expected) \
114
+ {\
115
+ SchemaValidator validator(schema);\
116
+ Document d;\
117
+ /*printf("\n%s\n", json);*/\
118
+ d.Parse(json);\
119
+ EXPECT_FALSE(d.HasParseError());\
120
+ EXPECT_TRUE(expected == d.Accept(validator));\
121
+ EXPECT_TRUE(expected == validator.IsValid());\
122
+ ValidateErrorCode code = validator.GetInvalidSchemaCode();\
123
+ if (expected) {\
124
+ EXPECT_TRUE(code == kValidateErrorNone);\
125
+ EXPECT_TRUE(validator.GetInvalidSchemaKeyword() == 0);\
126
+ }\
127
+ if ((expected) && !validator.IsValid()) {\
128
+ StringBuffer sb;\
129
+ validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);\
130
+ printf("Invalid schema: %s\n", sb.GetString());\
131
+ printf("Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword());\
132
+ printf("Invalid code: %d\n", code);\
133
+ printf("Invalid message: %s\n", GetValidateError_En(code));\
134
+ sb.Clear();\
135
+ validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);\
136
+ printf("Invalid document: %s\n", sb.GetString());\
137
+ sb.Clear();\
138
+ Writer<StringBuffer> w(sb);\
139
+ validator.GetError().Accept(w);\
140
+ printf("Validation error: %s\n", sb.GetString());\
141
+ }\
142
+ }
143
+
144
+ #define INVALIDATE(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error) \
145
+ {\
146
+ INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error, kValidateDefaultFlags, SchemaValidator, Pointer) \
147
+ }
148
+
149
+ #define INVALIDATE_(schema, json, invalidSchemaPointer, invalidSchemaKeyword, invalidDocumentPointer, error, \
150
+ flags, SchemaValidatorType, PointerType) \
151
+ {\
152
+ SchemaValidatorType validator(schema);\
153
+ validator.SetValidateFlags(flags);\
154
+ Document d;\
155
+ /*printf("\n%s\n", json);*/\
156
+ d.Parse(json);\
157
+ EXPECT_FALSE(d.HasParseError());\
158
+ d.Accept(validator);\
159
+ EXPECT_FALSE(validator.IsValid());\
160
+ ValidateErrorCode code = validator.GetInvalidSchemaCode();\
161
+ ASSERT_TRUE(code != kValidateErrorNone);\
162
+ ASSERT_TRUE(strcmp(GetValidateError_En(code), "Unknown error.") != 0);\
163
+ if (validator.GetInvalidSchemaPointer() != PointerType(invalidSchemaPointer)) {\
164
+ StringBuffer sb;\
165
+ validator.GetInvalidSchemaPointer().Stringify(sb);\
166
+ printf("GetInvalidSchemaPointer() Expected: %s Actual: %s\n", invalidSchemaPointer, sb.GetString());\
167
+ ADD_FAILURE();\
168
+ }\
169
+ ASSERT_TRUE(validator.GetInvalidSchemaKeyword() != 0);\
170
+ if (strcmp(validator.GetInvalidSchemaKeyword(), invalidSchemaKeyword) != 0) {\
171
+ printf("GetInvalidSchemaKeyword() Expected: %s Actual %s\n", invalidSchemaKeyword, validator.GetInvalidSchemaKeyword());\
172
+ ADD_FAILURE();\
173
+ }\
174
+ if (validator.GetInvalidDocumentPointer() != PointerType(invalidDocumentPointer)) {\
175
+ StringBuffer sb;\
176
+ validator.GetInvalidDocumentPointer().Stringify(sb);\
177
+ printf("GetInvalidDocumentPointer() Expected: %s Actual: %s\n", invalidDocumentPointer, sb.GetString());\
178
+ ADD_FAILURE();\
179
+ }\
180
+ Document e;\
181
+ e.Parse(error);\
182
+ if (validator.GetError() != e) {\
183
+ StringBuffer sb;\
184
+ Writer<StringBuffer> w(sb);\
185
+ validator.GetError().Accept(w);\
186
+ printf("GetError() Expected: %s Actual: %s\n", error, sb.GetString());\
187
+ ADD_FAILURE();\
188
+ }\
189
+ }
190
+
191
+ TEST(SchemaValidator, Typeless) {
192
+ Document sd;
193
+ sd.Parse("{}");
194
+ SchemaDocument s(sd);
195
+
196
+ VALIDATE(s, "42", true);
197
+ VALIDATE(s, "\"I'm a string\"", true);
198
+ VALIDATE(s, "{ \"an\": [ \"arbitrarily\", \"nested\" ], \"data\": \"structure\" }", true);
199
+ }
200
+
201
+ TEST(SchemaValidator, MultiType) {
202
+ Document sd;
203
+ sd.Parse("{ \"type\": [\"number\", \"string\"] }");
204
+ SchemaDocument s(sd);
205
+
206
+ VALIDATE(s, "42", true);
207
+ VALIDATE(s, "\"Life, the universe, and everything\"", true);
208
+ INVALIDATE(s, "[\"Life\", \"the universe\", \"and everything\"]", "", "type", "",
209
+ "{ \"type\": {"
210
+ " \"errorCode\": 20,"
211
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
212
+ " \"expected\": [\"string\", \"number\"], \"actual\": \"array\""
213
+ "}}");
214
+ }
215
+
216
+ TEST(SchemaValidator, Enum_Typed) {
217
+ Document sd;
218
+ sd.Parse("{ \"type\": \"string\", \"enum\" : [\"red\", \"amber\", \"green\"] }");
219
+ SchemaDocument s(sd);
220
+
221
+ VALIDATE(s, "\"red\"", true);
222
+ INVALIDATE(s, "\"blue\"", "", "enum", "",
223
+ "{ \"enum\": { \"errorCode\": 19, \"instanceRef\": \"#\", \"schemaRef\": \"#\" }}");
224
+ }
225
+
226
+ TEST(SchemaValidator, Enum_Typless) {
227
+ Document sd;
228
+ sd.Parse("{ \"enum\": [\"red\", \"amber\", \"green\", null, 42] }");
229
+ SchemaDocument s(sd);
230
+
231
+ VALIDATE(s, "\"red\"", true);
232
+ VALIDATE(s, "null", true);
233
+ VALIDATE(s, "42", true);
234
+ INVALIDATE(s, "0", "", "enum", "",
235
+ "{ \"enum\": { \"errorCode\": 19, \"instanceRef\": \"#\", \"schemaRef\": \"#\" }}");
236
+ }
237
+
238
+ TEST(SchemaValidator, Enum_InvalidType) {
239
+ Document sd;
240
+ sd.Parse("{ \"type\": \"string\", \"enum\": [\"red\", \"amber\", \"green\", null] }");
241
+ SchemaDocument s(sd);
242
+
243
+ VALIDATE(s, "\"red\"", true);
244
+ INVALIDATE(s, "null", "", "type", "",
245
+ "{ \"type\": {"
246
+ " \"errorCode\": 20,"
247
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
248
+ " \"expected\": [\"string\"], \"actual\": \"null\""
249
+ "}}");
250
+ }
251
+
252
+ TEST(SchemaValidator, AllOf) {
253
+ {
254
+ Document sd;
255
+ sd.Parse("{\"allOf\": [{ \"type\": \"string\" }, { \"type\": \"string\", \"maxLength\": 5 }]}");
256
+ SchemaDocument s(sd);
257
+
258
+ VALIDATE(s, "\"ok\"", true);
259
+ INVALIDATE(s, "\"too long\"", "", "allOf", "",
260
+ "{ \"allOf\": {"
261
+ " \"errors\": ["
262
+ " {},"
263
+ " {\"maxLength\": {\"errorCode\": 6, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\", \"expected\": 5, \"actual\": \"too long\"}}"
264
+ " ],"
265
+ " \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
266
+ "}}");
267
+ }
268
+ {
269
+ Document sd;
270
+ sd.Parse("{\"allOf\": [{ \"type\": \"string\" }, { \"type\": \"number\" } ] }");
271
+ SchemaDocument s(sd);
272
+
273
+ VALIDATE(s, "\"No way\"", false);
274
+ INVALIDATE(s, "-1", "", "allOf", "",
275
+ "{ \"allOf\": {"
276
+ " \"errors\": ["
277
+ " {\"type\": { \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\", \"errorCode\": 20, \"expected\": [\"string\"], \"actual\": \"integer\"}},"
278
+ " {}"
279
+ " ],"
280
+ " \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
281
+ "}}");
282
+ }
283
+ }
284
+
285
+ TEST(SchemaValidator, AnyOf) {
286
+ Document sd;
287
+ sd.Parse("{\"anyOf\": [{ \"type\": \"string\" }, { \"type\": \"number\" } ] }");
288
+ SchemaDocument s(sd);
289
+
290
+ VALIDATE(s, "\"Yes\"", true);
291
+ VALIDATE(s, "42", true);
292
+ INVALIDATE(s, "{ \"Not a\": \"string or number\" }", "", "anyOf", "",
293
+ "{ \"anyOf\": {"
294
+ " \"errorCode\": 24,"
295
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\", "
296
+ " \"errors\": ["
297
+ " { \"type\": {"
298
+ " \"errorCode\": 20,"
299
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#/anyOf/0\","
300
+ " \"expected\": [\"string\"], \"actual\": \"object\""
301
+ " }},"
302
+ " { \"type\": {"
303
+ " \"errorCode\": 20,"
304
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#/anyOf/1\","
305
+ " \"expected\": [\"number\"], \"actual\": \"object\""
306
+ " }}"
307
+ " ]"
308
+ "}}");
309
+ }
310
+
311
+ TEST(SchemaValidator, OneOf) {
312
+ Document sd;
313
+ sd.Parse("{\"oneOf\": [{ \"type\": \"number\", \"multipleOf\": 5 }, { \"type\": \"number\", \"multipleOf\": 3 } ] }");
314
+ SchemaDocument s(sd);
315
+
316
+ VALIDATE(s, "10", true);
317
+ VALIDATE(s, "9", true);
318
+ INVALIDATE(s, "2", "", "oneOf", "",
319
+ "{ \"oneOf\": {"
320
+ " \"errorCode\": 21,"
321
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
322
+ " \"errors\": ["
323
+ " { \"multipleOf\": {"
324
+ " \"errorCode\": 1,"
325
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#/oneOf/0\","
326
+ " \"expected\": 5, \"actual\": 2"
327
+ " }},"
328
+ " { \"multipleOf\": {"
329
+ " \"errorCode\": 1,"
330
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#/oneOf/1\","
331
+ " \"expected\": 3, \"actual\": 2"
332
+ " }}"
333
+ " ]"
334
+ "}}");
335
+ INVALIDATE(s, "15", "", "oneOf", "",
336
+ "{ \"oneOf\": { \"errorCode\": 22, \"instanceRef\": \"#\", \"schemaRef\": \"#\", \"errors\": [{}, {}]}}");
337
+ }
338
+
339
+ TEST(SchemaValidator, Not) {
340
+ Document sd;
341
+ sd.Parse("{\"not\":{ \"type\": \"string\"}}");
342
+ SchemaDocument s(sd);
343
+
344
+ VALIDATE(s, "42", true);
345
+ VALIDATE(s, "{ \"key\": \"value\" }", true);
346
+ INVALIDATE(s, "\"I am a string\"", "", "not", "",
347
+ "{ \"not\": { \"errorCode\": 25, \"instanceRef\": \"#\", \"schemaRef\": \"#\" }}");
348
+ }
349
+
350
+ TEST(SchemaValidator, Ref) {
351
+ Document sd;
352
+ sd.Parse(
353
+ "{"
354
+ " \"$schema\": \"http://json-schema.org/draft-04/schema#\","
355
+ ""
356
+ " \"definitions\": {"
357
+ " \"address\": {"
358
+ " \"type\": \"object\","
359
+ " \"properties\": {"
360
+ " \"street_address\": { \"type\": \"string\" },"
361
+ " \"city\": { \"type\": \"string\" },"
362
+ " \"state\": { \"type\": \"string\" }"
363
+ " },"
364
+ " \"required\": [\"street_address\", \"city\", \"state\"]"
365
+ " }"
366
+ " },"
367
+ " \"type\": \"object\","
368
+ " \"properties\": {"
369
+ " \"billing_address\": { \"$ref\": \"#/definitions/address\" },"
370
+ " \"shipping_address\": { \"$ref\": \"#/definitions/address\" }"
371
+ " }"
372
+ "}");
373
+ SchemaDocument s(sd);
374
+
375
+ VALIDATE(s, "{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\"}, \"billing_address\": {\"street_address\": \"1st Street SE\", \"city\": \"Washington\", \"state\": \"DC\"} }", true);
376
+ }
377
+
378
+ TEST(SchemaValidator, Ref_AllOf) {
379
+ Document sd;
380
+ sd.Parse(
381
+ "{"
382
+ " \"$schema\": \"http://json-schema.org/draft-04/schema#\","
383
+ ""
384
+ " \"definitions\": {"
385
+ " \"address\": {"
386
+ " \"type\": \"object\","
387
+ " \"properties\": {"
388
+ " \"street_address\": { \"type\": \"string\" },"
389
+ " \"city\": { \"type\": \"string\" },"
390
+ " \"state\": { \"type\": \"string\" }"
391
+ " },"
392
+ " \"required\": [\"street_address\", \"city\", \"state\"]"
393
+ " }"
394
+ " },"
395
+ " \"type\": \"object\","
396
+ " \"properties\": {"
397
+ " \"billing_address\": { \"$ref\": \"#/definitions/address\" },"
398
+ " \"shipping_address\": {"
399
+ " \"allOf\": ["
400
+ " { \"$ref\": \"#/definitions/address\" },"
401
+ " { \"properties\":"
402
+ " { \"type\": { \"enum\": [ \"residential\", \"business\" ] } },"
403
+ " \"required\": [\"type\"]"
404
+ " }"
405
+ " ]"
406
+ " }"
407
+ " }"
408
+ "}");
409
+ SchemaDocument s(sd);
410
+
411
+ INVALIDATE(s, "{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\"} }", "/properties/shipping_address", "allOf", "/shipping_address",
412
+ "{ \"allOf\": {"
413
+ " \"errors\": ["
414
+ " {},"
415
+ " {\"required\": {\"errorCode\": 15, \"instanceRef\": \"#/shipping_address\", \"schemaRef\": \"#/properties/shipping_address/allOf/1\", \"missing\": [\"type\"]}}"
416
+ " ],"
417
+ " \"errorCode\":23,\"instanceRef\":\"#/shipping_address\",\"schemaRef\":\"#/properties/shipping_address\""
418
+ "}}");
419
+ VALIDATE(s, "{\"shipping_address\": {\"street_address\": \"1600 Pennsylvania Avenue NW\", \"city\": \"Washington\", \"state\": \"DC\", \"type\": \"business\"} }", true);
420
+ }
421
+
422
+ TEST(SchemaValidator, String) {
423
+ Document sd;
424
+ sd.Parse("{\"type\":\"string\"}");
425
+ SchemaDocument s(sd);
426
+
427
+ VALIDATE(s, "\"I'm a string\"", true);
428
+ INVALIDATE(s, "42", "", "type", "",
429
+ "{ \"type\": {"
430
+ " \"errorCode\": 20,"
431
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
432
+ " \"expected\": [\"string\"], \"actual\": \"integer\""
433
+ "}}");
434
+ INVALIDATE(s, "2147483648", "", "type", "",
435
+ "{ \"type\": {"
436
+ " \"errorCode\": 20,"
437
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
438
+ " \"expected\": [\"string\"], \"actual\": \"integer\""
439
+ "}}"); // 2^31 can only be fit in unsigned
440
+ INVALIDATE(s, "-2147483649", "", "type", "",
441
+ "{ \"type\": {"
442
+ " \"errorCode\": 20,"
443
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
444
+ " \"expected\": [\"string\"], \"actual\": \"integer\""
445
+ "}}"); // -2^31 - 1 can only be fit in int64_t
446
+ INVALIDATE(s, "4294967296", "", "type", "",
447
+ "{ \"type\": {"
448
+ " \"errorCode\": 20,"
449
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
450
+ " \"expected\": [\"string\"], \"actual\": \"integer\""
451
+ "}}"); // 2^32 can only be fit in int64_t
452
+ INVALIDATE(s, "3.1415926", "", "type", "",
453
+ "{ \"type\": {"
454
+ " \"errorCode\": 20,"
455
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
456
+ " \"expected\": [\"string\"], \"actual\": \"number\""
457
+ "}}");
458
+ }
459
+
460
+ TEST(SchemaValidator, String_LengthRange) {
461
+ Document sd;
462
+ sd.Parse("{\"type\":\"string\",\"minLength\":2,\"maxLength\":3}");
463
+ SchemaDocument s(sd);
464
+
465
+ INVALIDATE(s, "\"A\"", "", "minLength", "",
466
+ "{ \"minLength\": {"
467
+ " \"errorCode\": 7,"
468
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
469
+ " \"expected\": 2, \"actual\": \"A\""
470
+ "}}");
471
+ VALIDATE(s, "\"AB\"", true);
472
+ VALIDATE(s, "\"ABC\"", true);
473
+ INVALIDATE(s, "\"ABCD\"", "", "maxLength", "",
474
+ "{ \"maxLength\": {"
475
+ " \"errorCode\": 6,"
476
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
477
+ " \"expected\": 3, \"actual\": \"ABCD\""
478
+ "}}");
479
+ }
480
+
481
+ #if RAPIDJSON_SCHEMA_HAS_REGEX
482
+ TEST(SchemaValidator, String_Pattern) {
483
+ Document sd;
484
+ sd.Parse("{\"type\":\"string\",\"pattern\":\"^(\\\\([0-9]{3}\\\\))?[0-9]{3}-[0-9]{4}$\"}");
485
+ SchemaDocument s(sd);
486
+
487
+ VALIDATE(s, "\"555-1212\"", true);
488
+ VALIDATE(s, "\"(888)555-1212\"", true);
489
+ INVALIDATE(s, "\"(888)555-1212 ext. 532\"", "", "pattern", "",
490
+ "{ \"pattern\": {"
491
+ " \"errorCode\": 8,"
492
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
493
+ " \"actual\": \"(888)555-1212 ext. 532\""
494
+ "}}");
495
+ INVALIDATE(s, "\"(800)FLOWERS\"", "", "pattern", "",
496
+ "{ \"pattern\": {"
497
+ " \"errorCode\": 8,"
498
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
499
+ " \"actual\": \"(800)FLOWERS\""
500
+ "}}");
501
+ }
502
+
503
+ TEST(SchemaValidator, String_Pattern_Invalid) {
504
+ Document sd;
505
+ sd.Parse("{\"type\":\"string\",\"pattern\":\"a{0}\"}"); // TODO: report regex is invalid somehow
506
+ SchemaDocument s(sd);
507
+
508
+ VALIDATE(s, "\"\"", true);
509
+ VALIDATE(s, "\"a\"", true);
510
+ VALIDATE(s, "\"aa\"", true);
511
+ }
512
+ #endif
513
+
514
+ TEST(SchemaValidator, Integer) {
515
+ Document sd;
516
+ sd.Parse("{\"type\":\"integer\"}");
517
+ SchemaDocument s(sd);
518
+
519
+ VALIDATE(s, "42", true);
520
+ VALIDATE(s, "-1", true);
521
+ VALIDATE(s, "2147483648", true); // 2^31 can only be fit in unsigned
522
+ VALIDATE(s, "-2147483649", true); // -2^31 - 1 can only be fit in int64_t
523
+ VALIDATE(s, "2147483648", true); // 2^31 can only be fit in unsigned
524
+ VALIDATE(s, "4294967296", true); // 2^32 can only be fit in int64_t
525
+ INVALIDATE(s, "3.1415926", "", "type", "",
526
+ "{ \"type\": {"
527
+ " \"errorCode\": 20,"
528
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
529
+ " \"expected\": [\"integer\"], \"actual\": \"number\""
530
+ "}}");
531
+ INVALIDATE(s, "\"42\"", "", "type", "",
532
+ "{ \"type\": {"
533
+ " \"errorCode\": 20,"
534
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
535
+ " \"expected\": [\"integer\"], \"actual\": \"string\""
536
+ "}}");
537
+ }
538
+
539
+ TEST(SchemaValidator, Integer_Range) {
540
+ Document sd;
541
+ sd.Parse("{\"type\":\"integer\",\"minimum\":0,\"maximum\":100,\"exclusiveMaximum\":true}");
542
+ SchemaDocument s(sd);
543
+
544
+ INVALIDATE(s, "-1", "", "minimum", "",
545
+ "{ \"minimum\": {"
546
+ " \"errorCode\": 4,"
547
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
548
+ " \"expected\": 0, \"actual\": -1"
549
+ "}}");
550
+ VALIDATE(s, "0", true);
551
+ VALIDATE(s, "10", true);
552
+ VALIDATE(s, "99", true);
553
+ INVALIDATE(s, "100", "", "maximum", "",
554
+ "{ \"maximum\": {"
555
+ " \"errorCode\": 3,"
556
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
557
+ " \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 100"
558
+ "}}");
559
+ INVALIDATE(s, "101", "", "maximum", "",
560
+ "{ \"maximum\": {"
561
+ " \"errorCode\": 3,"
562
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
563
+ " \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 101"
564
+ "}}");
565
+ }
566
+
567
+ TEST(SchemaValidator, Integer_Range64Boundary) {
568
+ Document sd;
569
+ sd.Parse("{\"type\":\"integer\",\"minimum\":-9223372036854775807,\"maximum\":9223372036854775806}");
570
+ SchemaDocument s(sd);
571
+
572
+ INVALIDATE(s, "-9223372036854775808", "", "minimum", "",
573
+ "{ \"minimum\": {"
574
+ " \"errorCode\": 4,"
575
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
576
+ " \"expected\": -9223372036854775807, \"actual\": -9223372036854775808"
577
+ "}}");
578
+ VALIDATE(s, "-9223372036854775807", true);
579
+ VALIDATE(s, "-2147483648", true); // int min
580
+ VALIDATE(s, "0", true);
581
+ VALIDATE(s, "2147483647", true); // int max
582
+ VALIDATE(s, "2147483648", true); // unsigned first
583
+ VALIDATE(s, "4294967295", true); // unsigned max
584
+ VALIDATE(s, "9223372036854775806", true);
585
+ INVALIDATE(s, "9223372036854775807", "", "maximum", "",
586
+ "{ \"maximum\": {"
587
+ " \"errorCode\": 2,"
588
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
589
+ " \"expected\": 9223372036854775806, \"actual\": 9223372036854775807"
590
+ "}}");
591
+ INVALIDATE(s, "18446744073709551615", "", "maximum", "",
592
+ "{ \"maximum\": {"
593
+ " \"errorCode\": 2,"
594
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
595
+ " \"expected\": 9223372036854775806, \"actual\": 18446744073709551615"
596
+ "}}"); // uint64_t max
597
+ }
598
+
599
+ TEST(SchemaValidator, Integer_RangeU64Boundary) {
600
+ Document sd;
601
+ sd.Parse("{\"type\":\"integer\",\"minimum\":9223372036854775808,\"maximum\":18446744073709551614}");
602
+ SchemaDocument s(sd);
603
+
604
+ INVALIDATE(s, "-9223372036854775808", "", "minimum", "",
605
+ "{ \"minimum\": {"
606
+ " \"errorCode\": 4,"
607
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
608
+ " \"expected\": 9223372036854775808, \"actual\": -9223372036854775808"
609
+ "}}");
610
+ INVALIDATE(s, "9223372036854775807", "", "minimum", "",
611
+ "{ \"minimum\": {"
612
+ " \"errorCode\": 4,"
613
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
614
+ " \"expected\": 9223372036854775808, \"actual\": 9223372036854775807"
615
+ "}}");
616
+ INVALIDATE(s, "-2147483648", "", "minimum", "",
617
+ "{ \"minimum\": {"
618
+ " \"errorCode\": 4,"
619
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
620
+ " \"expected\": 9223372036854775808, \"actual\": -2147483648"
621
+ "}}"); // int min
622
+ INVALIDATE(s, "0", "", "minimum", "",
623
+ "{ \"minimum\": {"
624
+ " \"errorCode\": 4,"
625
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
626
+ " \"expected\": 9223372036854775808, \"actual\": 0"
627
+ "}}");
628
+ INVALIDATE(s, "2147483647", "", "minimum", "",
629
+ "{ \"minimum\": {"
630
+ " \"errorCode\": 4,"
631
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
632
+ " \"expected\": 9223372036854775808, \"actual\": 2147483647"
633
+ "}}"); // int max
634
+ INVALIDATE(s, "2147483648", "", "minimum", "",
635
+ "{ \"minimum\": {"
636
+ " \"errorCode\": 4,"
637
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
638
+ " \"expected\": 9223372036854775808, \"actual\": 2147483648"
639
+ "}}"); // unsigned first
640
+ INVALIDATE(s, "4294967295", "", "minimum", "",
641
+ "{ \"minimum\": {"
642
+ " \"errorCode\": 4,"
643
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
644
+ " \"expected\": 9223372036854775808, \"actual\": 4294967295"
645
+ "}}"); // unsigned max
646
+ VALIDATE(s, "9223372036854775808", true);
647
+ VALIDATE(s, "18446744073709551614", true);
648
+ INVALIDATE(s, "18446744073709551615", "", "maximum", "",
649
+ "{ \"maximum\": {"
650
+ " \"errorCode\": 2,"
651
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
652
+ " \"expected\": 18446744073709551614, \"actual\": 18446744073709551615"
653
+ "}}");
654
+ }
655
+
656
+ TEST(SchemaValidator, Integer_Range64BoundaryExclusive) {
657
+ Document sd;
658
+ sd.Parse("{\"type\":\"integer\",\"minimum\":-9223372036854775808,\"maximum\":18446744073709551615,\"exclusiveMinimum\":true,\"exclusiveMaximum\":true}");
659
+ SchemaDocument s(sd);
660
+
661
+ INVALIDATE(s, "-9223372036854775808", "", "minimum", "",
662
+ "{ \"minimum\": {"
663
+ " \"errorCode\": 5,"
664
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
665
+ " \"expected\": -9223372036854775808, \"exclusiveMinimum\": true, "
666
+ " \"actual\": -9223372036854775808"
667
+ "}}");
668
+ VALIDATE(s, "-9223372036854775807", true);
669
+ VALIDATE(s, "18446744073709551614", true);
670
+ INVALIDATE(s, "18446744073709551615", "", "maximum", "",
671
+ "{ \"maximum\": {"
672
+ " \"errorCode\": 3,"
673
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
674
+ " \"expected\": 18446744073709551615, \"exclusiveMaximum\": true, "
675
+ " \"actual\": 18446744073709551615"
676
+ "}}");
677
+ }
678
+
679
+ TEST(SchemaValidator, Integer_MultipleOf) {
680
+ Document sd;
681
+ sd.Parse("{\"type\":\"integer\",\"multipleOf\":10}");
682
+ SchemaDocument s(sd);
683
+
684
+ VALIDATE(s, "0", true);
685
+ VALIDATE(s, "10", true);
686
+ VALIDATE(s, "-10", true);
687
+ VALIDATE(s, "20", true);
688
+ INVALIDATE(s, "23", "", "multipleOf", "",
689
+ "{ \"multipleOf\": {"
690
+ " \"errorCode\": 1,"
691
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
692
+ " \"expected\": 10, \"actual\": 23"
693
+ "}}");
694
+ INVALIDATE(s, "-23", "", "multipleOf", "",
695
+ "{ \"multipleOf\": {"
696
+ " \"errorCode\": 1,"
697
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
698
+ " \"expected\": 10, \"actual\": -23"
699
+ "}}");
700
+ }
701
+
702
+ TEST(SchemaValidator, Integer_MultipleOf64Boundary) {
703
+ Document sd;
704
+ sd.Parse("{\"type\":\"integer\",\"multipleOf\":18446744073709551615}");
705
+ SchemaDocument s(sd);
706
+
707
+ VALIDATE(s, "0", true);
708
+ VALIDATE(s, "18446744073709551615", true);
709
+ INVALIDATE(s, "18446744073709551614", "", "multipleOf", "",
710
+ "{ \"multipleOf\": {"
711
+ " \"errorCode\": 1,"
712
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
713
+ " \"expected\": 18446744073709551615, \"actual\": 18446744073709551614"
714
+ "}}");
715
+ }
716
+
717
+ TEST(SchemaValidator, Number_Range) {
718
+ Document sd;
719
+ sd.Parse("{\"type\":\"number\",\"minimum\":0,\"maximum\":100,\"exclusiveMaximum\":true}");
720
+ SchemaDocument s(sd);
721
+
722
+ INVALIDATE(s, "-1", "", "minimum", "",
723
+ "{ \"minimum\": {"
724
+ " \"errorCode\": 4,"
725
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
726
+ " \"expected\": 0, \"actual\": -1"
727
+ "}}");
728
+ VALIDATE(s, "0", true);
729
+ VALIDATE(s, "0.1", true);
730
+ VALIDATE(s, "10", true);
731
+ VALIDATE(s, "99", true);
732
+ VALIDATE(s, "99.9", true);
733
+ INVALIDATE(s, "100", "", "maximum", "",
734
+ "{ \"maximum\": {"
735
+ " \"errorCode\": 3,"
736
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
737
+ " \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 100"
738
+ "}}");
739
+ INVALIDATE(s, "100.0", "", "maximum", "",
740
+ "{ \"maximum\": {"
741
+ " \"errorCode\": 3,"
742
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
743
+ " \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 100.0"
744
+ "}}");
745
+ INVALIDATE(s, "101.5", "", "maximum", "",
746
+ "{ \"maximum\": {"
747
+ " \"errorCode\": 3,"
748
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
749
+ " \"expected\": 100, \"exclusiveMaximum\": true, \"actual\": 101.5"
750
+ "}}");
751
+ }
752
+
753
+ TEST(SchemaValidator, Number_RangeInt) {
754
+ Document sd;
755
+ sd.Parse("{\"type\":\"number\",\"minimum\":-100,\"maximum\":-1,\"exclusiveMaximum\":true}");
756
+ SchemaDocument s(sd);
757
+
758
+ INVALIDATE(s, "-101", "", "minimum", "",
759
+ "{ \"minimum\": {"
760
+ " \"errorCode\": 4,"
761
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
762
+ " \"expected\": -100, \"actual\": -101"
763
+ "}}");
764
+ INVALIDATE(s, "-100.1", "", "minimum", "",
765
+ "{ \"minimum\": {"
766
+ " \"errorCode\": 4,"
767
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
768
+ " \"expected\": -100, \"actual\": -100.1"
769
+ "}}");
770
+ VALIDATE(s, "-100", true);
771
+ VALIDATE(s, "-2", true);
772
+ INVALIDATE(s, "-1", "", "maximum", "",
773
+ "{ \"maximum\": {"
774
+ " \"errorCode\": 3,"
775
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
776
+ " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": -1"
777
+ "}}");
778
+ INVALIDATE(s, "-0.9", "", "maximum", "",
779
+ "{ \"maximum\": {"
780
+ " \"errorCode\": 3,"
781
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
782
+ " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": -0.9"
783
+ "}}");
784
+ INVALIDATE(s, "0", "", "maximum", "",
785
+ "{ \"maximum\": {"
786
+ " \"errorCode\": 3,"
787
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
788
+ " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 0"
789
+ "}}");
790
+ INVALIDATE(s, "2147483647", "", "maximum", "",
791
+ "{ \"maximum\": {"
792
+ " \"errorCode\": 3,"
793
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
794
+ " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 2147483647"
795
+ "}}"); // int max
796
+ INVALIDATE(s, "2147483648", "", "maximum", "",
797
+ "{ \"maximum\": {"
798
+ " \"errorCode\": 3,"
799
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
800
+ " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 2147483648"
801
+ "}}"); // unsigned first
802
+ INVALIDATE(s, "4294967295", "", "maximum", "",
803
+ "{ \"maximum\": {"
804
+ " \"errorCode\": 3,"
805
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
806
+ " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 4294967295"
807
+ "}}"); // unsigned max
808
+ INVALIDATE(s, "9223372036854775808", "", "maximum", "",
809
+ "{ \"maximum\": {"
810
+ " \"errorCode\": 3,"
811
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
812
+ " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 9223372036854775808"
813
+ "}}");
814
+ INVALIDATE(s, "18446744073709551614", "", "maximum", "",
815
+ "{ \"maximum\": {"
816
+ " \"errorCode\": 3,"
817
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
818
+ " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551614"
819
+ "}}");
820
+ INVALIDATE(s, "18446744073709551615", "", "maximum", "",
821
+ "{ \"maximum\": {"
822
+ " \"errorCode\": 3,"
823
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
824
+ " \"expected\": -1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551615"
825
+ "}}");
826
+ }
827
+
828
+ TEST(SchemaValidator, Number_RangeDouble) {
829
+ Document sd;
830
+ sd.Parse("{\"type\":\"number\",\"minimum\":0.1,\"maximum\":100.1,\"exclusiveMaximum\":true}");
831
+ SchemaDocument s(sd);
832
+
833
+ INVALIDATE(s, "-9223372036854775808", "", "minimum", "",
834
+ "{ \"minimum\": {"
835
+ " \"errorCode\": 4,"
836
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
837
+ " \"expected\": 0.1, \"actual\": -9223372036854775808"
838
+ "}}");
839
+ INVALIDATE(s, "-2147483648", "", "minimum", "",
840
+ "{ \"minimum\": {"
841
+ " \"errorCode\": 4,"
842
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
843
+ " \"expected\": 0.1, \"actual\": -2147483648"
844
+ "}}"); // int min
845
+ INVALIDATE(s, "-1", "", "minimum", "",
846
+ "{ \"minimum\": {"
847
+ " \"errorCode\": 4,"
848
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
849
+ " \"expected\": 0.1, \"actual\": -1"
850
+ "}}");
851
+ VALIDATE(s, "0.1", true);
852
+ VALIDATE(s, "10", true);
853
+ VALIDATE(s, "99", true);
854
+ VALIDATE(s, "100", true);
855
+ INVALIDATE(s, "101", "", "maximum", "",
856
+ "{ \"maximum\": {"
857
+ " \"errorCode\": 3,"
858
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
859
+ " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 101"
860
+ "}}");
861
+ INVALIDATE(s, "101.5", "", "maximum", "",
862
+ "{ \"maximum\": {"
863
+ " \"errorCode\": 3,"
864
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
865
+ " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 101.5"
866
+ "}}");
867
+ INVALIDATE(s, "18446744073709551614", "", "maximum", "",
868
+ "{ \"maximum\": {"
869
+ " \"errorCode\": 3,"
870
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
871
+ " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551614"
872
+ "}}");
873
+ INVALIDATE(s, "18446744073709551615", "", "maximum", "",
874
+ "{ \"maximum\": {"
875
+ " \"errorCode\": 3,"
876
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
877
+ " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551615"
878
+ "}}");
879
+ INVALIDATE(s, "2147483647", "", "maximum", "",
880
+ "{ \"maximum\": {"
881
+ " \"errorCode\": 3,"
882
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
883
+ " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 2147483647"
884
+ "}}"); // int max
885
+ INVALIDATE(s, "2147483648", "", "maximum", "",
886
+ "{ \"maximum\": {"
887
+ " \"errorCode\": 3,"
888
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
889
+ " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 2147483648"
890
+ "}}"); // unsigned first
891
+ INVALIDATE(s, "4294967295", "", "maximum", "",
892
+ "{ \"maximum\": {"
893
+ " \"errorCode\": 3,"
894
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
895
+ " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 4294967295"
896
+ "}}"); // unsigned max
897
+ INVALIDATE(s, "9223372036854775808", "", "maximum", "",
898
+ "{ \"maximum\": {"
899
+ " \"errorCode\": 3,"
900
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
901
+ " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 9223372036854775808"
902
+ "}}");
903
+ INVALIDATE(s, "18446744073709551614", "", "maximum", "",
904
+ "{ \"maximum\": {"
905
+ " \"errorCode\": 3,"
906
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
907
+ " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551614"
908
+ "}}");
909
+ INVALIDATE(s, "18446744073709551615", "", "maximum", "",
910
+ "{ \"maximum\": {"
911
+ " \"errorCode\": 3,"
912
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
913
+ " \"expected\": 100.1, \"exclusiveMaximum\": true, \"actual\": 18446744073709551615"
914
+ "}}");
915
+ }
916
+
917
+ TEST(SchemaValidator, Number_RangeDoubleU64Boundary) {
918
+ Document sd;
919
+ sd.Parse("{\"type\":\"number\",\"minimum\":9223372036854775808.0,\"maximum\":18446744073709550000.0}");
920
+ SchemaDocument s(sd);
921
+
922
+ INVALIDATE(s, "-9223372036854775808", "", "minimum", "",
923
+ "{ \"minimum\": {"
924
+ " \"errorCode\": 4,"
925
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
926
+ " \"expected\": 9223372036854775808.0, \"actual\": -9223372036854775808"
927
+ "}}");
928
+ INVALIDATE(s, "-2147483648", "", "minimum", "",
929
+ "{ \"minimum\": {"
930
+ " \"errorCode\": 4,"
931
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
932
+ " \"expected\": 9223372036854775808.0, \"actual\": -2147483648"
933
+ "}}"); // int min
934
+ INVALIDATE(s, "0", "", "minimum", "",
935
+ "{ \"minimum\": {"
936
+ " \"errorCode\": 4,"
937
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
938
+ " \"expected\": 9223372036854775808.0, \"actual\": 0"
939
+ "}}");
940
+ INVALIDATE(s, "2147483647", "", "minimum", "",
941
+ "{ \"minimum\": {"
942
+ " \"errorCode\": 4,"
943
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
944
+ " \"expected\": 9223372036854775808.0, \"actual\": 2147483647"
945
+ "}}"); // int max
946
+ INVALIDATE(s, "2147483648", "", "minimum", "",
947
+ "{ \"minimum\": {"
948
+ " \"errorCode\": 4,"
949
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
950
+ " \"expected\": 9223372036854775808.0, \"actual\": 2147483648"
951
+ "}}"); // unsigned first
952
+ INVALIDATE(s, "4294967295", "", "minimum", "",
953
+ "{ \"minimum\": {"
954
+ " \"errorCode\": 4,"
955
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
956
+ " \"expected\": 9223372036854775808.0, \"actual\": 4294967295"
957
+ "}}"); // unsigned max
958
+ VALIDATE(s, "9223372036854775808", true);
959
+ VALIDATE(s, "18446744073709540000", true);
960
+ INVALIDATE(s, "18446744073709551615", "", "maximum", "",
961
+ "{ \"maximum\": {"
962
+ " \"errorCode\": 2,"
963
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
964
+ " \"expected\": 18446744073709550000.0, \"actual\": 18446744073709551615"
965
+ "}}");
966
+ }
967
+
968
+ TEST(SchemaValidator, Number_MultipleOf) {
969
+ Document sd;
970
+ sd.Parse("{\"type\":\"number\",\"multipleOf\":10.0}");
971
+ SchemaDocument s(sd);
972
+
973
+ VALIDATE(s, "0", true);
974
+ VALIDATE(s, "10", true);
975
+ VALIDATE(s, "-10", true);
976
+ VALIDATE(s, "20", true);
977
+ INVALIDATE(s, "23", "", "multipleOf", "",
978
+ "{ \"multipleOf\": {"
979
+ " \"errorCode\": 1,"
980
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
981
+ " \"expected\": 10.0, \"actual\": 23"
982
+ "}}");
983
+ INVALIDATE(s, "-2147483648", "", "multipleOf", "",
984
+ "{ \"multipleOf\": {"
985
+ " \"errorCode\": 1,"
986
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
987
+ " \"expected\": 10.0, \"actual\": -2147483648"
988
+ "}}"); // int min
989
+ VALIDATE(s, "-2147483640", true);
990
+ INVALIDATE(s, "2147483647", "", "multipleOf", "",
991
+ "{ \"multipleOf\": {"
992
+ " \"errorCode\": 1,"
993
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
994
+ " \"expected\": 10.0, \"actual\": 2147483647"
995
+ "}}"); // int max
996
+ INVALIDATE(s, "2147483648", "", "multipleOf", "",
997
+ "{ \"multipleOf\": {"
998
+ " \"errorCode\": 1,"
999
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1000
+ " \"expected\": 10.0, \"actual\": 2147483648"
1001
+ "}}"); // unsigned first
1002
+ VALIDATE(s, "2147483650", true);
1003
+ INVALIDATE(s, "4294967295", "", "multipleOf", "",
1004
+ "{ \"multipleOf\": {"
1005
+ " \"errorCode\": 1,"
1006
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1007
+ " \"expected\": 10.0, \"actual\": 4294967295"
1008
+ "}}"); // unsigned max
1009
+ VALIDATE(s, "4294967300", true);
1010
+ }
1011
+
1012
+ TEST(SchemaValidator, Number_MultipleOfOne) {
1013
+ Document sd;
1014
+ sd.Parse("{\"type\":\"number\",\"multipleOf\":1}");
1015
+ SchemaDocument s(sd);
1016
+
1017
+ VALIDATE(s, "42", true);
1018
+ VALIDATE(s, "42.0", true);
1019
+ INVALIDATE(s, "3.1415926", "", "multipleOf", "",
1020
+ "{ \"multipleOf\": {"
1021
+ " \"errorCode\": 1,"
1022
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1023
+ " \"expected\": 1, \"actual\": 3.1415926"
1024
+ "}}");
1025
+ }
1026
+
1027
+ TEST(SchemaValidator, Object) {
1028
+ Document sd;
1029
+ sd.Parse("{\"type\":\"object\"}");
1030
+ SchemaDocument s(sd);
1031
+
1032
+ VALIDATE(s, "{\"key\":\"value\",\"another_key\":\"another_value\"}", true);
1033
+ VALIDATE(s, "{\"Sun\":1.9891e30,\"Jupiter\":1.8986e27,\"Saturn\":5.6846e26,\"Neptune\":10.243e25,\"Uranus\":8.6810e25,\"Earth\":5.9736e24,\"Venus\":4.8685e24,\"Mars\":6.4185e23,\"Mercury\":3.3022e23,\"Moon\":7.349e22,\"Pluto\":1.25e22}", true);
1034
+ INVALIDATE(s, "[\"An\", \"array\", \"not\", \"an\", \"object\"]", "", "type", "",
1035
+ "{ \"type\": {"
1036
+ " \"errorCode\": 20,"
1037
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1038
+ " \"expected\": [\"object\"], \"actual\": \"array\""
1039
+ "}}");
1040
+ INVALIDATE(s, "\"Not an object\"", "", "type", "",
1041
+ "{ \"type\": {"
1042
+ " \"errorCode\": 20,"
1043
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1044
+ " \"expected\": [\"object\"], \"actual\": \"string\""
1045
+ "}}");
1046
+ }
1047
+
1048
+ TEST(SchemaValidator, Object_Properties) {
1049
+ Document sd;
1050
+ sd.Parse(
1051
+ "{"
1052
+ " \"type\": \"object\","
1053
+ " \"properties\" : {"
1054
+ " \"number\": { \"type\": \"number\" },"
1055
+ " \"street_name\" : { \"type\": \"string\" },"
1056
+ " \"street_type\" : { \"type\": \"string\", \"enum\" : [\"Street\", \"Avenue\", \"Boulevard\"] }"
1057
+ " }"
1058
+ "}");
1059
+
1060
+ SchemaDocument s(sd);
1061
+
1062
+ VALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }", true);
1063
+ INVALIDATE(s, "{ \"number\": \"1600\", \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }", "/properties/number", "type", "/number",
1064
+ "{ \"type\": {"
1065
+ " \"errorCode\": 20,"
1066
+ " \"instanceRef\": \"#/number\", \"schemaRef\": \"#/properties/number\","
1067
+ " \"expected\": [\"number\"], \"actual\": \"string\""
1068
+ "}}");
1069
+ INVALIDATE(s, "{ \"number\": \"One\", \"street_name\": \"Microsoft\", \"street_type\": \"Way\" }",
1070
+ "/properties/number", "type", "/number",
1071
+ "{ \"type\": {"
1072
+ " \"errorCode\": 20,"
1073
+ " \"instanceRef\": \"#/number\", \"schemaRef\": \"#/properties/number\","
1074
+ " \"expected\": [\"number\"], \"actual\": \"string\""
1075
+ "}}"); // fail fast
1076
+ VALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\" }", true);
1077
+ VALIDATE(s, "{}", true);
1078
+ VALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\", \"direction\": \"NW\" }", true);
1079
+ }
1080
+
1081
+ TEST(SchemaValidator, Object_AdditionalPropertiesBoolean) {
1082
+ Document sd;
1083
+ sd.Parse(
1084
+ "{"
1085
+ " \"type\": \"object\","
1086
+ " \"properties\" : {"
1087
+ " \"number\": { \"type\": \"number\" },"
1088
+ " \"street_name\" : { \"type\": \"string\" },"
1089
+ " \"street_type\" : { \"type\": \"string\","
1090
+ " \"enum\" : [\"Street\", \"Avenue\", \"Boulevard\"]"
1091
+ " }"
1092
+ " },"
1093
+ " \"additionalProperties\": false"
1094
+ "}");
1095
+
1096
+ SchemaDocument s(sd);
1097
+
1098
+ VALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }", true);
1099
+ INVALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\", \"direction\": \"NW\" }", "", "additionalProperties", "/direction",
1100
+ "{ \"additionalProperties\": {"
1101
+ " \"errorCode\": 16,"
1102
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1103
+ " \"disallowed\": \"direction\""
1104
+ "}}");
1105
+ }
1106
+
1107
+ TEST(SchemaValidator, Object_AdditionalPropertiesObject) {
1108
+ Document sd;
1109
+ sd.Parse(
1110
+ "{"
1111
+ " \"type\": \"object\","
1112
+ " \"properties\" : {"
1113
+ " \"number\": { \"type\": \"number\" },"
1114
+ " \"street_name\" : { \"type\": \"string\" },"
1115
+ " \"street_type\" : { \"type\": \"string\","
1116
+ " \"enum\" : [\"Street\", \"Avenue\", \"Boulevard\"]"
1117
+ " }"
1118
+ " },"
1119
+ " \"additionalProperties\": { \"type\": \"string\" }"
1120
+ "}");
1121
+ SchemaDocument s(sd);
1122
+
1123
+ VALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\" }", true);
1124
+ VALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\", \"direction\": \"NW\" }", true);
1125
+ INVALIDATE(s, "{ \"number\": 1600, \"street_name\": \"Pennsylvania\", \"street_type\": \"Avenue\", \"office_number\": 201 }", "/additionalProperties", "type", "/office_number",
1126
+ "{ \"type\": {"
1127
+ " \"errorCode\": 20,"
1128
+ " \"instanceRef\": \"#/office_number\", \"schemaRef\": \"#/additionalProperties\","
1129
+ " \"expected\": [\"string\"], \"actual\": \"integer\""
1130
+ "}}");
1131
+ }
1132
+
1133
+ TEST(SchemaValidator, Object_Required) {
1134
+ Document sd;
1135
+ sd.Parse(
1136
+ "{"
1137
+ " \"type\": \"object\","
1138
+ " \"properties\" : {"
1139
+ " \"name\": { \"type\": \"string\" },"
1140
+ " \"email\" : { \"type\": \"string\" },"
1141
+ " \"address\" : { \"type\": \"string\" },"
1142
+ " \"telephone\" : { \"type\": \"string\" }"
1143
+ " },"
1144
+ " \"required\":[\"name\", \"email\"]"
1145
+ "}");
1146
+ SchemaDocument s(sd);
1147
+
1148
+ VALIDATE(s, "{ \"name\": \"William Shakespeare\", \"email\" : \"bill@stratford-upon-avon.co.uk\" }", true);
1149
+ VALIDATE(s, "{ \"name\": \"William Shakespeare\", \"email\" : \"bill@stratford-upon-avon.co.uk\", \"address\" : \"Henley Street, Stratford-upon-Avon, Warwickshire, England\", \"authorship\" : \"in question\"}", true);
1150
+ INVALIDATE(s, "{ \"name\": \"William Shakespeare\", \"address\" : \"Henley Street, Stratford-upon-Avon, Warwickshire, England\" }", "", "required", "",
1151
+ "{ \"required\": {"
1152
+ " \"errorCode\": 15,"
1153
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1154
+ " \"missing\": [\"email\"]"
1155
+ "}}");
1156
+ INVALIDATE(s, "{}", "", "required", "",
1157
+ "{ \"required\": {"
1158
+ " \"errorCode\": 15,"
1159
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1160
+ " \"missing\": [\"name\", \"email\"]"
1161
+ "}}");
1162
+ }
1163
+
1164
+ TEST(SchemaValidator, Object_Required_PassWithDefault) {
1165
+ Document sd;
1166
+ sd.Parse(
1167
+ "{"
1168
+ " \"type\": \"object\","
1169
+ " \"properties\" : {"
1170
+ " \"name\": { \"type\": \"string\", \"default\": \"William Shakespeare\" },"
1171
+ " \"email\" : { \"type\": \"string\", \"default\": \"\" },"
1172
+ " \"address\" : { \"type\": \"string\" },"
1173
+ " \"telephone\" : { \"type\": \"string\" }"
1174
+ " },"
1175
+ " \"required\":[\"name\", \"email\"]"
1176
+ "}");
1177
+ SchemaDocument s(sd);
1178
+
1179
+ VALIDATE(s, "{ \"email\" : \"bill@stratford-upon-avon.co.uk\", \"address\" : \"Henley Street, Stratford-upon-Avon, Warwickshire, England\", \"authorship\" : \"in question\"}", true);
1180
+ INVALIDATE(s, "{ \"name\": \"William Shakespeare\", \"address\" : \"Henley Street, Stratford-upon-Avon, Warwickshire, England\" }", "", "required", "",
1181
+ "{ \"required\": {"
1182
+ " \"errorCode\": 15,"
1183
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1184
+ " \"missing\": [\"email\"]"
1185
+ "}}");
1186
+ INVALIDATE(s, "{}", "", "required", "",
1187
+ "{ \"required\": {"
1188
+ " \"errorCode\": 15,"
1189
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1190
+ " \"missing\": [\"email\"]"
1191
+ "}}");
1192
+ }
1193
+
1194
+ TEST(SchemaValidator, Object_PropertiesRange) {
1195
+ Document sd;
1196
+ sd.Parse("{\"type\":\"object\", \"minProperties\":2, \"maxProperties\":3}");
1197
+ SchemaDocument s(sd);
1198
+
1199
+ INVALIDATE(s, "{}", "", "minProperties", "",
1200
+ "{ \"minProperties\": {"
1201
+ " \"errorCode\": 14,"
1202
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1203
+ " \"expected\": 2, \"actual\": 0"
1204
+ "}}");
1205
+ INVALIDATE(s, "{\"a\":0}", "", "minProperties", "",
1206
+ "{ \"minProperties\": {"
1207
+ " \"errorCode\": 14,"
1208
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1209
+ " \"expected\": 2, \"actual\": 1"
1210
+ "}}");
1211
+ VALIDATE(s, "{\"a\":0,\"b\":1}", true);
1212
+ VALIDATE(s, "{\"a\":0,\"b\":1,\"c\":2}", true);
1213
+ INVALIDATE(s, "{\"a\":0,\"b\":1,\"c\":2,\"d\":3}", "", "maxProperties", "",
1214
+ "{ \"maxProperties\": {"
1215
+ " \"errorCode\": 13,"
1216
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\", "
1217
+ " \"expected\": 3, \"actual\": 4"
1218
+ "}}");
1219
+ }
1220
+
1221
+ TEST(SchemaValidator, Object_PropertyDependencies) {
1222
+ Document sd;
1223
+ sd.Parse(
1224
+ "{"
1225
+ " \"type\": \"object\","
1226
+ " \"properties\": {"
1227
+ " \"name\": { \"type\": \"string\" },"
1228
+ " \"credit_card\": { \"type\": \"number\" },"
1229
+ " \"cvv_code\": { \"type\": \"number\" },"
1230
+ " \"billing_address\": { \"type\": \"string\" }"
1231
+ " },"
1232
+ " \"required\": [\"name\"],"
1233
+ " \"dependencies\": {"
1234
+ " \"credit_card\": [\"cvv_code\", \"billing_address\"]"
1235
+ " }"
1236
+ "}");
1237
+ SchemaDocument s(sd);
1238
+
1239
+ VALIDATE(s, "{ \"name\": \"John Doe\", \"credit_card\": 5555555555555555, \"cvv_code\": 777, "
1240
+ "\"billing_address\": \"555 Debtor's Lane\" }", true);
1241
+ INVALIDATE(s, "{ \"name\": \"John Doe\", \"credit_card\": 5555555555555555 }", "", "dependencies", "",
1242
+ "{ \"dependencies\": {"
1243
+ " \"errorCode\": 18,"
1244
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1245
+ " \"errors\": {"
1246
+ " \"credit_card\": {"
1247
+ " \"required\": {"
1248
+ " \"errorCode\": 15,"
1249
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#/dependencies/credit_card\","
1250
+ " \"missing\": [\"cvv_code\", \"billing_address\"]"
1251
+ " } } }"
1252
+ "}}");
1253
+ VALIDATE(s, "{ \"name\": \"John Doe\"}", true);
1254
+ VALIDATE(s, "{ \"name\": \"John Doe\", \"cvv_code\": 777, \"billing_address\": \"555 Debtor's Lane\" }", true);
1255
+ }
1256
+
1257
+ TEST(SchemaValidator, Object_SchemaDependencies) {
1258
+ Document sd;
1259
+ sd.Parse(
1260
+ "{"
1261
+ " \"type\": \"object\","
1262
+ " \"properties\" : {"
1263
+ " \"name\": { \"type\": \"string\" },"
1264
+ " \"credit_card\" : { \"type\": \"number\" }"
1265
+ " },"
1266
+ " \"required\" : [\"name\"],"
1267
+ " \"dependencies\" : {"
1268
+ " \"credit_card\": {"
1269
+ " \"properties\": {"
1270
+ " \"billing_address\": { \"type\": \"string\" }"
1271
+ " },"
1272
+ " \"required\" : [\"billing_address\"]"
1273
+ " }"
1274
+ " }"
1275
+ "}");
1276
+ SchemaDocument s(sd);
1277
+
1278
+ VALIDATE(s, "{\"name\": \"John Doe\", \"credit_card\" : 5555555555555555,\"billing_address\" : \"555 Debtor's Lane\"}", true);
1279
+ INVALIDATE(s, "{\"name\": \"John Doe\", \"credit_card\" : 5555555555555555 }", "", "dependencies", "",
1280
+ "{ \"dependencies\": {"
1281
+ " \"errorCode\": 18,"
1282
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1283
+ " \"errors\": {"
1284
+ " \"credit_card\": {"
1285
+ " \"required\": {"
1286
+ " \"errorCode\": 15,"
1287
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#/dependencies/credit_card\","
1288
+ " \"missing\": [\"billing_address\"]"
1289
+ " } } }"
1290
+ "}}");
1291
+ VALIDATE(s, "{\"name\": \"John Doe\", \"billing_address\" : \"555 Debtor's Lane\"}", true);
1292
+ }
1293
+
1294
+ #if RAPIDJSON_SCHEMA_HAS_REGEX
1295
+ TEST(SchemaValidator, Object_PatternProperties) {
1296
+ Document sd;
1297
+ sd.Parse(
1298
+ "{"
1299
+ " \"type\": \"object\","
1300
+ " \"patternProperties\": {"
1301
+ " \"^S_\": { \"type\": \"string\" },"
1302
+ " \"^I_\": { \"type\": \"integer\" }"
1303
+ " }"
1304
+ "}");
1305
+ SchemaDocument s(sd);
1306
+
1307
+ VALIDATE(s, "{ \"S_25\": \"This is a string\" }", true);
1308
+ VALIDATE(s, "{ \"I_0\": 42 }", true);
1309
+ INVALIDATE(s, "{ \"S_0\": 42 }", "", "patternProperties", "/S_0",
1310
+ "{ \"type\": {"
1311
+ " \"errorCode\": 20,"
1312
+ " \"instanceRef\": \"#/S_0\", \"schemaRef\": \"#/patternProperties/%5ES_\","
1313
+ " \"expected\": [\"string\"], \"actual\": \"integer\""
1314
+ "}}");
1315
+ INVALIDATE(s, "{ \"I_42\": \"This is a string\" }", "", "patternProperties", "/I_42",
1316
+ "{ \"type\": {"
1317
+ " \"errorCode\": 20,"
1318
+ " \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/patternProperties/%5EI_\","
1319
+ " \"expected\": [\"integer\"], \"actual\": \"string\""
1320
+ "}}");
1321
+ VALIDATE(s, "{ \"keyword\": \"value\" }", true);
1322
+ }
1323
+
1324
+ TEST(SchemaValidator, Object_PatternProperties_ErrorConflict) {
1325
+ Document sd;
1326
+ sd.Parse(
1327
+ "{"
1328
+ " \"type\": \"object\","
1329
+ " \"patternProperties\": {"
1330
+ " \"^I_\": { \"multipleOf\": 5 },"
1331
+ " \"30$\": { \"multipleOf\": 6 }"
1332
+ " }"
1333
+ "}");
1334
+ SchemaDocument s(sd);
1335
+
1336
+ VALIDATE(s, "{ \"I_30\": 30 }", true);
1337
+ INVALIDATE(s, "{ \"I_30\": 7 }", "", "patternProperties", "/I_30",
1338
+ "{ \"multipleOf\": ["
1339
+ " {"
1340
+ " \"errorCode\": 1,"
1341
+ " \"instanceRef\": \"#/I_30\", \"schemaRef\": \"#/patternProperties/%5EI_\","
1342
+ " \"expected\": 5, \"actual\": 7"
1343
+ " }, {"
1344
+ " \"errorCode\": 1,"
1345
+ " \"instanceRef\": \"#/I_30\", \"schemaRef\": \"#/patternProperties/30%24\","
1346
+ " \"expected\": 6, \"actual\": 7"
1347
+ " }"
1348
+ "]}");
1349
+ }
1350
+
1351
+ TEST(SchemaValidator, Object_Properties_PatternProperties) {
1352
+ Document sd;
1353
+ sd.Parse(
1354
+ "{"
1355
+ " \"type\": \"object\","
1356
+ " \"properties\": {"
1357
+ " \"I_42\": { \"type\": \"integer\", \"minimum\": 73 }"
1358
+ " },"
1359
+ " \"patternProperties\": {"
1360
+ " \"^I_\": { \"type\": \"integer\", \"multipleOf\": 6 }"
1361
+ " }"
1362
+ "}");
1363
+ SchemaDocument s(sd);
1364
+
1365
+ VALIDATE(s, "{ \"I_6\": 6 }", true);
1366
+ VALIDATE(s, "{ \"I_42\": 78 }", true);
1367
+ INVALIDATE(s, "{ \"I_42\": 42 }", "", "patternProperties", "/I_42",
1368
+ "{ \"minimum\": {"
1369
+ " \"errorCode\": 4,"
1370
+ " \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/properties/I_42\","
1371
+ " \"expected\": 73, \"actual\": 42"
1372
+ "}}");
1373
+ INVALIDATE(s, "{ \"I_42\": 7 }", "", "patternProperties", "/I_42",
1374
+ "{ \"minimum\": {"
1375
+ " \"errorCode\": 4,"
1376
+ " \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/properties/I_42\","
1377
+ " \"expected\": 73, \"actual\": 7"
1378
+ " },"
1379
+ " \"multipleOf\": {"
1380
+ " \"errorCode\": 1,"
1381
+ " \"instanceRef\": \"#/I_42\", \"schemaRef\": \"#/patternProperties/%5EI_\","
1382
+ " \"expected\": 6, \"actual\": 7"
1383
+ " }"
1384
+ "}");
1385
+ }
1386
+
1387
+ TEST(SchemaValidator, Object_PatternProperties_AdditionalPropertiesObject) {
1388
+ Document sd;
1389
+ sd.Parse(
1390
+ "{"
1391
+ " \"type\": \"object\","
1392
+ " \"properties\": {"
1393
+ " \"builtin\": { \"type\": \"number\" }"
1394
+ " },"
1395
+ " \"patternProperties\": {"
1396
+ " \"^S_\": { \"type\": \"string\" },"
1397
+ " \"^I_\": { \"type\": \"integer\" }"
1398
+ " },"
1399
+ " \"additionalProperties\": { \"type\": \"string\" }"
1400
+ "}");
1401
+ SchemaDocument s(sd);
1402
+
1403
+ VALIDATE(s, "{ \"builtin\": 42 }", true);
1404
+ VALIDATE(s, "{ \"keyword\": \"value\" }", true);
1405
+ INVALIDATE(s, "{ \"keyword\": 42 }", "/additionalProperties", "type", "/keyword",
1406
+ "{ \"type\": {"
1407
+ " \"errorCode\": 20,"
1408
+ " \"instanceRef\": \"#/keyword\", \"schemaRef\": \"#/additionalProperties\","
1409
+ " \"expected\": [\"string\"], \"actual\": \"integer\""
1410
+ "}}");
1411
+ }
1412
+
1413
+ // Replaces test Issue285 and tests failure as well as success
1414
+ TEST(SchemaValidator, Object_PatternProperties_AdditionalPropertiesBoolean) {
1415
+ Document sd;
1416
+ sd.Parse(
1417
+ "{"
1418
+ " \"type\": \"object\","
1419
+ " \"patternProperties\": {"
1420
+ " \"^S_\": { \"type\": \"string\" },"
1421
+ " \"^I_\": { \"type\": \"integer\" }"
1422
+ " },"
1423
+ " \"additionalProperties\": false"
1424
+ "}");
1425
+ SchemaDocument s(sd);
1426
+
1427
+ VALIDATE(s, "{ \"S_25\": \"This is a string\" }", true);
1428
+ VALIDATE(s, "{ \"I_0\": 42 }", true);
1429
+ INVALIDATE(s, "{ \"keyword\": \"value\" }", "", "additionalProperties", "/keyword",
1430
+ "{ \"additionalProperties\": {"
1431
+ " \"errorCode\": 16,"
1432
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1433
+ " \"disallowed\": \"keyword\""
1434
+ "}}");
1435
+ }
1436
+ #endif
1437
+
1438
+ TEST(SchemaValidator, Array) {
1439
+ Document sd;
1440
+ sd.Parse("{\"type\":\"array\"}");
1441
+ SchemaDocument s(sd);
1442
+
1443
+ VALIDATE(s, "[1, 2, 3, 4, 5]", true);
1444
+ VALIDATE(s, "[3, \"different\", { \"types\" : \"of values\" }]", true);
1445
+ INVALIDATE(s, "{\"Not\": \"an array\"}", "", "type", "",
1446
+ "{ \"type\": {"
1447
+ " \"errorCode\": 20,"
1448
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1449
+ " \"expected\": [\"array\"], \"actual\": \"object\""
1450
+ "}}");
1451
+ }
1452
+
1453
+ TEST(SchemaValidator, Array_ItemsList) {
1454
+ Document sd;
1455
+ sd.Parse(
1456
+ "{"
1457
+ " \"type\": \"array\","
1458
+ " \"items\" : {"
1459
+ " \"type\": \"number\""
1460
+ " }"
1461
+ "}");
1462
+ SchemaDocument s(sd);
1463
+
1464
+ VALIDATE(s, "[1, 2, 3, 4, 5]", true);
1465
+ INVALIDATE(s, "[1, 2, \"3\", 4, 5]", "/items", "type", "/2",
1466
+ "{ \"type\": {"
1467
+ " \"errorCode\": 20,"
1468
+ " \"instanceRef\": \"#/2\", \"schemaRef\": \"#/items\","
1469
+ " \"expected\": [\"number\"], \"actual\": \"string\""
1470
+ "}}");
1471
+ VALIDATE(s, "[]", true);
1472
+ }
1473
+
1474
+ TEST(SchemaValidator, Array_ItemsTuple) {
1475
+ Document sd;
1476
+ sd.Parse(
1477
+ "{"
1478
+ " \"type\": \"array\","
1479
+ " \"items\": ["
1480
+ " {"
1481
+ " \"type\": \"number\""
1482
+ " },"
1483
+ " {"
1484
+ " \"type\": \"string\""
1485
+ " },"
1486
+ " {"
1487
+ " \"type\": \"string\","
1488
+ " \"enum\": [\"Street\", \"Avenue\", \"Boulevard\"]"
1489
+ " },"
1490
+ " {"
1491
+ " \"type\": \"string\","
1492
+ " \"enum\": [\"NW\", \"NE\", \"SW\", \"SE\"]"
1493
+ " }"
1494
+ " ]"
1495
+ "}");
1496
+ SchemaDocument s(sd);
1497
+
1498
+ VALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\", \"NW\"]", true);
1499
+ INVALIDATE(s, "[24, \"Sussex\", \"Drive\"]", "/items/2", "enum", "/2",
1500
+ "{ \"enum\": { \"errorCode\": 19, \"instanceRef\": \"#/2\", \"schemaRef\": \"#/items/2\" }}");
1501
+ INVALIDATE(s, "[\"Palais de l'Elysee\"]", "/items/0", "type", "/0",
1502
+ "{ \"type\": {"
1503
+ " \"errorCode\": 20,"
1504
+ " \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items/0\","
1505
+ " \"expected\": [\"number\"], \"actual\": \"string\""
1506
+ "}}");
1507
+ INVALIDATE(s, "[\"Twenty-four\", \"Sussex\", \"Drive\"]", "/items/0", "type", "/0",
1508
+ "{ \"type\": {"
1509
+ " \"errorCode\": 20,"
1510
+ " \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items/0\","
1511
+ " \"expected\": [\"number\"], \"actual\": \"string\""
1512
+ "}}"); // fail fast
1513
+ VALIDATE(s, "[10, \"Downing\", \"Street\"]", true);
1514
+ VALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\", \"NW\", \"Washington\"]", true);
1515
+ }
1516
+
1517
+ TEST(SchemaValidator, Array_AdditionalItems) {
1518
+ Document sd;
1519
+ sd.Parse(
1520
+ "{"
1521
+ " \"type\": \"array\","
1522
+ " \"items\": ["
1523
+ " {"
1524
+ " \"type\": \"number\""
1525
+ " },"
1526
+ " {"
1527
+ " \"type\": \"string\""
1528
+ " },"
1529
+ " {"
1530
+ " \"type\": \"string\","
1531
+ " \"enum\": [\"Street\", \"Avenue\", \"Boulevard\"]"
1532
+ " },"
1533
+ " {"
1534
+ " \"type\": \"string\","
1535
+ " \"enum\": [\"NW\", \"NE\", \"SW\", \"SE\"]"
1536
+ " }"
1537
+ " ],"
1538
+ " \"additionalItems\": false"
1539
+ "}");
1540
+ SchemaDocument s(sd);
1541
+
1542
+ VALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\", \"NW\"]", true);
1543
+ VALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\"]", true);
1544
+ INVALIDATE(s, "[1600, \"Pennsylvania\", \"Avenue\", \"NW\", \"Washington\"]", "", "additionalItems", "/4",
1545
+ "{ \"additionalItems\": {"
1546
+ " \"errorCode\": 12,"
1547
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1548
+ " \"disallowed\": 4"
1549
+ "}}");
1550
+ }
1551
+
1552
+ TEST(SchemaValidator, Array_ItemsRange) {
1553
+ Document sd;
1554
+ sd.Parse("{\"type\": \"array\",\"minItems\": 2,\"maxItems\" : 3}");
1555
+ SchemaDocument s(sd);
1556
+
1557
+ INVALIDATE(s, "[]", "", "minItems", "",
1558
+ "{ \"minItems\": {"
1559
+ " \"errorCode\": 10,"
1560
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1561
+ " \"expected\": 2, \"actual\": 0"
1562
+ "}}");
1563
+ INVALIDATE(s, "[1]", "", "minItems", "",
1564
+ "{ \"minItems\": {"
1565
+ " \"errorCode\": 10,"
1566
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1567
+ " \"expected\": 2, \"actual\": 1"
1568
+ "}}");
1569
+ VALIDATE(s, "[1, 2]", true);
1570
+ VALIDATE(s, "[1, 2, 3]", true);
1571
+ INVALIDATE(s, "[1, 2, 3, 4]", "", "maxItems", "",
1572
+ "{ \"maxItems\": {"
1573
+ " \"errorCode\": 9,"
1574
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1575
+ " \"expected\": 3, \"actual\": 4"
1576
+ "}}");
1577
+ }
1578
+
1579
+ TEST(SchemaValidator, Array_UniqueItems) {
1580
+ Document sd;
1581
+ sd.Parse("{\"type\": \"array\", \"uniqueItems\": true}");
1582
+ SchemaDocument s(sd);
1583
+
1584
+ VALIDATE(s, "[1, 2, 3, 4, 5]", true);
1585
+ INVALIDATE(s, "[1, 2, 3, 3, 4]", "", "uniqueItems", "/3",
1586
+ "{ \"uniqueItems\": {"
1587
+ " \"errorCode\": 11,"
1588
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1589
+ " \"duplicates\": [2, 3]"
1590
+ "}}");
1591
+ INVALIDATE(s, "[1, 2, 3, 3, 3]", "", "uniqueItems", "/3",
1592
+ "{ \"uniqueItems\": {"
1593
+ " \"errorCode\": 11,"
1594
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1595
+ " \"duplicates\": [2, 3]"
1596
+ "}}"); // fail fast
1597
+ VALIDATE(s, "[]", true);
1598
+ }
1599
+
1600
+ TEST(SchemaValidator, Boolean) {
1601
+ Document sd;
1602
+ sd.Parse("{\"type\":\"boolean\"}");
1603
+ SchemaDocument s(sd);
1604
+
1605
+ VALIDATE(s, "true", true);
1606
+ VALIDATE(s, "false", true);
1607
+ INVALIDATE(s, "\"true\"", "", "type", "",
1608
+ "{ \"type\": {"
1609
+ " \"errorCode\": 20,"
1610
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1611
+ " \"expected\": [\"boolean\"], \"actual\": \"string\""
1612
+ "}}");
1613
+ INVALIDATE(s, "0", "", "type", "",
1614
+ "{ \"type\": {"
1615
+ " \"errorCode\": 20,"
1616
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1617
+ " \"expected\": [\"boolean\"], \"actual\": \"integer\""
1618
+ "}}");
1619
+ }
1620
+
1621
+ TEST(SchemaValidator, Null) {
1622
+ Document sd;
1623
+ sd.Parse("{\"type\":\"null\"}");
1624
+ SchemaDocument s(sd);
1625
+
1626
+ VALIDATE(s, "null", true);
1627
+ INVALIDATE(s, "false", "", "type", "",
1628
+ "{ \"type\": {"
1629
+ " \"errorCode\": 20,"
1630
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1631
+ " \"expected\": [\"null\"], \"actual\": \"boolean\""
1632
+ "}}");
1633
+ INVALIDATE(s, "0", "", "type", "",
1634
+ "{ \"type\": {"
1635
+ " \"errorCode\": 20,"
1636
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1637
+ " \"expected\": [\"null\"], \"actual\": \"integer\""
1638
+ "}}");
1639
+ INVALIDATE(s, "\"\"", "", "type", "",
1640
+ "{ \"type\": {"
1641
+ " \"errorCode\": 20,"
1642
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
1643
+ " \"expected\": [\"null\"], \"actual\": \"string\""
1644
+ "}}");
1645
+ }
1646
+
1647
+ // Additional tests
1648
+
1649
+ TEST(SchemaValidator, ObjectInArray) {
1650
+ Document sd;
1651
+ sd.Parse("{\"type\":\"array\", \"items\": { \"type\":\"string\" }}");
1652
+ SchemaDocument s(sd);
1653
+
1654
+ VALIDATE(s, "[\"a\"]", true);
1655
+ INVALIDATE(s, "[1]", "/items", "type", "/0",
1656
+ "{ \"type\": {"
1657
+ " \"errorCode\": 20,"
1658
+ " \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items\","
1659
+ " \"expected\": [\"string\"], \"actual\": \"integer\""
1660
+ "}}");
1661
+ INVALIDATE(s, "[{}]", "/items", "type", "/0",
1662
+ "{ \"type\": {"
1663
+ " \"errorCode\": 20,"
1664
+ " \"instanceRef\": \"#/0\", \"schemaRef\": \"#/items\","
1665
+ " \"expected\": [\"string\"], \"actual\": \"object\""
1666
+ "}}");
1667
+ }
1668
+
1669
+ TEST(SchemaValidator, MultiTypeInObject) {
1670
+ Document sd;
1671
+ sd.Parse(
1672
+ "{"
1673
+ " \"type\":\"object\","
1674
+ " \"properties\": {"
1675
+ " \"tel\" : {"
1676
+ " \"type\":[\"integer\", \"string\"]"
1677
+ " }"
1678
+ " }"
1679
+ "}");
1680
+ SchemaDocument s(sd);
1681
+
1682
+ VALIDATE(s, "{ \"tel\": 999 }", true);
1683
+ VALIDATE(s, "{ \"tel\": \"123-456\" }", true);
1684
+ INVALIDATE(s, "{ \"tel\": true }", "/properties/tel", "type", "/tel",
1685
+ "{ \"type\": {"
1686
+ " \"errorCode\": 20,"
1687
+ " \"instanceRef\": \"#/tel\", \"schemaRef\": \"#/properties/tel\","
1688
+ " \"expected\": [\"string\", \"integer\"], \"actual\": \"boolean\""
1689
+ "}}");
1690
+ }
1691
+
1692
+ TEST(SchemaValidator, MultiTypeWithObject) {
1693
+ Document sd;
1694
+ sd.Parse(
1695
+ "{"
1696
+ " \"type\": [\"object\",\"string\"],"
1697
+ " \"properties\": {"
1698
+ " \"tel\" : {"
1699
+ " \"type\": \"integer\""
1700
+ " }"
1701
+ " }"
1702
+ "}");
1703
+ SchemaDocument s(sd);
1704
+
1705
+ VALIDATE(s, "\"Hello\"", true);
1706
+ VALIDATE(s, "{ \"tel\": 999 }", true);
1707
+ INVALIDATE(s, "{ \"tel\": \"fail\" }", "/properties/tel", "type", "/tel",
1708
+ "{ \"type\": {"
1709
+ " \"errorCode\": 20,"
1710
+ " \"instanceRef\": \"#/tel\", \"schemaRef\": \"#/properties/tel\","
1711
+ " \"expected\": [\"integer\"], \"actual\": \"string\""
1712
+ "}}");
1713
+ }
1714
+
1715
+ TEST(SchemaValidator, AllOf_Nested) {
1716
+ Document sd;
1717
+ sd.Parse(
1718
+ "{"
1719
+ " \"allOf\": ["
1720
+ " { \"type\": \"string\", \"minLength\": 2 },"
1721
+ " { \"type\": \"string\", \"maxLength\": 5 },"
1722
+ " { \"allOf\": [ { \"enum\" : [\"ok\", \"okay\", \"OK\", \"o\"] }, { \"enum\" : [\"ok\", \"OK\", \"o\"]} ] }"
1723
+ " ]"
1724
+ "}");
1725
+ SchemaDocument s(sd);
1726
+
1727
+ VALIDATE(s, "\"ok\"", true);
1728
+ VALIDATE(s, "\"OK\"", true);
1729
+ INVALIDATE(s, "\"okay\"", "", "allOf", "",
1730
+ "{ \"allOf\": {"
1731
+ " \"errors\": ["
1732
+ " {},{},"
1733
+ " { \"allOf\": {"
1734
+ " \"errors\": ["
1735
+ " {},"
1736
+ " { \"enum\": {\"errorCode\": 19, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\" }}"
1737
+ " ],"
1738
+ " \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\""
1739
+ " }}],"
1740
+ " \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
1741
+ "}}");
1742
+ INVALIDATE(s, "\"o\"", "", "allOf", "",
1743
+ "{ \"allOf\": {"
1744
+ " \"errors\": ["
1745
+ " { \"minLength\": {\"actual\": \"o\", \"expected\": 2, \"errorCode\": 7, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\" }},"
1746
+ " {},{}"
1747
+ " ],"
1748
+ " \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
1749
+ "}}");
1750
+ INVALIDATE(s, "\"n\"", "", "allOf", "",
1751
+ "{ \"allOf\": {"
1752
+ " \"errors\": ["
1753
+ " { \"minLength\": {\"actual\": \"n\", \"expected\": 2, \"errorCode\": 7, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\" }},"
1754
+ " {},"
1755
+ " { \"allOf\": {"
1756
+ " \"errors\": ["
1757
+ " { \"enum\": {\"errorCode\": 19 ,\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"}},"
1758
+ " { \"enum\": {\"errorCode\": 19, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}}"
1759
+ " ],"
1760
+ " \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\""
1761
+ " }}"
1762
+ " ],"
1763
+ " \"errorCode\":23,\"instanceRef\":\"#\",\"schemaRef\":\"#\""
1764
+ "}}");
1765
+ INVALIDATE(s, "\"too long\"", "", "allOf", "",
1766
+ "{ \"allOf\": {"
1767
+ " \"errors\": ["
1768
+ " {},"
1769
+ " { \"maxLength\": {\"actual\": \"too long\", \"expected\": 5, \"errorCode\": 6, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\" }},"
1770
+ " { \"allOf\": {"
1771
+ " \"errors\": ["
1772
+ " { \"enum\": {\"errorCode\": 19 ,\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"}},"
1773
+ " { \"enum\": {\"errorCode\": 19, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}}"
1774
+ " ],"
1775
+ " \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\""
1776
+ " }}"
1777
+ " ],"
1778
+ " \"errorCode\":23,\"instanceRef\":\"#\",\"schemaRef\":\"#\""
1779
+ "}}");
1780
+ INVALIDATE(s, "123", "", "allOf", "",
1781
+ "{ \"allOf\": {"
1782
+ " \"errors\": ["
1783
+ " {\"type\": {\"expected\": [\"string\"], \"actual\": \"integer\", \"errorCode\": 20, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/0\"}},"
1784
+ " {\"type\": {\"expected\": [\"string\"], \"actual\": \"integer\", \"errorCode\": 20, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/1\"}},"
1785
+ " { \"allOf\": {"
1786
+ " \"errors\": ["
1787
+ " { \"enum\": {\"errorCode\": 19 ,\"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/0\"}},"
1788
+ " { \"enum\": {\"errorCode\": 19, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2/allOf/1\"}}"
1789
+ " ],"
1790
+ " \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#/allOf/2\""
1791
+ " }}"
1792
+ " ],"
1793
+ " \"errorCode\":23,\"instanceRef\":\"#\",\"schemaRef\":\"#\""
1794
+ "}}");
1795
+ }
1796
+
1797
+ TEST(SchemaValidator, EscapedPointer) {
1798
+ Document sd;
1799
+ sd.Parse(
1800
+ "{"
1801
+ " \"type\": \"object\","
1802
+ " \"properties\": {"
1803
+ " \"~/\": { \"type\": \"number\" }"
1804
+ " }"
1805
+ "}");
1806
+ SchemaDocument s(sd);
1807
+ INVALIDATE(s, "{\"~/\":true}", "/properties/~0~1", "type", "/~0~1",
1808
+ "{ \"type\": {"
1809
+ " \"errorCode\": 20,"
1810
+ " \"instanceRef\": \"#/~0~1\", \"schemaRef\": \"#/properties/~0~1\","
1811
+ " \"expected\": [\"number\"], \"actual\": \"boolean\""
1812
+ "}}");
1813
+ }
1814
+
1815
+ TEST(SchemaValidator, SchemaPointer) {
1816
+ Document sd;
1817
+ sd.Parse(
1818
+ "{"
1819
+ " \"swagger\": \"2.0\","
1820
+ " \"paths\": {"
1821
+ " \"/some/path\": {"
1822
+ " \"post\": {"
1823
+ " \"parameters\": ["
1824
+ " {"
1825
+ " \"in\": \"body\","
1826
+ " \"name\": \"body\","
1827
+ " \"schema\": {"
1828
+ " \"properties\": {"
1829
+ " \"a\": {"
1830
+ " \"$ref\": \"#/definitions/Prop_a\""
1831
+ " },"
1832
+ " \"b\": {"
1833
+ " \"type\": \"integer\""
1834
+ " }"
1835
+ " },"
1836
+ " \"type\": \"object\""
1837
+ " }"
1838
+ " }"
1839
+ " ],"
1840
+ " \"responses\": {"
1841
+ " \"200\": {"
1842
+ " \"schema\": {"
1843
+ " \"$ref\": \"#/definitions/Resp_200\""
1844
+ " }"
1845
+ " }"
1846
+ " }"
1847
+ " }"
1848
+ " }"
1849
+ " },"
1850
+ " \"definitions\": {"
1851
+ " \"Prop_a\": {"
1852
+ " \"properties\": {"
1853
+ " \"c\": {"
1854
+ " \"enum\": ["
1855
+ " \"C1\","
1856
+ " \"C2\","
1857
+ " \"C3\""
1858
+ " ],"
1859
+ " \"type\": \"string\""
1860
+ " },"
1861
+ " \"d\": {"
1862
+ " \"$ref\": \"#/definitions/Prop_d\""
1863
+ " },"
1864
+ " \"s\": {"
1865
+ " \"type\": \"string\""
1866
+ " }"
1867
+ " },"
1868
+ " \"required\": [\"c\"],"
1869
+ " \"type\": \"object\""
1870
+ " },"
1871
+ " \"Prop_d\": {"
1872
+ " \"properties\": {"
1873
+ " \"a\": {"
1874
+ " \"$ref\": \"#/definitions/Prop_a\""
1875
+ " },"
1876
+ " \"c\": {"
1877
+ " \"$ref\": \"#/definitions/Prop_a/properties/c\""
1878
+ " }"
1879
+ " },"
1880
+ " \"type\": \"object\""
1881
+ " },"
1882
+ " \"Resp_200\": {"
1883
+ " \"properties\": {"
1884
+ " \"e\": {"
1885
+ " \"type\": \"string\""
1886
+ " },"
1887
+ " \"f\": {"
1888
+ " \"type\": \"boolean\""
1889
+ " },"
1890
+ " \"cyclic_source\": {"
1891
+ " \"$ref\": \"#/definitions/Resp_200/properties/cyclic_target\""
1892
+ " },"
1893
+ " \"cyclic_target\": {"
1894
+ " \"$ref\": \"#/definitions/Resp_200/properties/cyclic_source\""
1895
+ " }"
1896
+ " },"
1897
+ " \"type\": \"object\""
1898
+ " }"
1899
+ " }"
1900
+ "}");
1901
+ SchemaDocument s1(sd, NULL, 0, NULL, NULL, Pointer("#/paths/~1some~1path/post/parameters/0/schema"));
1902
+ VALIDATE(s1,
1903
+ "{"
1904
+ " \"a\": {"
1905
+ " \"c\": \"C1\","
1906
+ " \"d\": {"
1907
+ " \"a\": {"
1908
+ " \"c\": \"C2\""
1909
+ " },"
1910
+ " \"c\": \"C3\""
1911
+ " }"
1912
+ " },"
1913
+ " \"b\": 123"
1914
+ "}",
1915
+ true);
1916
+ INVALIDATE(s1,
1917
+ "{"
1918
+ " \"a\": {"
1919
+ " \"c\": \"C1\","
1920
+ " \"d\": {"
1921
+ " \"a\": {"
1922
+ " \"c\": \"C2\""
1923
+ " },"
1924
+ " \"c\": \"C3\""
1925
+ " }"
1926
+ " },"
1927
+ " \"b\": \"should be an int\""
1928
+ "}",
1929
+ "#/paths/~1some~1path/post/parameters/0/schema/properties/b", "type", "#/b",
1930
+ "{ \"type\": {"
1931
+ " \"errorCode\": 20,"
1932
+ " \"instanceRef\":\"#/b\","
1933
+ " \"schemaRef\":\"#/paths/~1some~1path/post/parameters/0/schema/properties/b\","
1934
+ " \"expected\": [\"integer\"], \"actual\":\"string\""
1935
+ "}}");
1936
+ INVALIDATE(s1,
1937
+ "{"
1938
+ " \"a\": {"
1939
+ " \"c\": \"C1\","
1940
+ " \"d\": {"
1941
+ " \"a\": {"
1942
+ " \"c\": \"should be within enum\""
1943
+ " },"
1944
+ " \"c\": \"C3\""
1945
+ " }"
1946
+ " },"
1947
+ " \"b\": 123"
1948
+ "}",
1949
+ "#/definitions/Prop_a/properties/c", "enum", "#/a/d/a/c",
1950
+ "{ \"enum\": {"
1951
+ " \"errorCode\": 19,"
1952
+ " \"instanceRef\":\"#/a/d/a/c\","
1953
+ " \"schemaRef\":\"#/definitions/Prop_a/properties/c\""
1954
+ "}}");
1955
+ INVALIDATE(s1,
1956
+ "{"
1957
+ " \"a\": {"
1958
+ " \"c\": \"C1\","
1959
+ " \"d\": {"
1960
+ " \"a\": {"
1961
+ " \"s\": \"required 'c' is missing\""
1962
+ " }"
1963
+ " }"
1964
+ " },"
1965
+ " \"b\": 123"
1966
+ "}",
1967
+ "#/definitions/Prop_a", "required", "#/a/d/a",
1968
+ "{ \"required\": {"
1969
+ " \"errorCode\": 15,"
1970
+ " \"missing\":[\"c\"],"
1971
+ " \"instanceRef\":\"#/a/d/a\","
1972
+ " \"schemaRef\":\"#/definitions/Prop_a\""
1973
+ "}}");
1974
+ SchemaDocument s2(sd, NULL, 0, NULL, NULL, Pointer("#/paths/~1some~1path/post/responses/200/schema"));
1975
+ VALIDATE(s2,
1976
+ "{ \"e\": \"some string\", \"f\": false }",
1977
+ true);
1978
+ INVALIDATE(s2,
1979
+ "{ \"e\": true, \"f\": false }",
1980
+ "#/definitions/Resp_200/properties/e", "type", "#/e",
1981
+ "{ \"type\": {"
1982
+ " \"errorCode\": 20,"
1983
+ " \"instanceRef\":\"#/e\","
1984
+ " \"schemaRef\":\"#/definitions/Resp_200/properties/e\","
1985
+ " \"expected\": [\"string\"], \"actual\":\"boolean\""
1986
+ "}}");
1987
+ INVALIDATE(s2,
1988
+ "{ \"e\": \"some string\", \"f\": 123 }",
1989
+ "#/definitions/Resp_200/properties/f", "type", "#/f",
1990
+ "{ \"type\": {"
1991
+ " \"errorCode\": 20,"
1992
+ " \"instanceRef\":\"#/f\","
1993
+ " \"schemaRef\":\"#/definitions/Resp_200/properties/f\","
1994
+ " \"expected\": [\"boolean\"], \"actual\":\"integer\""
1995
+ "}}");
1996
+ }
1997
+
1998
+ template <typename Allocator>
1999
+ static char* ReadFile(const char* filename, Allocator& allocator) {
2000
+ const char *paths[] = {
2001
+ "",
2002
+ "bin/",
2003
+ "../bin/",
2004
+ "../../bin/",
2005
+ "../../../bin/"
2006
+ };
2007
+ char buffer[1024];
2008
+ FILE *fp = 0;
2009
+ for (size_t i = 0; i < sizeof(paths) / sizeof(paths[0]); i++) {
2010
+ sprintf(buffer, "%s%s", paths[i], filename);
2011
+ fp = fopen(buffer, "rb");
2012
+ if (fp)
2013
+ break;
2014
+ }
2015
+
2016
+ if (!fp)
2017
+ return 0;
2018
+
2019
+ fseek(fp, 0, SEEK_END);
2020
+ size_t length = static_cast<size_t>(ftell(fp));
2021
+ fseek(fp, 0, SEEK_SET);
2022
+ char* json = reinterpret_cast<char*>(allocator.Malloc(length + 1));
2023
+ size_t readLength = fread(json, 1, length, fp);
2024
+ json[readLength] = '\0';
2025
+ fclose(fp);
2026
+ return json;
2027
+ }
2028
+
2029
+ TEST(SchemaValidator, ValidateMetaSchema) {
2030
+ CrtAllocator allocator;
2031
+ char* json = ReadFile("draft-04/schema", allocator);
2032
+ Document d;
2033
+ d.Parse(json);
2034
+ ASSERT_FALSE(d.HasParseError());
2035
+ SchemaDocument sd(d);
2036
+ SchemaValidator validator(sd);
2037
+ d.Accept(validator);
2038
+ if (!validator.IsValid()) {
2039
+ StringBuffer sb;
2040
+ validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);
2041
+ printf("Invalid schema: %s\n", sb.GetString());
2042
+ printf("Invalid keyword: %s\n", validator.GetInvalidSchemaKeyword());
2043
+ printf("Invalid code: %d\n", validator.GetInvalidSchemaCode());
2044
+ printf("Invalid message: %s\n", GetValidateError_En(validator.GetInvalidSchemaCode()));
2045
+ sb.Clear();
2046
+ validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);
2047
+ printf("Invalid document: %s\n", sb.GetString());
2048
+ sb.Clear();
2049
+ Writer<StringBuffer> w(sb);
2050
+ validator.GetError().Accept(w);
2051
+ printf("Validation error: %s\n", sb.GetString());
2052
+ ADD_FAILURE();
2053
+ }
2054
+ CrtAllocator::Free(json);
2055
+ }
2056
+
2057
+ TEST(SchemaValidator, ValidateMetaSchema_UTF16) {
2058
+ typedef GenericDocument<UTF16<> > D;
2059
+ typedef GenericSchemaDocument<D::ValueType> SD;
2060
+ typedef GenericSchemaValidator<SD> SV;
2061
+
2062
+ CrtAllocator allocator;
2063
+ char* json = ReadFile("draft-04/schema", allocator);
2064
+
2065
+ D d;
2066
+ StringStream ss(json);
2067
+ d.ParseStream<0, UTF8<> >(ss);
2068
+ ASSERT_FALSE(d.HasParseError());
2069
+ SD sd(d);
2070
+ SV validator(sd);
2071
+ d.Accept(validator);
2072
+ if (!validator.IsValid()) {
2073
+ GenericStringBuffer<UTF16<> > sb;
2074
+ validator.GetInvalidSchemaPointer().StringifyUriFragment(sb);
2075
+ wprintf(L"Invalid schema: %ls\n", sb.GetString());
2076
+ wprintf(L"Invalid keyword: %ls\n", validator.GetInvalidSchemaKeyword());
2077
+ sb.Clear();
2078
+ validator.GetInvalidDocumentPointer().StringifyUriFragment(sb);
2079
+ wprintf(L"Invalid document: %ls\n", sb.GetString());
2080
+ sb.Clear();
2081
+ Writer<GenericStringBuffer<UTF16<> >, UTF16<> > w(sb);
2082
+ validator.GetError().Accept(w);
2083
+ printf("Validation error: %ls\n", sb.GetString());
2084
+ ADD_FAILURE();
2085
+ }
2086
+ CrtAllocator::Free(json);
2087
+ }
2088
+
2089
+ template <typename SchemaDocumentType = SchemaDocument>
2090
+ class RemoteSchemaDocumentProvider : public IGenericRemoteSchemaDocumentProvider<SchemaDocumentType> {
2091
+ public:
2092
+ RemoteSchemaDocumentProvider() :
2093
+ documentAllocator_(documentBuffer_, sizeof(documentBuffer_)),
2094
+ schemaAllocator_(schemaBuffer_, sizeof(schemaBuffer_))
2095
+ {
2096
+ const char* filenames[kCount] = {
2097
+ "jsonschema/remotes/integer.json",
2098
+ "jsonschema/remotes/subSchemas.json",
2099
+ "jsonschema/remotes/folder/folderInteger.json",
2100
+ "draft-04/schema",
2101
+ "unittestschema/address.json"
2102
+ };
2103
+ const char* uris[kCount] = {
2104
+ "http://localhost:1234/integer.json",
2105
+ "http://localhost:1234/subSchemas.json",
2106
+ "http://localhost:1234/folder/folderInteger.json",
2107
+ "http://json-schema.org/draft-04/schema",
2108
+ "http://localhost:1234/address.json"
2109
+ };
2110
+
2111
+ for (size_t i = 0; i < kCount; i++) {
2112
+ sd_[i] = 0;
2113
+
2114
+ char jsonBuffer[8192];
2115
+ MemoryPoolAllocator<> jsonAllocator(jsonBuffer, sizeof(jsonBuffer));
2116
+ char* json = ReadFile(filenames[i], jsonAllocator);
2117
+ if (!json) {
2118
+ printf("json remote file %s not found", filenames[i]);
2119
+ ADD_FAILURE();
2120
+ }
2121
+ else {
2122
+ char stackBuffer[4096];
2123
+ MemoryPoolAllocator<> stackAllocator(stackBuffer, sizeof(stackBuffer));
2124
+ DocumentType d(&documentAllocator_, 1024, &stackAllocator);
2125
+ d.Parse(json);
2126
+ sd_[i] = new SchemaDocumentType(d, uris[i], static_cast<SizeType>(strlen(uris[i])), 0, &schemaAllocator_);
2127
+ MemoryPoolAllocator<>::Free(json);
2128
+ }
2129
+ };
2130
+ }
2131
+
2132
+ ~RemoteSchemaDocumentProvider() {
2133
+ for (size_t i = 0; i < kCount; i++)
2134
+ delete sd_[i];
2135
+ }
2136
+
2137
+ virtual const SchemaDocumentType* GetRemoteDocument(const char* uri, SizeType length) {
2138
+ for (size_t i = 0; i < kCount; i++)
2139
+ if (typename SchemaDocumentType::SValue(uri, length) == sd_[i]->GetURI())
2140
+ return sd_[i];
2141
+ return 0;
2142
+ }
2143
+
2144
+ private:
2145
+ typedef GenericDocument<typename SchemaDocumentType::EncodingType, MemoryPoolAllocator<>, MemoryPoolAllocator<> > DocumentType;
2146
+
2147
+ RemoteSchemaDocumentProvider(const RemoteSchemaDocumentProvider&);
2148
+ RemoteSchemaDocumentProvider& operator=(const RemoteSchemaDocumentProvider&);
2149
+
2150
+ static const size_t kCount = 5;
2151
+ SchemaDocumentType* sd_[kCount];
2152
+ typename DocumentType::AllocatorType documentAllocator_;
2153
+ typename SchemaDocumentType::AllocatorType schemaAllocator_;
2154
+ char documentBuffer_[16384];
2155
+ char schemaBuffer_[128u * 1024];
2156
+ };
2157
+
2158
+ TEST(SchemaValidator, TestSuite) {
2159
+ const char* filenames[] = {
2160
+ "additionalItems.json",
2161
+ "additionalProperties.json",
2162
+ "allOf.json",
2163
+ "anyOf.json",
2164
+ "default.json",
2165
+ "definitions.json",
2166
+ "dependencies.json",
2167
+ "enum.json",
2168
+ "items.json",
2169
+ "maximum.json",
2170
+ "maxItems.json",
2171
+ "maxLength.json",
2172
+ "maxProperties.json",
2173
+ "minimum.json",
2174
+ "minItems.json",
2175
+ "minLength.json",
2176
+ "minProperties.json",
2177
+ "multipleOf.json",
2178
+ "not.json",
2179
+ "oneOf.json",
2180
+ "pattern.json",
2181
+ "patternProperties.json",
2182
+ "properties.json",
2183
+ "ref.json",
2184
+ "refRemote.json",
2185
+ "required.json",
2186
+ "type.json",
2187
+ "uniqueItems.json"
2188
+ };
2189
+
2190
+ const char* onlyRunDescription = 0;
2191
+ //const char* onlyRunDescription = "a string is a string";
2192
+
2193
+ unsigned testCount = 0;
2194
+ unsigned passCount = 0;
2195
+
2196
+ typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
2197
+ RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
2198
+
2199
+ char jsonBuffer[65536];
2200
+ char documentBuffer[65536];
2201
+ char documentStackBuffer[65536];
2202
+ char schemaBuffer[65536];
2203
+ char validatorBuffer[65536];
2204
+ MemoryPoolAllocator<> jsonAllocator(jsonBuffer, sizeof(jsonBuffer));
2205
+ MemoryPoolAllocator<> documentAllocator(documentBuffer, sizeof(documentBuffer));
2206
+ MemoryPoolAllocator<> documentStackAllocator(documentStackBuffer, sizeof(documentStackBuffer));
2207
+ MemoryPoolAllocator<> schemaAllocator(schemaBuffer, sizeof(schemaBuffer));
2208
+ MemoryPoolAllocator<> validatorAllocator(validatorBuffer, sizeof(validatorBuffer));
2209
+
2210
+ for (size_t i = 0; i < sizeof(filenames) / sizeof(filenames[0]); i++) {
2211
+ char filename[FILENAME_MAX];
2212
+ sprintf(filename, "jsonschema/tests/draft4/%s", filenames[i]);
2213
+ char* json = ReadFile(filename, jsonAllocator);
2214
+ if (!json) {
2215
+ printf("json test suite file %s not found", filename);
2216
+ ADD_FAILURE();
2217
+ }
2218
+ else {
2219
+ //printf("\njson test suite file %s parsed ok\n", filename);
2220
+ GenericDocument<UTF8<>, MemoryPoolAllocator<>, MemoryPoolAllocator<> > d(&documentAllocator, 1024, &documentStackAllocator);
2221
+ d.Parse(json);
2222
+ if (d.HasParseError()) {
2223
+ printf("json test suite file %s has parse error", filename);
2224
+ ADD_FAILURE();
2225
+ }
2226
+ else {
2227
+ for (Value::ConstValueIterator schemaItr = d.Begin(); schemaItr != d.End(); ++schemaItr) {
2228
+ {
2229
+ const char* description1 = (*schemaItr)["description"].GetString();
2230
+ //printf("\ncompiling schema for json test %s \n", description1);
2231
+ SchemaDocumentType schema((*schemaItr)["schema"], filenames[i], static_cast<SizeType>(strlen(filenames[i])), &provider, &schemaAllocator);
2232
+ GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > validator(schema, &validatorAllocator);
2233
+ const Value& tests = (*schemaItr)["tests"];
2234
+ for (Value::ConstValueIterator testItr = tests.Begin(); testItr != tests.End(); ++testItr) {
2235
+ const char* description2 = (*testItr)["description"].GetString();
2236
+ //printf("running json test %s \n", description2);
2237
+ if (!onlyRunDescription || strcmp(description2, onlyRunDescription) == 0) {
2238
+ const Value& data = (*testItr)["data"];
2239
+ bool expected = (*testItr)["valid"].GetBool();
2240
+ testCount++;
2241
+ validator.Reset();
2242
+ data.Accept(validator);
2243
+ bool actual = validator.IsValid();
2244
+ if (expected != actual)
2245
+ printf("Fail: %30s \"%s\" \"%s\"\n", filename, description1, description2);
2246
+ else {
2247
+ //printf("Passed: %30s \"%s\" \"%s\"\n", filename, description1, description2);
2248
+ passCount++;
2249
+ }
2250
+ }
2251
+ }
2252
+ //printf("%zu %zu %zu\n", documentAllocator.Size(), schemaAllocator.Size(), validatorAllocator.Size());
2253
+ }
2254
+ schemaAllocator.Clear();
2255
+ validatorAllocator.Clear();
2256
+ }
2257
+ }
2258
+ }
2259
+ documentAllocator.Clear();
2260
+ MemoryPoolAllocator<>::Free(json);
2261
+ jsonAllocator.Clear();
2262
+ }
2263
+ printf("%d / %d passed (%2d%%)\n", passCount, testCount, passCount * 100 / testCount);
2264
+ if (passCount != testCount)
2265
+ ADD_FAILURE();
2266
+ }
2267
+
2268
+ TEST(SchemaValidatingReader, Simple) {
2269
+ Document sd;
2270
+ sd.Parse("{ \"type\": \"string\", \"enum\" : [\"red\", \"amber\", \"green\"] }");
2271
+ SchemaDocument s(sd);
2272
+
2273
+ Document d;
2274
+ StringStream ss("\"red\"");
2275
+ SchemaValidatingReader<kParseDefaultFlags, StringStream, UTF8<> > reader(ss, s);
2276
+ d.Populate(reader);
2277
+ EXPECT_TRUE(reader.GetParseResult());
2278
+ EXPECT_TRUE(reader.IsValid());
2279
+ EXPECT_TRUE(d.IsString());
2280
+ EXPECT_STREQ("red", d.GetString());
2281
+ }
2282
+
2283
+ TEST(SchemaValidatingReader, Invalid) {
2284
+ Document sd;
2285
+ sd.Parse("{\"type\":\"string\",\"minLength\":2,\"maxLength\":3}");
2286
+ SchemaDocument s(sd);
2287
+
2288
+ Document d;
2289
+ StringStream ss("\"ABCD\"");
2290
+ SchemaValidatingReader<kParseDefaultFlags, StringStream, UTF8<> > reader(ss, s);
2291
+ d.Populate(reader);
2292
+ EXPECT_FALSE(reader.GetParseResult());
2293
+ EXPECT_FALSE(reader.IsValid());
2294
+ EXPECT_EQ(kParseErrorTermination, reader.GetParseResult().Code());
2295
+ EXPECT_STREQ("maxLength", reader.GetInvalidSchemaKeyword());
2296
+ EXPECT_TRUE(reader.GetInvalidSchemaCode() == kValidateErrorMaxLength);
2297
+ EXPECT_TRUE(reader.GetInvalidSchemaPointer() == SchemaDocument::PointerType(""));
2298
+ EXPECT_TRUE(reader.GetInvalidDocumentPointer() == SchemaDocument::PointerType(""));
2299
+ EXPECT_TRUE(d.IsNull());
2300
+ Document e;
2301
+ e.Parse(
2302
+ "{ \"maxLength\": {"
2303
+ " \"errorCode\": 6,"
2304
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
2305
+ " \"expected\": 3, \"actual\": \"ABCD\""
2306
+ "}}");
2307
+ if (e != reader.GetError()) {
2308
+ ADD_FAILURE();
2309
+ }
2310
+ }
2311
+
2312
+ TEST(SchemaValidatingWriter, Simple) {
2313
+ Document sd;
2314
+ sd.Parse("{\"type\":\"string\",\"minLength\":2,\"maxLength\":3}");
2315
+ SchemaDocument s(sd);
2316
+
2317
+ Document d;
2318
+ StringBuffer sb;
2319
+ Writer<StringBuffer> writer(sb);
2320
+ GenericSchemaValidator<SchemaDocument, Writer<StringBuffer> > validator(s, writer);
2321
+
2322
+ d.Parse("\"red\"");
2323
+ EXPECT_TRUE(d.Accept(validator));
2324
+ EXPECT_TRUE(validator.IsValid());
2325
+ EXPECT_STREQ("\"red\"", sb.GetString());
2326
+
2327
+ sb.Clear();
2328
+ validator.Reset();
2329
+ d.Parse("\"ABCD\"");
2330
+ EXPECT_FALSE(d.Accept(validator));
2331
+ EXPECT_FALSE(validator.IsValid());
2332
+ EXPECT_TRUE(validator.GetInvalidSchemaPointer() == SchemaDocument::PointerType(""));
2333
+ EXPECT_TRUE(validator.GetInvalidDocumentPointer() == SchemaDocument::PointerType(""));
2334
+ EXPECT_TRUE(validator.GetInvalidSchemaCode() == kValidateErrorMaxLength);
2335
+ Document e;
2336
+ e.Parse(
2337
+ "{ \"maxLength\": {"
2338
+ " \"errorCode\": 6,"
2339
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
2340
+ " \"expected\": 3, \"actual\": \"ABCD\""
2341
+ "}}");
2342
+ EXPECT_EQ(e, validator.GetError());
2343
+ }
2344
+
2345
+ TEST(Schema, Issue848) {
2346
+ rapidjson::Document d;
2347
+ rapidjson::SchemaDocument s(d);
2348
+ rapidjson::GenericSchemaValidator<rapidjson::SchemaDocument, rapidjson::Document> v(s);
2349
+ }
2350
+
2351
+ #if RAPIDJSON_HAS_CXX11_RVALUE_REFS
2352
+
2353
+ static SchemaDocument ReturnSchemaDocument() {
2354
+ Document sd;
2355
+ sd.Parse("{ \"type\": [\"number\", \"string\"] }");
2356
+ SchemaDocument s(sd);
2357
+ return s;
2358
+ }
2359
+
2360
+ TEST(Schema, Issue552) {
2361
+ SchemaDocument s = ReturnSchemaDocument();
2362
+ VALIDATE(s, "42", true);
2363
+ VALIDATE(s, "\"Life, the universe, and everything\"", true);
2364
+ INVALIDATE(s, "[\"Life\", \"the universe\", \"and everything\"]", "", "type", "",
2365
+ "{ \"type\": {"
2366
+ " \"errorCode\": 20,"
2367
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
2368
+ " \"expected\": [\"string\", \"number\"], \"actual\": \"array\""
2369
+ "}}");
2370
+ }
2371
+
2372
+ #endif // RAPIDJSON_HAS_CXX11_RVALUE_REFS
2373
+
2374
+ TEST(SchemaValidator, Issue608) {
2375
+ Document sd;
2376
+ sd.Parse("{\"required\": [\"a\", \"b\"] }");
2377
+ SchemaDocument s(sd);
2378
+
2379
+ VALIDATE(s, "{\"a\" : null, \"b\": null}", true);
2380
+ INVALIDATE(s, "{\"a\" : null, \"a\" : null}", "", "required", "",
2381
+ "{ \"required\": {"
2382
+ " \"errorCode\": 15,"
2383
+ " \"instanceRef\": \"#\", \"schemaRef\": \"#\","
2384
+ " \"missing\": [\"b\"]"
2385
+ "}}");
2386
+ }
2387
+
2388
+ // Fail to resolve $ref in allOf causes crash in SchemaValidator::StartObject()
2389
+ TEST(SchemaValidator, Issue728_AllOfRef) {
2390
+ Document sd;
2391
+ sd.Parse("{\"allOf\": [{\"$ref\": \"#/abc\"}]}");
2392
+ SchemaDocument s(sd);
2393
+ VALIDATE(s, "{\"key1\": \"abc\", \"key2\": \"def\"}", true);
2394
+ }
2395
+
2396
+ TEST(SchemaValidator, Issue1017_allOfHandler) {
2397
+ Document sd;
2398
+ sd.Parse("{\"allOf\": [{\"type\": \"object\",\"properties\": {\"cyanArray2\": {\"type\": \"array\",\"items\": { \"type\": \"string\" }}}},{\"type\": \"object\",\"properties\": {\"blackArray\": {\"type\": \"array\",\"items\": { \"type\": \"string\" }}},\"required\": [ \"blackArray\" ]}]}");
2399
+ SchemaDocument s(sd);
2400
+ StringBuffer sb;
2401
+ Writer<StringBuffer> writer(sb);
2402
+ GenericSchemaValidator<SchemaDocument, Writer<StringBuffer> > validator(s, writer);
2403
+ EXPECT_TRUE(validator.StartObject());
2404
+ EXPECT_TRUE(validator.Key("cyanArray2", 10, false));
2405
+ EXPECT_TRUE(validator.StartArray());
2406
+ EXPECT_TRUE(validator.EndArray(0));
2407
+ EXPECT_TRUE(validator.Key("blackArray", 10, false));
2408
+ EXPECT_TRUE(validator.StartArray());
2409
+ EXPECT_TRUE(validator.EndArray(0));
2410
+ EXPECT_TRUE(validator.EndObject(0));
2411
+ EXPECT_TRUE(validator.IsValid());
2412
+ EXPECT_STREQ("{\"cyanArray2\":[],\"blackArray\":[]}", sb.GetString());
2413
+ }
2414
+
2415
+ TEST(SchemaValidator, Ref_remote) {
2416
+ typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
2417
+ RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
2418
+ Document sd;
2419
+ sd.Parse("{\"$ref\": \"http://localhost:1234/subSchemas.json#/integer\"}");
2420
+ SchemaDocumentType s(sd, 0, 0, &provider);
2421
+ typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
2422
+ typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
2423
+ INVALIDATE_(s, "null", "/integer", "type", "",
2424
+ "{ \"type\": {"
2425
+ " \"errorCode\": 20,"
2426
+ " \"instanceRef\": \"#\","
2427
+ " \"schemaRef\": \"http://localhost:1234/subSchemas.json#/integer\","
2428
+ " \"expected\": [\"integer\"], \"actual\": \"null\""
2429
+ "}}",
2430
+ kValidateDefaultFlags, SchemaValidatorType, PointerType);
2431
+ }
2432
+
2433
+ // Merge with id where $ref is full URI
2434
+ TEST(SchemaValidator, Ref_remote_change_resolution_scope_uri) {
2435
+ typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
2436
+ RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
2437
+ Document sd;
2438
+ sd.Parse("{\"id\": \"http://ignore/blah#/ref\", \"type\": \"object\", \"properties\": {\"myInt\": {\"$ref\": \"http://localhost:1234/subSchemas.json#/integer\"}}}");
2439
+ SchemaDocumentType s(sd, 0, 0, &provider);
2440
+ typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
2441
+ typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
2442
+ INVALIDATE_(s, "{\"myInt\": null}", "/integer", "type", "/myInt",
2443
+ "{ \"type\": {"
2444
+ " \"errorCode\": 20,"
2445
+ " \"instanceRef\": \"#/myInt\","
2446
+ " \"schemaRef\": \"http://localhost:1234/subSchemas.json#/integer\","
2447
+ " \"expected\": [\"integer\"], \"actual\": \"null\""
2448
+ "}}",
2449
+ kValidateDefaultFlags, SchemaValidatorType, PointerType);
2450
+ }
2451
+
2452
+ // Merge with id where $ref is a relative path
2453
+ TEST(SchemaValidator, Ref_remote_change_resolution_scope_relative_path) {
2454
+ typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
2455
+ RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
2456
+ Document sd;
2457
+ sd.Parse("{\"id\": \"http://localhost:1234/\", \"type\": \"object\", \"properties\": {\"myInt\": {\"$ref\": \"subSchemas.json#/integer\"}}}");
2458
+ SchemaDocumentType s(sd, 0, 0, &provider);
2459
+ typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
2460
+ typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
2461
+ INVALIDATE_(s, "{\"myInt\": null}", "/integer", "type", "/myInt",
2462
+ "{ \"type\": {"
2463
+ " \"errorCode\": 20,"
2464
+ " \"instanceRef\": \"#/myInt\","
2465
+ " \"schemaRef\": \"http://localhost:1234/subSchemas.json#/integer\","
2466
+ " \"expected\": [\"integer\"], \"actual\": \"null\""
2467
+ "}}",
2468
+ kValidateDefaultFlags, SchemaValidatorType, PointerType);
2469
+ }
2470
+
2471
+ // Merge with id where $ref is an absolute path
2472
+ TEST(SchemaValidator, Ref_remote_change_resolution_scope_absolute_path) {
2473
+ typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
2474
+ RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
2475
+ Document sd;
2476
+ sd.Parse("{\"id\": \"http://localhost:1234/xxxx\", \"type\": \"object\", \"properties\": {\"myInt\": {\"$ref\": \"/subSchemas.json#/integer\"}}}");
2477
+ SchemaDocumentType s(sd, 0, 0, &provider);
2478
+ typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
2479
+ typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
2480
+ INVALIDATE_(s, "{\"myInt\": null}", "/integer", "type", "/myInt",
2481
+ "{ \"type\": {"
2482
+ " \"errorCode\": 20,"
2483
+ " \"instanceRef\": \"#/myInt\","
2484
+ " \"schemaRef\": \"http://localhost:1234/subSchemas.json#/integer\","
2485
+ " \"expected\": [\"integer\"], \"actual\": \"null\""
2486
+ "}}",
2487
+ kValidateDefaultFlags, SchemaValidatorType, PointerType);
2488
+ }
2489
+
2490
+ // Merge with id where $ref is an absolute path, and the document has a base URI
2491
+ TEST(SchemaValidator, Ref_remote_change_resolution_scope_absolute_path_document) {
2492
+ typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
2493
+ RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
2494
+ Document sd;
2495
+ sd.Parse("{\"type\": \"object\", \"properties\": {\"myInt\": {\"$ref\": \"/subSchemas.json#/integer\"}}}");
2496
+ SchemaDocumentType s(sd, "http://localhost:1234/xxxx", 26, &provider);
2497
+ typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
2498
+ typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
2499
+ INVALIDATE_(s, "{\"myInt\": null}", "/integer", "type", "/myInt",
2500
+ "{ \"type\": {"
2501
+ " \"errorCode\": 20,"
2502
+ " \"instanceRef\": \"#/myInt\","
2503
+ " \"schemaRef\": \"http://localhost:1234/subSchemas.json#/integer\","
2504
+ " \"expected\": [\"integer\"], \"actual\": \"null\""
2505
+ "}}",
2506
+ kValidateDefaultFlags, SchemaValidatorType, PointerType);
2507
+ }
2508
+
2509
+ // $ref is a non-JSON pointer fragment and there a matching id
2510
+ TEST(SchemaValidator, Ref_internal_id_1) {
2511
+ typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
2512
+ Document sd;
2513
+ sd.Parse("{\"type\": \"object\", \"properties\": {\"myInt1\": {\"$ref\": \"#myId\"}, \"myStr\": {\"type\": \"string\", \"id\": \"#myStrId\"}, \"myInt2\": {\"type\": \"integer\", \"id\": \"#myId\"}}}");
2514
+ SchemaDocumentType s(sd);
2515
+ typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
2516
+ typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
2517
+ INVALIDATE_(s, "{\"myInt1\": null}", "/properties/myInt2", "type", "/myInt1",
2518
+ "{ \"type\": {"
2519
+ " \"errorCode\": 20,"
2520
+ " \"instanceRef\": \"#/myInt1\","
2521
+ " \"schemaRef\": \"#/properties/myInt2\","
2522
+ " \"expected\": [\"integer\"], \"actual\": \"null\""
2523
+ "}}",
2524
+ kValidateDefaultFlags, SchemaValidatorType, PointerType);
2525
+ }
2526
+
2527
+ // $ref is a non-JSON pointer fragment and there are two matching ids so we take the first
2528
+ TEST(SchemaValidator, Ref_internal_id_2) {
2529
+ typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
2530
+ Document sd;
2531
+ sd.Parse("{\"type\": \"object\", \"properties\": {\"myInt1\": {\"$ref\": \"#myId\"}, \"myInt2\": {\"type\": \"integer\", \"id\": \"#myId\"}, \"myStr\": {\"type\": \"string\", \"id\": \"#myId\"}}}");
2532
+ SchemaDocumentType s(sd);
2533
+ typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
2534
+ typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
2535
+ INVALIDATE_(s, "{\"myInt1\": null}", "/properties/myInt2", "type", "/myInt1",
2536
+ "{ \"type\": {"
2537
+ " \"errorCode\": 20,"
2538
+ " \"instanceRef\": \"#/myInt1\","
2539
+ " \"schemaRef\": \"#/properties/myInt2\","
2540
+ " \"expected\": [\"integer\"], \"actual\": \"null\""
2541
+ "}}",
2542
+ kValidateDefaultFlags, SchemaValidatorType, PointerType);
2543
+ }
2544
+
2545
+ // $ref is a non-JSON pointer fragment and there is a matching id within array
2546
+ TEST(SchemaValidator, Ref_internal_id_in_array) {
2547
+ typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
2548
+ Document sd;
2549
+ sd.Parse("{\"type\": \"object\", \"properties\": {\"myInt1\": {\"$ref\": \"#myId\"}, \"myInt2\": {\"anyOf\": [{\"type\": \"string\", \"id\": \"#myStrId\"}, {\"type\": \"integer\", \"id\": \"#myId\"}]}}}");
2550
+ SchemaDocumentType s(sd);
2551
+ typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
2552
+ typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
2553
+ INVALIDATE_(s, "{\"myInt1\": null}", "/properties/myInt2/anyOf/1", "type", "/myInt1",
2554
+ "{ \"type\": {"
2555
+ " \"errorCode\": 20,"
2556
+ " \"instanceRef\": \"#/myInt1\","
2557
+ " \"schemaRef\": \"#/properties/myInt2/anyOf/1\","
2558
+ " \"expected\": [\"integer\"], \"actual\": \"null\""
2559
+ "}}",
2560
+ kValidateDefaultFlags, SchemaValidatorType, PointerType);
2561
+ }
2562
+
2563
+ // $ref is a non-JSON pointer fragment and there is a matching id, and the schema is embedded in the document
2564
+ TEST(SchemaValidator, Ref_internal_id_and_schema_pointer) {
2565
+ typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
2566
+ Document sd;
2567
+ sd.Parse("{ \"schema\": {\"type\": \"object\", \"properties\": {\"myInt1\": {\"$ref\": \"#myId\"}, \"myInt2\": {\"anyOf\": [{\"type\": \"integer\", \"id\": \"#myId\"}]}}}}");
2568
+ typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
2569
+ SchemaDocumentType s(sd, 0, 0, 0, 0, PointerType("/schema"));
2570
+ typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
2571
+ INVALIDATE_(s, "{\"myInt1\": null}", "/schema/properties/myInt2/anyOf/0", "type", "/myInt1",
2572
+ "{ \"type\": {"
2573
+ " \"errorCode\": 20,"
2574
+ " \"instanceRef\": \"#/myInt1\","
2575
+ " \"schemaRef\": \"#/schema/properties/myInt2/anyOf/0\","
2576
+ " \"expected\": [\"integer\"], \"actual\": \"null\""
2577
+ "}}",
2578
+ kValidateDefaultFlags, SchemaValidatorType, PointerType);
2579
+ }
2580
+
2581
+ // Test that $refs are correctly resolved when intermediate multiple ids are present
2582
+ // Includes $ref to a part of the document with a different in-scope id, which also contains $ref..
2583
+ TEST(SchemaValidator, Ref_internal_multiple_ids) {
2584
+ typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
2585
+ //RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
2586
+ CrtAllocator allocator;
2587
+ char* schema = ReadFile("unittestschema/idandref.json", allocator);
2588
+ Document sd;
2589
+ sd.Parse(schema);
2590
+ ASSERT_FALSE(sd.HasParseError());
2591
+ SchemaDocumentType s(sd, "http://xyz", 10/*, &provider*/);
2592
+ typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
2593
+ typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
2594
+ INVALIDATE_(s, "{\"PA1\": \"s\", \"PA2\": \"t\", \"PA3\": \"r\", \"PX1\": 1, \"PX2Y\": 2, \"PX3Z\": 3, \"PX4\": 4, \"PX5\": 5, \"PX6\": 6, \"PX7W\": 7, \"PX8N\": { \"NX\": 8}}", "#", "errors", "#",
2595
+ "{ \"type\": ["
2596
+ " {\"errorCode\": 20, \"instanceRef\": \"#/PA1\", \"schemaRef\": \"http://xyz#/definitions/A\", \"expected\": [\"integer\"], \"actual\": \"string\"},"
2597
+ " {\"errorCode\": 20, \"instanceRef\": \"#/PA2\", \"schemaRef\": \"http://xyz#/definitions/A\", \"expected\": [\"integer\"], \"actual\": \"string\"},"
2598
+ " {\"errorCode\": 20, \"instanceRef\": \"#/PA3\", \"schemaRef\": \"http://xyz#/definitions/A\", \"expected\": [\"integer\"], \"actual\": \"string\"},"
2599
+ " {\"errorCode\": 20, \"instanceRef\": \"#/PX1\", \"schemaRef\": \"http://xyz#/definitions/B/definitions/X\", \"expected\": [\"boolean\"], \"actual\": \"integer\"},"
2600
+ " {\"errorCode\": 20, \"instanceRef\": \"#/PX2Y\", \"schemaRef\": \"http://xyz#/definitions/B/definitions/X\", \"expected\": [\"boolean\"], \"actual\": \"integer\"},"
2601
+ " {\"errorCode\": 20, \"instanceRef\": \"#/PX3Z\", \"schemaRef\": \"http://xyz#/definitions/B/definitions/X\", \"expected\": [\"boolean\"], \"actual\": \"integer\"},"
2602
+ " {\"errorCode\": 20, \"instanceRef\": \"#/PX4\", \"schemaRef\": \"http://xyz#/definitions/B/definitions/X\", \"expected\": [\"boolean\"], \"actual\": \"integer\"},"
2603
+ " {\"errorCode\": 20, \"instanceRef\": \"#/PX5\", \"schemaRef\": \"http://xyz#/definitions/B/definitions/X\", \"expected\": [\"boolean\"], \"actual\": \"integer\"},"
2604
+ " {\"errorCode\": 20, \"instanceRef\": \"#/PX6\", \"schemaRef\": \"http://xyz#/definitions/B/definitions/X\", \"expected\": [\"boolean\"], \"actual\": \"integer\"},"
2605
+ " {\"errorCode\": 20, \"instanceRef\": \"#/PX7W\", \"schemaRef\": \"http://xyz#/definitions/B/definitions/X\", \"expected\": [\"boolean\"], \"actual\": \"integer\"},"
2606
+ " {\"errorCode\": 20, \"instanceRef\": \"#/PX8N/NX\", \"schemaRef\": \"http://xyz#/definitions/B/definitions/X\", \"expected\": [\"boolean\"], \"actual\": \"integer\"}"
2607
+ "]}",
2608
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidatorType, PointerType);
2609
+ CrtAllocator::Free(schema);
2610
+ }
2611
+
2612
+ TEST(SchemaValidator, Ref_remote_issue1210) {
2613
+ class SchemaDocumentProvider : public IRemoteSchemaDocumentProvider {
2614
+ SchemaDocument** collection;
2615
+
2616
+ // Dummy private copy constructor & assignment operator.
2617
+ // Function bodies added so that they compile in MSVC 2019.
2618
+ SchemaDocumentProvider(const SchemaDocumentProvider&) : collection(NULL) {
2619
+ }
2620
+ SchemaDocumentProvider& operator=(const SchemaDocumentProvider&) {
2621
+ return *this;
2622
+ }
2623
+
2624
+ public:
2625
+ SchemaDocumentProvider(SchemaDocument** collection) : collection(collection) { }
2626
+ virtual const SchemaDocument* GetRemoteDocument(const char* uri, SizeType length) {
2627
+ int i = 0;
2628
+ while (collection[i] && SchemaDocument::SValue(uri, length) != collection[i]->GetURI()) ++i;
2629
+ return collection[i];
2630
+ }
2631
+ };
2632
+ SchemaDocument* collection[] = { 0, 0, 0 };
2633
+ SchemaDocumentProvider provider(collection);
2634
+
2635
+ Document x, y, z;
2636
+ x.Parse("{\"properties\":{\"country\":{\"$ref\":\"y.json#/definitions/country_remote\"}},\"type\":\"object\"}");
2637
+ y.Parse("{\"definitions\":{\"country_remote\":{\"$ref\":\"z.json#/definitions/country_list\"}}}");
2638
+ z.Parse("{\"definitions\":{\"country_list\":{\"enum\":[\"US\"]}}}");
2639
+
2640
+ SchemaDocument sz(z, "z.json", 6, &provider);
2641
+ collection[0] = &sz;
2642
+ SchemaDocument sy(y, "y.json", 6, &provider);
2643
+ collection[1] = &sy;
2644
+ SchemaDocument sx(x, "x.json", 6, &provider);
2645
+
2646
+ VALIDATE(sx, "{\"country\":\"UK\"}", false);
2647
+ VALIDATE(sx, "{\"country\":\"US\"}", true);
2648
+ }
2649
+
2650
+ // Test that when kValidateContinueOnErrorFlag is set, all errors are reported.
2651
+ TEST(SchemaValidator, ContinueOnErrors) {
2652
+ CrtAllocator allocator;
2653
+ char* schema = ReadFile("unittestschema/address.json", allocator);
2654
+ Document sd;
2655
+ sd.Parse(schema);
2656
+ ASSERT_FALSE(sd.HasParseError());
2657
+ SchemaDocument s(sd);
2658
+ VALIDATE(s, "{\"version\": 1.0, \"address\": {\"number\": 24, \"street1\": \"The Woodlands\", \"street3\": \"Ham\", \"city\": \"Romsey\", \"area\": \"Kent\", \"country\": \"UK\", \"postcode\": \"SO51 0GP\"}, \"phones\": [\"0111-222333\", \"0777-666888\"], \"names\": [\"Fred\", \"Bloggs\"]}", true);
2659
+ INVALIDATE_(s, "{\"version\": 1.01, \"address\": {\"number\": 0, \"street2\": false, \"street3\": \"Ham\", \"city\": \"RomseyTownFC\", \"area\": \"BC\", \"country\": \"USA\", \"postcode\": \"999ABC\"}, \"phones\": [], \"planet\": \"Earth\", \"extra\": {\"S_xxx\": 123}}", "#", "errors", "#",
2660
+ "{ \"multipleOf\": {"
2661
+ " \"errorCode\": 1, \"instanceRef\": \"#/version\", \"schemaRef\": \"#/definitions/decimal_type\", \"expected\": 1.0, \"actual\": 1.01"
2662
+ " },"
2663
+ " \"minimum\": {"
2664
+ " \"errorCode\": 5, \"instanceRef\": \"#/address/number\", \"schemaRef\": \"#/definitions/positiveInt_type\", \"expected\": 0, \"actual\": 0, \"exclusiveMinimum\": true"
2665
+ " },"
2666
+ " \"type\": ["
2667
+ " {\"expected\": [\"null\", \"string\"], \"actual\": \"boolean\", \"errorCode\": 20, \"instanceRef\": \"#/address/street2\", \"schemaRef\": \"#/definitions/address_type/properties/street2\"},"
2668
+ " {\"expected\": [\"string\"], \"actual\": \"integer\", \"errorCode\": 20, \"instanceRef\": \"#/extra/S_xxx\", \"schemaRef\": \"#/properties/extra/patternProperties/%5ES_\"}"
2669
+ " ],"
2670
+ " \"maxLength\": {"
2671
+ " \"actual\": \"RomseyTownFC\", \"expected\": 10, \"errorCode\": 6, \"instanceRef\": \"#/address/city\", \"schemaRef\": \"#/definitions/address_type/properties/city\""
2672
+ " },"
2673
+ " \"anyOf\": {"
2674
+ " \"errors\":["
2675
+ " {\"pattern\": {\"actual\": \"999ABC\", \"errorCode\": 8, \"instanceRef\": \"#/address/postcode\", \"schemaRef\": \"#/definitions/address_type/properties/postcode/anyOf/0\"}},"
2676
+ " {\"pattern\": {\"actual\": \"999ABC\", \"errorCode\": 8, \"instanceRef\": \"#/address/postcode\", \"schemaRef\": \"#/definitions/address_type/properties/postcode/anyOf/1\"}}"
2677
+ " ],"
2678
+ " \"errorCode\": 24, \"instanceRef\": \"#/address/postcode\", \"schemaRef\": \"#/definitions/address_type/properties/postcode\""
2679
+ " },"
2680
+ " \"allOf\": {"
2681
+ " \"errors\":["
2682
+ " {\"enum\":{\"errorCode\":19,\"instanceRef\":\"#/address/country\",\"schemaRef\":\"#/definitions/country_type\"}}"
2683
+ " ],"
2684
+ " \"errorCode\":23,\"instanceRef\":\"#/address/country\",\"schemaRef\":\"#/definitions/address_type/properties/country\""
2685
+ " },"
2686
+ " \"minItems\": {"
2687
+ " \"actual\": 0, \"expected\": 1, \"errorCode\": 10, \"instanceRef\": \"#/phones\", \"schemaRef\": \"#/properties/phones\""
2688
+ " },"
2689
+ " \"additionalProperties\": {"
2690
+ " \"disallowed\": \"planet\", \"errorCode\": 16, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
2691
+ " },"
2692
+ " \"required\": {"
2693
+ " \"missing\": [\"street1\"], \"errorCode\": 15, \"instanceRef\": \"#/address\", \"schemaRef\": \"#/definitions/address_type\""
2694
+ " }"
2695
+ "}",
2696
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
2697
+ INVALIDATE_(s, "{\"address\": {\"number\": 200, \"street1\": {}, \"street3\": null, \"city\": \"Rom\", \"area\": \"Dorset\", \"postcode\": \"SO51 0GP\"}, \"phones\": [\"0111-222333\", \"0777-666888\", \"0777-666888\"], \"names\": [\"Fred\", \"S\", \"M\", \"Bloggs\"]}", "#", "errors", "#",
2698
+ "{ \"maximum\": {"
2699
+ " \"errorCode\": 3, \"instanceRef\": \"#/address/number\", \"schemaRef\": \"#/definitions/positiveInt_type\", \"expected\": 100, \"actual\": 200, \"exclusiveMaximum\": true"
2700
+ " },"
2701
+ " \"type\": {"
2702
+ " \"expected\": [\"string\"], \"actual\": \"object\", \"errorCode\": 20, \"instanceRef\": \"#/address/street1\", \"schemaRef\": \"#/definitions/address_type/properties/street1\""
2703
+ " },"
2704
+ " \"not\": {"
2705
+ " \"errorCode\": 25, \"instanceRef\": \"#/address/street3\", \"schemaRef\": \"#/definitions/address_type/properties/street3\""
2706
+ " },"
2707
+ " \"minLength\": {"
2708
+ " \"actual\": \"Rom\", \"expected\": 4, \"errorCode\": 7, \"instanceRef\": \"#/address/city\", \"schemaRef\": \"#/definitions/address_type/properties/city\""
2709
+ " },"
2710
+ " \"maxItems\": {"
2711
+ " \"actual\": 3, \"expected\": 2, \"errorCode\": 9, \"instanceRef\": \"#/phones\", \"schemaRef\": \"#/properties/phones\""
2712
+ " },"
2713
+ " \"uniqueItems\": {"
2714
+ " \"duplicates\": [1, 2], \"errorCode\": 11, \"instanceRef\": \"#/phones\", \"schemaRef\": \"#/properties/phones\""
2715
+ " },"
2716
+ " \"minProperties\": {\"actual\": 6, \"expected\": 7, \"errorCode\": 14, \"instanceRef\": \"#/address\", \"schemaRef\": \"#/definitions/address_type\""
2717
+ " },"
2718
+ " \"additionalItems\": ["
2719
+ " {\"disallowed\": 2, \"errorCode\": 12, \"instanceRef\": \"#/names\", \"schemaRef\": \"#/properties/names\"},"
2720
+ " {\"disallowed\": 3, \"errorCode\": 12, \"instanceRef\": \"#/names\", \"schemaRef\": \"#/properties/names\"}"
2721
+ " ],"
2722
+ " \"dependencies\": {"
2723
+ " \"errors\": {"
2724
+ " \"address\": {\"required\": {\"missing\": [\"version\"], \"errorCode\": 15, \"instanceRef\": \"#\", \"schemaRef\": \"#/dependencies/address\"}},"
2725
+ " \"names\": {\"required\": {\"missing\": [\"version\"], \"errorCode\": 15, \"instanceRef\": \"#\", \"schemaRef\": \"#/dependencies/names\"}}"
2726
+ " },"
2727
+ " \"errorCode\": 18, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
2728
+ " },"
2729
+ " \"oneOf\": {"
2730
+ " \"errors\": ["
2731
+ " {\"enum\": {\"errorCode\": 19, \"instanceRef\": \"#/address/area\", \"schemaRef\": \"#/definitions/county_type\"}},"
2732
+ " {\"enum\": {\"errorCode\": 19, \"instanceRef\": \"#/address/area\", \"schemaRef\": \"#/definitions/province_type\"}}"
2733
+ " ],"
2734
+ " \"errorCode\": 21, \"instanceRef\": \"#/address/area\", \"schemaRef\": \"#/definitions/address_type/properties/area\""
2735
+ " }"
2736
+ "}",
2737
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
2738
+
2739
+ CrtAllocator::Free(schema);
2740
+ }
2741
+
2742
+ // Test that when kValidateContinueOnErrorFlag is set, it is not propagated to oneOf sub-validator so we only get the first error.
2743
+ TEST(SchemaValidator, ContinueOnErrors_OneOf) {
2744
+ typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
2745
+ RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
2746
+ CrtAllocator allocator;
2747
+ char* schema = ReadFile("unittestschema/oneOf_address.json", allocator);
2748
+ Document sd;
2749
+ sd.Parse(schema);
2750
+ ASSERT_FALSE(sd.HasParseError());
2751
+ SchemaDocumentType s(sd, 0, 0, &provider);
2752
+ typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
2753
+ typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
2754
+ INVALIDATE_(s, "{\"version\": 1.01, \"address\": {\"number\": 0, \"street2\": false, \"street3\": \"Ham\", \"city\": \"RomseyTownFC\", \"area\": \"BC\", \"country\": \"USA\", \"postcode\": \"999ABC\"}, \"phones\": [], \"planet\": \"Earth\", \"extra\": {\"S_xxx\": 123}}", "#", "errors", "#",
2755
+ "{ \"oneOf\": {"
2756
+ " \"errors\": [{"
2757
+ " \"multipleOf\": {"
2758
+ " \"errorCode\": 1, \"instanceRef\": \"#/version\", \"schemaRef\": \"http://localhost:1234/address.json#/definitions/decimal_type\", \"expected\": 1.0, \"actual\": 1.01"
2759
+ " }"
2760
+ " }],"
2761
+ " \"errorCode\": 21, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
2762
+ " }"
2763
+ "}",
2764
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidatorType, PointerType);
2765
+ CrtAllocator::Free(schema);
2766
+ }
2767
+
2768
+ // Test that when kValidateContinueOnErrorFlag is set, it is not propagated to allOf sub-validator so we only get the first error.
2769
+ TEST(SchemaValidator, ContinueOnErrors_AllOf) {
2770
+ typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
2771
+ RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
2772
+ CrtAllocator allocator;
2773
+ char* schema = ReadFile("unittestschema/allOf_address.json", allocator);
2774
+ Document sd;
2775
+ sd.Parse(schema);
2776
+ ASSERT_FALSE(sd.HasParseError());
2777
+ SchemaDocumentType s(sd, 0, 0, &provider);
2778
+ typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
2779
+ typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
2780
+ INVALIDATE_(s, "{\"version\": 1.01, \"address\": {\"number\": 0, \"street2\": false, \"street3\": \"Ham\", \"city\": \"RomseyTownFC\", \"area\": \"BC\", \"country\": \"USA\", \"postcode\": \"999ABC\"}, \"phones\": [], \"planet\": \"Earth\", \"extra\": {\"S_xxx\": 123}}", "#", "errors", "#",
2781
+ "{ \"allOf\": {"
2782
+ " \"errors\": [{"
2783
+ " \"multipleOf\": {"
2784
+ " \"errorCode\": 1, \"instanceRef\": \"#/version\", \"schemaRef\": \"http://localhost:1234/address.json#/definitions/decimal_type\", \"expected\": 1.0, \"actual\": 1.01"
2785
+ " }"
2786
+ " }],"
2787
+ " \"errorCode\": 23, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
2788
+ " }"
2789
+ "}",
2790
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidatorType, PointerType);
2791
+ CrtAllocator::Free(schema);
2792
+ }
2793
+
2794
+ // Test that when kValidateContinueOnErrorFlag is set, it is not propagated to anyOf sub-validator so we only get the first error.
2795
+ TEST(SchemaValidator, ContinueOnErrors_AnyOf) {
2796
+ typedef GenericSchemaDocument<Value, MemoryPoolAllocator<> > SchemaDocumentType;
2797
+ RemoteSchemaDocumentProvider<SchemaDocumentType> provider;
2798
+ CrtAllocator allocator;
2799
+ char* schema = ReadFile("unittestschema/anyOf_address.json", allocator);
2800
+ Document sd;
2801
+ sd.Parse(schema);
2802
+ ASSERT_FALSE(sd.HasParseError());
2803
+ SchemaDocumentType s(sd, 0, 0, &provider);
2804
+ typedef GenericSchemaValidator<SchemaDocumentType, BaseReaderHandler<UTF8<> >, MemoryPoolAllocator<> > SchemaValidatorType;
2805
+ typedef GenericPointer<Value, MemoryPoolAllocator<> > PointerType;
2806
+ INVALIDATE_(s, "{\"version\": 1.01, \"address\": {\"number\": 0, \"street2\": false, \"street3\": \"Ham\", \"city\": \"RomseyTownFC\", \"area\": \"BC\", \"country\": \"USA\", \"postcode\": \"999ABC\"}, \"phones\": [], \"planet\": \"Earth\", \"extra\": {\"S_xxx\": 123}}", "#", "errors", "#",
2807
+ "{ \"anyOf\": {"
2808
+ " \"errors\": [{"
2809
+ " \"multipleOf\": {"
2810
+ " \"errorCode\": 1, \"instanceRef\": \"#/version\", \"schemaRef\": \"http://localhost:1234/address.json#/definitions/decimal_type\", \"expected\": 1.0, \"actual\": 1.01"
2811
+ " }"
2812
+ " }],"
2813
+ " \"errorCode\": 24, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
2814
+ " }"
2815
+ "}",
2816
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidatorType, PointerType);
2817
+
2818
+ CrtAllocator::Free(schema);
2819
+ }
2820
+
2821
+ // Test that when kValidateContinueOnErrorFlag is set, arrays with uniqueItems:true are correctly processed when an item is invalid.
2822
+ // This tests that we don't blow up if a hasher does not get created.
2823
+ TEST(SchemaValidator, ContinueOnErrors_UniqueItems) {
2824
+ CrtAllocator allocator;
2825
+ char* schema = ReadFile("unittestschema/address.json", allocator);
2826
+ Document sd;
2827
+ sd.Parse(schema);
2828
+ ASSERT_FALSE(sd.HasParseError());
2829
+ SchemaDocument s(sd);
2830
+ VALIDATE(s, "{\"phones\":[\"12-34\",\"56-78\"]}", true);
2831
+ INVALIDATE_(s, "{\"phones\":[\"12-34\",\"12-34\"]}", "#", "errors", "#",
2832
+ "{\"uniqueItems\": {\"duplicates\": [0,1], \"errorCode\": 11, \"instanceRef\": \"#/phones\", \"schemaRef\": \"#/properties/phones\"}}",
2833
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
2834
+ INVALIDATE_(s, "{\"phones\":[\"ab-34\",\"cd-78\"]}", "#", "errors", "#",
2835
+ "{\"pattern\": ["
2836
+ " {\"actual\": \"ab-34\", \"errorCode\": 8, \"instanceRef\": \"#/phones/0\", \"schemaRef\": \"#/definitions/phone_type\"},"
2837
+ " {\"actual\": \"cd-78\", \"errorCode\": 8, \"instanceRef\": \"#/phones/1\", \"schemaRef\": \"#/definitions/phone_type\"}"
2838
+ "]}",
2839
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
2840
+ CrtAllocator::Free(schema);
2841
+ }
2842
+
2843
+ // Test that when kValidateContinueOnErrorFlag is set, an enum field is correctly processed when it has an invalid value.
2844
+ // This tests that we don't blow up if a hasher does not get created.
2845
+ TEST(SchemaValidator, ContinueOnErrors_Enum) {
2846
+ CrtAllocator allocator;
2847
+ char* schema = ReadFile("unittestschema/address.json", allocator);
2848
+ Document sd;
2849
+ sd.Parse(schema);
2850
+ ASSERT_FALSE(sd.HasParseError());
2851
+ SchemaDocument s(sd);
2852
+ VALIDATE(s, "{\"gender\":\"M\"}", true);
2853
+ INVALIDATE_(s, "{\"gender\":\"X\"}", "#", "errors", "#",
2854
+ "{\"enum\": {\"errorCode\": 19, \"instanceRef\": \"#/gender\", \"schemaRef\": \"#/properties/gender\"}}",
2855
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
2856
+ INVALIDATE_(s, "{\"gender\":1}", "#", "errors", "#",
2857
+ "{\"type\": {\"expected\":[\"string\"], \"actual\": \"integer\", \"errorCode\": 20, \"instanceRef\": \"#/gender\", \"schemaRef\": \"#/properties/gender\"}}",
2858
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
2859
+ CrtAllocator::Free(schema);
2860
+ }
2861
+
2862
+ // Test that when kValidateContinueOnErrorFlag is set, an array appearing for an object property is handled
2863
+ // This tests that we don't blow up when there is a type mismatch.
2864
+ TEST(SchemaValidator, ContinueOnErrors_RogueArray) {
2865
+ CrtAllocator allocator;
2866
+ char* schema = ReadFile("unittestschema/address.json", allocator);
2867
+ Document sd;
2868
+ sd.Parse(schema);
2869
+ ASSERT_FALSE(sd.HasParseError());
2870
+ SchemaDocument s(sd);
2871
+ INVALIDATE_(s, "{\"address\":[{\"number\": 0}]}", "#", "errors", "#",
2872
+ "{\"type\": {\"expected\":[\"object\"], \"actual\": \"array\", \"errorCode\": 20, \"instanceRef\": \"#/address\", \"schemaRef\": \"#/definitions/address_type\"},"
2873
+ " \"dependencies\": {"
2874
+ " \"errors\": {"
2875
+ " \"address\": {\"required\": {\"missing\": [\"version\"], \"errorCode\": 15, \"instanceRef\": \"#\", \"schemaRef\": \"#/dependencies/address\"}}"
2876
+ " },\"errorCode\": 18, \"instanceRef\": \"#\", \"schemaRef\": \"#\"}}",
2877
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
2878
+ CrtAllocator::Free(schema);
2879
+ }
2880
+
2881
+ // Test that when kValidateContinueOnErrorFlag is set, an object appearing for an array property is handled
2882
+ // This tests that we don't blow up when there is a type mismatch.
2883
+ TEST(SchemaValidator, ContinueOnErrors_RogueObject) {
2884
+ CrtAllocator allocator;
2885
+ char* schema = ReadFile("unittestschema/address.json", allocator);
2886
+ Document sd;
2887
+ sd.Parse(schema);
2888
+ ASSERT_FALSE(sd.HasParseError());
2889
+ SchemaDocument s(sd);
2890
+ INVALIDATE_(s, "{\"phones\":{\"number\": 0}}", "#", "errors", "#",
2891
+ "{\"type\": {\"expected\":[\"array\"], \"actual\": \"object\", \"errorCode\": 20, \"instanceRef\": \"#/phones\", \"schemaRef\": \"#/properties/phones\"}}",
2892
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
2893
+ CrtAllocator::Free(schema);
2894
+ }
2895
+
2896
+ // Test that when kValidateContinueOnErrorFlag is set, a string appearing for an array or object property is handled
2897
+ // This tests that we don't blow up when there is a type mismatch.
2898
+ TEST(SchemaValidator, ContinueOnErrors_RogueString) {
2899
+ CrtAllocator allocator;
2900
+ char* schema = ReadFile("unittestschema/address.json", allocator);
2901
+ Document sd;
2902
+ sd.Parse(schema);
2903
+ ASSERT_FALSE(sd.HasParseError());
2904
+ SchemaDocument s(sd);
2905
+ INVALIDATE_(s, "{\"address\":\"number\"}", "#", "errors", "#",
2906
+ "{\"type\": {\"expected\":[\"object\"], \"actual\": \"string\", \"errorCode\": 20, \"instanceRef\": \"#/address\", \"schemaRef\": \"#/definitions/address_type\"},"
2907
+ " \"dependencies\": {"
2908
+ " \"errors\": {"
2909
+ " \"address\": {\"required\": {\"missing\": [\"version\"], \"errorCode\": 15, \"instanceRef\": \"#\", \"schemaRef\": \"#/dependencies/address\"}}"
2910
+ " },\"errorCode\": 18, \"instanceRef\": \"#\", \"schemaRef\": \"#\"}}",
2911
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
2912
+ INVALIDATE_(s, "{\"phones\":\"number\"}", "#", "errors", "#",
2913
+ "{\"type\": {\"expected\":[\"array\"], \"actual\": \"string\", \"errorCode\": 20, \"instanceRef\": \"#/phones\", \"schemaRef\": \"#/properties/phones\"}}",
2914
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
2915
+ CrtAllocator::Free(schema);
2916
+ }
2917
+
2918
+ // Test that when kValidateContinueOnErrorFlag is set, an incorrect simple type with a sub-schema is handled correctly.
2919
+ // This tests that we don't blow up when there is a type mismatch but there is a sub-schema present
2920
+ TEST(SchemaValidator, ContinueOnErrors_Issue2) {
2921
+ Document sd;
2922
+ sd.Parse("{\"type\":\"string\", \"anyOf\":[{\"maxLength\":2}]}");
2923
+ ASSERT_FALSE(sd.HasParseError());
2924
+ SchemaDocument s(sd);
2925
+ VALIDATE(s, "\"AB\"", true);
2926
+ INVALIDATE_(s, "\"ABC\"", "#", "errors", "#",
2927
+ "{ \"anyOf\": {"
2928
+ " \"errors\": [{"
2929
+ " \"maxLength\": {"
2930
+ " \"errorCode\": 6, \"instanceRef\": \"#\", \"schemaRef\": \"#/anyOf/0\", \"expected\": 2, \"actual\": \"ABC\""
2931
+ " }"
2932
+ " }],"
2933
+ " \"errorCode\": 24, \"instanceRef\": \"#\", \"schemaRef\": \"#\""
2934
+ " }"
2935
+ "}",
2936
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
2937
+ // Invalid type
2938
+ INVALIDATE_(s, "333", "#", "errors", "#",
2939
+ "{ \"type\": {"
2940
+ " \"errorCode\": 20, \"instanceRef\": \"#\", \"schemaRef\": \"#\", \"expected\": [\"string\"], \"actual\": \"integer\""
2941
+ " }"
2942
+ "}",
2943
+ kValidateDefaultFlags | kValidateContinueOnErrorFlag, SchemaValidator, Pointer);
2944
+ }
2945
+
2946
+ TEST(SchemaValidator, Schema_UnknownError) {
2947
+ ASSERT_TRUE(SchemaValidator::SchemaType::GetValidateErrorKeyword(kValidateErrors).GetString() == std::string("null"));
2948
+ }
2949
+
2950
+ #if defined(_MSC_VER) || defined(__clang__)
2951
+ RAPIDJSON_DIAG_POP
2952
+ #endif