jsoncons 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (155) hide show
  1. checksums.yaml +7 -0
  2. data/ext/jsoncons/extconf.rb +43 -0
  3. data/ext/jsoncons/jsoncons.cpp +161 -0
  4. data/ext/jsoncons/jsoncons.h +10 -0
  5. data/jsoncons.gemspec +44 -0
  6. data/lib/jsoncons/jsoncons/examples/input/address-book.json +13 -0
  7. data/lib/jsoncons/jsoncons/examples/input/books.json +28 -0
  8. data/lib/jsoncons/jsoncons/examples/input/countries.json +7 -0
  9. data/lib/jsoncons/jsoncons/examples/input/employees.json +30 -0
  10. data/lib/jsoncons/jsoncons/examples/input/jsonschema/name.json +15 -0
  11. data/lib/jsoncons/jsoncons/examples/input/multiple-json-objects.json +3 -0
  12. data/lib/jsoncons/jsoncons/examples/input/sales.csv +6 -0
  13. data/lib/jsoncons/jsoncons/examples/input/store.json +28 -0
  14. data/lib/jsoncons/jsoncons/examples/input/tasks.csv +6 -0
  15. data/lib/jsoncons/jsoncons/include/jsoncons/allocator_holder.hpp +38 -0
  16. data/lib/jsoncons/jsoncons/include/jsoncons/basic_json.hpp +5905 -0
  17. data/lib/jsoncons/jsoncons/include/jsoncons/bigint.hpp +1611 -0
  18. data/lib/jsoncons/jsoncons/include/jsoncons/byte_string.hpp +820 -0
  19. data/lib/jsoncons/jsoncons/include/jsoncons/config/binary_config.hpp +226 -0
  20. data/lib/jsoncons/jsoncons/include/jsoncons/config/compiler_support.hpp +375 -0
  21. data/lib/jsoncons/jsoncons/include/jsoncons/config/jsoncons_config.hpp +309 -0
  22. data/lib/jsoncons/jsoncons/include/jsoncons/config/version.hpp +40 -0
  23. data/lib/jsoncons/jsoncons/include/jsoncons/conv_error.hpp +218 -0
  24. data/lib/jsoncons/jsoncons/include/jsoncons/decode_json.hpp +209 -0
  25. data/lib/jsoncons/jsoncons/include/jsoncons/decode_traits.hpp +651 -0
  26. data/lib/jsoncons/jsoncons/include/jsoncons/detail/endian.hpp +44 -0
  27. data/lib/jsoncons/jsoncons/include/jsoncons/detail/grisu3.hpp +312 -0
  28. data/lib/jsoncons/jsoncons/include/jsoncons/detail/optional.hpp +483 -0
  29. data/lib/jsoncons/jsoncons/include/jsoncons/detail/parse_number.hpp +1133 -0
  30. data/lib/jsoncons/jsoncons/include/jsoncons/detail/span.hpp +188 -0
  31. data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_view.hpp +537 -0
  32. data/lib/jsoncons/jsoncons/include/jsoncons/detail/string_wrapper.hpp +370 -0
  33. data/lib/jsoncons/jsoncons/include/jsoncons/detail/write_number.hpp +567 -0
  34. data/lib/jsoncons/jsoncons/include/jsoncons/encode_json.hpp +315 -0
  35. data/lib/jsoncons/jsoncons/include/jsoncons/encode_traits.hpp +378 -0
  36. data/lib/jsoncons/jsoncons/include/jsoncons/json.hpp +18 -0
  37. data/lib/jsoncons/jsoncons/include/jsoncons/json_array.hpp +324 -0
  38. data/lib/jsoncons/jsoncons/include/jsoncons/json_content_handler.hpp +12 -0
  39. data/lib/jsoncons/jsoncons/include/jsoncons/json_cursor.hpp +448 -0
  40. data/lib/jsoncons/jsoncons/include/jsoncons/json_decoder.hpp +420 -0
  41. data/lib/jsoncons/jsoncons/include/jsoncons/json_encoder.hpp +1587 -0
  42. data/lib/jsoncons/jsoncons/include/jsoncons/json_error.hpp +156 -0
  43. data/lib/jsoncons/jsoncons/include/jsoncons/json_exception.hpp +241 -0
  44. data/lib/jsoncons/jsoncons/include/jsoncons/json_filter.hpp +653 -0
  45. data/lib/jsoncons/jsoncons/include/jsoncons/json_fwd.hpp +23 -0
  46. data/lib/jsoncons/jsoncons/include/jsoncons/json_object.hpp +1772 -0
  47. data/lib/jsoncons/jsoncons/include/jsoncons/json_options.hpp +862 -0
  48. data/lib/jsoncons/jsoncons/include/jsoncons/json_parser.hpp +2900 -0
  49. data/lib/jsoncons/jsoncons/include/jsoncons/json_reader.hpp +731 -0
  50. data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros.hpp +1072 -0
  51. data/lib/jsoncons/jsoncons/include/jsoncons/json_traits_macros_deprecated.hpp +144 -0
  52. data/lib/jsoncons/jsoncons/include/jsoncons/json_type.hpp +206 -0
  53. data/lib/jsoncons/jsoncons/include/jsoncons/json_type_traits.hpp +1830 -0
  54. data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor.hpp +1560 -0
  55. data/lib/jsoncons/jsoncons/include/jsoncons/json_visitor2.hpp +2079 -0
  56. data/lib/jsoncons/jsoncons/include/jsoncons/pretty_print.hpp +89 -0
  57. data/lib/jsoncons/jsoncons/include/jsoncons/ser_context.hpp +62 -0
  58. data/lib/jsoncons/jsoncons/include/jsoncons/sink.hpp +289 -0
  59. data/lib/jsoncons/jsoncons/include/jsoncons/source.hpp +777 -0
  60. data/lib/jsoncons/jsoncons/include/jsoncons/source_adaptor.hpp +148 -0
  61. data/lib/jsoncons/jsoncons/include/jsoncons/staj2_cursor.hpp +1189 -0
  62. data/lib/jsoncons/jsoncons/include/jsoncons/staj_cursor.hpp +1254 -0
  63. data/lib/jsoncons/jsoncons/include/jsoncons/staj_iterator.hpp +449 -0
  64. data/lib/jsoncons/jsoncons/include/jsoncons/tag_type.hpp +245 -0
  65. data/lib/jsoncons/jsoncons/include/jsoncons/text_source_adaptor.hpp +144 -0
  66. data/lib/jsoncons/jsoncons/include/jsoncons/traits_extension.hpp +884 -0
  67. data/lib/jsoncons/jsoncons/include/jsoncons/typed_array_view.hpp +250 -0
  68. data/lib/jsoncons/jsoncons/include/jsoncons/unicode_traits.hpp +1330 -0
  69. data/lib/jsoncons/jsoncons/include/jsoncons/uri.hpp +635 -0
  70. data/lib/jsoncons/jsoncons/include/jsoncons/value_converter.hpp +340 -0
  71. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson.hpp +23 -0
  72. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_cursor.hpp +320 -0
  73. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_decimal128.hpp +865 -0
  74. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_encoder.hpp +585 -0
  75. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_error.hpp +103 -0
  76. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_oid.hpp +245 -0
  77. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_options.hpp +75 -0
  78. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_parser.hpp +645 -0
  79. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_reader.hpp +92 -0
  80. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/bson_type.hpp +44 -0
  81. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/decode_bson.hpp +201 -0
  82. data/lib/jsoncons/jsoncons/include/jsoncons_ext/bson/encode_bson.hpp +144 -0
  83. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor.hpp +26 -0
  84. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor.hpp +351 -0
  85. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_cursor2.hpp +265 -0
  86. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_detail.hpp +93 -0
  87. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_encoder.hpp +1766 -0
  88. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_error.hpp +105 -0
  89. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_options.hpp +113 -0
  90. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_parser.hpp +1942 -0
  91. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/cbor_reader.hpp +116 -0
  92. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/decode_cbor.hpp +203 -0
  93. data/lib/jsoncons/jsoncons/include/jsoncons_ext/cbor/encode_cbor.hpp +151 -0
  94. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv.hpp +17 -0
  95. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_cursor.hpp +358 -0
  96. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_encoder.hpp +954 -0
  97. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_error.hpp +85 -0
  98. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_options.hpp +973 -0
  99. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_parser.hpp +2099 -0
  100. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_reader.hpp +348 -0
  101. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/csv_serializer.hpp +12 -0
  102. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/decode_csv.hpp +208 -0
  103. data/lib/jsoncons/jsoncons/include/jsoncons_ext/csv/encode_csv.hpp +122 -0
  104. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath.hpp +5215 -0
  105. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jmespath/jmespath_error.hpp +215 -0
  106. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch.hpp +579 -0
  107. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpatch/jsonpatch_error.hpp +121 -0
  108. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/expression.hpp +3329 -0
  109. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/flatten.hpp +432 -0
  110. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_location.hpp +445 -0
  111. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/json_query.hpp +115 -0
  112. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath.hpp +13 -0
  113. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_error.hpp +240 -0
  114. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_expression.hpp +2612 -0
  115. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpath/jsonpath_selector.hpp +1322 -0
  116. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer.hpp +1577 -0
  117. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonpointer/jsonpointer_error.hpp +119 -0
  118. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/format_validator.hpp +968 -0
  119. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/json_validator.hpp +120 -0
  120. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema.hpp +13 -0
  121. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_error.hpp +105 -0
  122. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/jsonschema_version.hpp +18 -0
  123. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator.hpp +1745 -0
  124. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/keyword_validator_factory.hpp +556 -0
  125. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_draft7.hpp +198 -0
  126. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_location.hpp +200 -0
  127. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/schema_version.hpp +35 -0
  128. data/lib/jsoncons/jsoncons/include/jsoncons_ext/jsonschema/subschema.hpp +144 -0
  129. data/lib/jsoncons/jsoncons/include/jsoncons_ext/mergepatch/mergepatch.hpp +103 -0
  130. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/decode_msgpack.hpp +202 -0
  131. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/encode_msgpack.hpp +142 -0
  132. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack.hpp +24 -0
  133. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor.hpp +343 -0
  134. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_cursor2.hpp +259 -0
  135. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_encoder.hpp +753 -0
  136. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_error.hpp +94 -0
  137. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_options.hpp +74 -0
  138. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_parser.hpp +748 -0
  139. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_reader.hpp +116 -0
  140. data/lib/jsoncons/jsoncons/include/jsoncons_ext/msgpack/msgpack_type.hpp +63 -0
  141. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/decode_ubjson.hpp +201 -0
  142. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/encode_ubjson.hpp +142 -0
  143. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson.hpp +23 -0
  144. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_cursor.hpp +307 -0
  145. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_encoder.hpp +502 -0
  146. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_error.hpp +100 -0
  147. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_options.hpp +87 -0
  148. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_parser.hpp +880 -0
  149. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_reader.hpp +92 -0
  150. data/lib/jsoncons/jsoncons/include/jsoncons_ext/ubjson/ubjson_type.hpp +43 -0
  151. data/lib/jsoncons/version.rb +5 -0
  152. data/lib/jsoncons.rb +33 -0
  153. data/test/jsoncons_test.rb +108 -0
  154. data/test/test_helper.rb +7 -0
  155. metadata +268 -0
@@ -0,0 +1,198 @@
1
+ // Copyright 2020 Daniel Parker
2
+ // Distributed under the Boost license, Version 1.0.
3
+ // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
+
5
+ // See https://github.com/danielaparker/jsoncons for latest version
6
+
7
+ #ifndef JSONCONS_JSONSCHEMA_SCHEMA_DRAFT7_HPP
8
+ #define JSONCONS_JSONSCHEMA_SCHEMA_DRAFT7_HPP
9
+
10
+ #include <jsoncons/json.hpp>
11
+
12
+ namespace jsoncons {
13
+ namespace jsonschema {
14
+
15
+ template <class Json>
16
+ struct schema_draft7
17
+ {
18
+ static Json get_schema()
19
+ {
20
+ static Json schema = Json::parse(R"(
21
+ {
22
+ "$schema": "http://json-schema.org/draft-07/schema#",
23
+ "$id": "http://json-schema.org/draft-07/schema#",
24
+ "title": "Core schema meta-schema",
25
+ "definitions": {
26
+ "schemaArray": {
27
+ "type": "array",
28
+ "minItems": 1,
29
+ "items": { "$ref": "#" }
30
+ },
31
+ "nonNegativeInteger": {
32
+ "type": "integer",
33
+ "minimum": 0
34
+ },
35
+ "nonNegativeIntegerDefault0": {
36
+ "allOf": [
37
+ { "$ref": "#/definitions/nonNegativeInteger" },
38
+ { "default": 0 }
39
+ ]
40
+ },
41
+ "simpleTypes": {
42
+ "enum": [
43
+ "array",
44
+ "boolean",
45
+ "integer",
46
+ "null",
47
+ "number",
48
+ "object",
49
+ "string"
50
+ ]
51
+ },
52
+ "stringArray": {
53
+ "type": "array",
54
+ "items": { "type": "string" },
55
+ "uniqueItems": true,
56
+ "default": []
57
+ }
58
+ },
59
+ "type": ["object", "boolean"],
60
+ "properties": {
61
+ "$id": {
62
+ "type": "string",
63
+ "format": "uri-reference"
64
+ },
65
+ "$schema": {
66
+ "type": "string",
67
+ "format": "uri"
68
+ },
69
+ "$ref": {
70
+ "type": "string",
71
+ "format": "uri-reference"
72
+ },
73
+ "$comment": {
74
+ "type": "string"
75
+ },
76
+ "title": {
77
+ "type": "string"
78
+ },
79
+ "description": {
80
+ "type": "string"
81
+ },
82
+ "default": true,
83
+ "readOnly": {
84
+ "type": "boolean",
85
+ "default": false
86
+ },
87
+ "examples": {
88
+ "type": "array",
89
+ "items": true
90
+ },
91
+ "multipleOf": {
92
+ "type": "number",
93
+ "exclusiveMinimum": 0
94
+ },
95
+ "maximum": {
96
+ "type": "number"
97
+ },
98
+ "exclusiveMaximum": {
99
+ "type": "number"
100
+ },
101
+ "minimum": {
102
+ "type": "number"
103
+ },
104
+ "exclusiveMinimum": {
105
+ "type": "number"
106
+ },
107
+ "maxLength": { "$ref": "#/definitions/nonNegativeInteger" },
108
+ "minLength": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
109
+ "pattern": {
110
+ "type": "string",
111
+ "format": "regex"
112
+ },
113
+ "additionalItems": { "$ref": "#" },
114
+ "items": {
115
+ "anyOf": [
116
+ { "$ref": "#" },
117
+ { "$ref": "#/definitions/schemaArray" }
118
+ ],
119
+ "default": true
120
+ },
121
+ "maxItems": { "$ref": "#/definitions/nonNegativeInteger" },
122
+ "minItems": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
123
+ "uniqueItems": {
124
+ "type": "boolean",
125
+ "default": false
126
+ },
127
+ "contains": { "$ref": "#" },
128
+ "maxProperties": { "$ref": "#/definitions/nonNegativeInteger" },
129
+ "minProperties": { "$ref": "#/definitions/nonNegativeIntegerDefault0" },
130
+ "required": { "$ref": "#/definitions/stringArray" },
131
+ "additionalProperties": { "$ref": "#" },
132
+ "definitions": {
133
+ "type": "object",
134
+ "additionalProperties": { "$ref": "#" },
135
+ "default": {}
136
+ },
137
+ "properties": {
138
+ "type": "object",
139
+ "additionalProperties": { "$ref": "#" },
140
+ "default": {}
141
+ },
142
+ "patternProperties": {
143
+ "type": "object",
144
+ "additionalProperties": { "$ref": "#" },
145
+ "propertyNames": { "format": "regex" },
146
+ "default": {}
147
+ },
148
+ "dependencies": {
149
+ "type": "object",
150
+ "additionalProperties": {
151
+ "anyOf": [
152
+ { "$ref": "#" },
153
+ { "$ref": "#/definitions/stringArray" }
154
+ ]
155
+ }
156
+ },
157
+ "propertyNames": { "$ref": "#" },
158
+ "const": true,
159
+ "enum": {
160
+ "type": "array",
161
+ "items": true,
162
+ "minItems": 1,
163
+ "uniqueItems": true
164
+ },
165
+ "type": {
166
+ "anyOf": [
167
+ { "$ref": "#/definitions/simpleTypes" },
168
+ {
169
+ "type": "array",
170
+ "items": { "$ref": "#/definitions/simpleTypes" },
171
+ "minItems": 1,
172
+ "uniqueItems": true
173
+ }
174
+ ]
175
+ },
176
+ "format": { "type": "string" },
177
+ "contentMediaType": { "type": "string" },
178
+ "contentEncoding": { "type": "string" },
179
+ "if": { "$ref": "#" },
180
+ "then": { "$ref": "#" },
181
+ "else": { "$ref": "#" },
182
+ "allOf": { "$ref": "#/definitions/schemaArray" },
183
+ "anyOf": { "$ref": "#/definitions/schemaArray" },
184
+ "oneOf": { "$ref": "#/definitions/schemaArray" },
185
+ "not": { "$ref": "#" }
186
+ },
187
+ "default": true
188
+ }
189
+ )");
190
+
191
+ return schema;
192
+ }
193
+ };
194
+
195
+ } // namespace jsonschema
196
+ } // namespace jsoncons
197
+
198
+ #endif // JSONCONS_JSONSCHEMA_SCHEMA_DRAFT7_HPP
@@ -0,0 +1,200 @@
1
+ // Copyright 2020 Daniel Parker
2
+ // Distributed under the Boost license, Version 1.0.
3
+ // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
+
5
+ // See https://github.com/danielaparker/jsoncons for latest version
6
+
7
+ #ifndef JSONCONS_JSONSCHEMA_SCHEMA_LOCATION_HPP
8
+ #define JSONCONS_JSONSCHEMA_SCHEMA_LOCATION_HPP
9
+
10
+ #include <jsoncons/config/jsoncons_config.hpp>
11
+ #include <jsoncons/uri.hpp>
12
+ #include <jsoncons/json.hpp>
13
+ #include <jsoncons_ext/jsonpointer/jsonpointer.hpp>
14
+ #include <jsoncons_ext/jsonschema/jsonschema_error.hpp>
15
+
16
+ namespace jsoncons {
17
+ namespace jsonschema {
18
+
19
+ class schema_location
20
+ {
21
+ jsoncons::uri uri_;
22
+ std::string identifier_;
23
+ public:
24
+ schema_location()
25
+ {
26
+ }
27
+
28
+ schema_location(const std::string& uri)
29
+ {
30
+ auto pos = uri.find('#');
31
+ if (pos != std::string::npos)
32
+ {
33
+ identifier_ = uri.substr(pos + 1);
34
+ unescape_percent(identifier_);
35
+ }
36
+ uri_ = jsoncons::uri(uri);
37
+ }
38
+
39
+ jsoncons::uri uri() const
40
+ {
41
+ return uri_;
42
+ }
43
+
44
+ bool has_fragment() const
45
+ {
46
+ return !identifier_.empty();
47
+ }
48
+
49
+ bool has_identifier() const
50
+ {
51
+ return !identifier_.empty() && identifier_.front() != '/';
52
+ }
53
+
54
+ jsoncons::string_view base() const
55
+ {
56
+ return uri_.base();
57
+ }
58
+
59
+ jsoncons::string_view path() const
60
+ {
61
+ return uri_.path();
62
+ }
63
+
64
+ bool is_absolute() const
65
+ {
66
+ return uri_.is_absolute();
67
+ }
68
+
69
+ std::string identifier() const
70
+ {
71
+ return identifier_;
72
+ }
73
+
74
+ std::string fragment() const
75
+ {
76
+ return identifier_;
77
+ }
78
+
79
+ schema_location resolve(const schema_location& uri) const
80
+ {
81
+ schema_location new_uri;
82
+ new_uri.identifier_ = identifier_;
83
+ new_uri.uri_ = uri_.resolve(uri.uri_);
84
+ return new_uri;
85
+ }
86
+
87
+ int compare(const schema_location& other) const
88
+ {
89
+ int result = uri_.compare(other.uri_);
90
+ if (result != 0)
91
+ {
92
+ return result;
93
+ }
94
+ return result;
95
+ }
96
+
97
+ schema_location append(const std::string& field) const
98
+ {
99
+ if (has_identifier())
100
+ return *this;
101
+
102
+ jsoncons::jsonpointer::json_pointer pointer(std::string(uri_.fragment()));
103
+ pointer /= field;
104
+
105
+ jsoncons::uri new_uri(uri_.scheme(),
106
+ uri_.userinfo(),
107
+ uri_.host(),
108
+ uri_.port(),
109
+ uri_.path(),
110
+ uri_.query(),
111
+ pointer.to_string());
112
+
113
+ schema_location wrapper;
114
+ wrapper.uri_ = new_uri;
115
+ wrapper.identifier_ = pointer.to_string();
116
+
117
+ return wrapper;
118
+ }
119
+
120
+ schema_location append(std::size_t index) const
121
+ {
122
+ if (has_identifier())
123
+ return *this;
124
+
125
+ jsoncons::jsonpointer::json_pointer pointer(std::string(uri_.fragment()));
126
+ pointer /= index;
127
+
128
+ jsoncons::uri new_uri(uri_.scheme(),
129
+ uri_.userinfo(),
130
+ uri_.host(),
131
+ uri_.port(),
132
+ uri_.path(),
133
+ uri_.query(),
134
+ pointer.to_string());
135
+
136
+ schema_location wrapper;
137
+ wrapper.uri_ = new_uri;
138
+ wrapper.identifier_ = pointer.to_string();
139
+
140
+ return wrapper;
141
+ }
142
+
143
+ std::string string() const
144
+ {
145
+ std::string s = uri_.string();
146
+ return s;
147
+ }
148
+
149
+ friend bool operator==(const schema_location& lhs, const schema_location& rhs)
150
+ {
151
+ return lhs.compare(rhs) == 0;
152
+ }
153
+
154
+ friend bool operator!=(const schema_location& lhs, const schema_location& rhs)
155
+ {
156
+ return lhs.compare(rhs) != 0;
157
+ }
158
+
159
+ friend bool operator<(const schema_location& lhs, const schema_location& rhs)
160
+ {
161
+ return lhs.compare(rhs) < 0;
162
+ }
163
+
164
+ friend bool operator<=(const schema_location& lhs, const schema_location& rhs)
165
+ {
166
+ return lhs.compare(rhs) <= 0;
167
+ }
168
+
169
+ friend bool operator>(const schema_location& lhs, const schema_location& rhs)
170
+ {
171
+ return lhs.compare(rhs) > 0;
172
+ }
173
+
174
+ friend bool operator>=(const schema_location& lhs, const schema_location& rhs)
175
+ {
176
+ return lhs.compare(rhs) >= 0;
177
+ }
178
+ private:
179
+ static void unescape_percent(std::string& s)
180
+ {
181
+ if (s.size() >= 3)
182
+ {
183
+ std::size_t pos = s.size() - 2;
184
+ while (pos-- >= 1)
185
+ {
186
+ if (s[pos] == '%')
187
+ {
188
+ std::string hex = s.substr(pos + 1, 2);
189
+ char ch = (char) std::strtoul(hex.c_str(), nullptr, 16);
190
+ s.replace(pos, 3, 1, ch);
191
+ }
192
+ }
193
+ }
194
+ }
195
+ };
196
+
197
+ } // namespace jsonschema
198
+ } // namespace jsoncons
199
+
200
+ #endif // JSONCONS_JSONSCHEMA_RULE_HPP
@@ -0,0 +1,35 @@
1
+ // Copyright 2021 Daniel Parker
2
+ // Distributed under the Boost license, Version 1.0.
3
+ // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
+
5
+ // See https://github.com/danielaparker/jsoncons for latest version
6
+
7
+ #ifndef JSONCONS_JSONSCHEMA_SCHEMA_VERSION_HPP
8
+ #define JSONCONS_JSONSCHEMA_SCHEMA_VERSION_HPP
9
+
10
+ #include <jsoncons/json.hpp>
11
+
12
+ namespace jsoncons {
13
+ namespace jsonschema {
14
+
15
+ class schema_version
16
+ {
17
+ public:
18
+ static bool contains(const string_view& url)
19
+ {
20
+ if (url.find("json-schema.org/draft-07/schema#") != string_view::npos)
21
+ {
22
+ return true;
23
+ }
24
+ else
25
+ {
26
+ return false;
27
+ }
28
+ }
29
+ };
30
+
31
+
32
+ } // namespace jsonschema
33
+ } // namespace jsoncons
34
+
35
+ #endif // JSONCONS_JSONSCHEMA_JSONSCHEMA_VERSION_HPP
@@ -0,0 +1,144 @@
1
+ // Copyright 2020 Daniel Parker
2
+ // Distributed under the Boost license, Version 1.0.
3
+ // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
+
5
+ // See https://github.com/danielaparker/jsoncons for latest version
6
+
7
+ #ifndef JSONCONS_JSONSCHEMA_SUBSCHEMA_HPP
8
+ #define JSONCONS_JSONSCHEMA_SUBSCHEMA_HPP
9
+
10
+ #include <jsoncons/config/jsoncons_config.hpp>
11
+ #include <jsoncons/uri.hpp>
12
+ #include <jsoncons/json.hpp>
13
+ #include <jsoncons_ext/jsonpointer/jsonpointer.hpp>
14
+ #include <jsoncons_ext/jsonschema/jsonschema_error.hpp>
15
+ #include <jsoncons_ext/jsonschema/schema_location.hpp>
16
+
17
+ namespace jsoncons {
18
+ namespace jsonschema {
19
+
20
+ // Interface for validation error handlers
21
+ class error_reporter
22
+ {
23
+ bool fail_early_;
24
+ std::size_t error_count_;
25
+ public:
26
+ error_reporter(bool fail_early = false)
27
+ : fail_early_(fail_early), error_count_(0)
28
+ {
29
+ }
30
+
31
+ virtual ~error_reporter() = default;
32
+
33
+ void error(const validation_output& o)
34
+ {
35
+ ++error_count_;
36
+ do_error(o);
37
+ }
38
+
39
+ std::size_t error_count() const
40
+ {
41
+ return error_count_;
42
+ }
43
+
44
+ bool fail_early() const
45
+ {
46
+ return fail_early_;
47
+ }
48
+
49
+ private:
50
+ virtual void do_error(const validation_output& /* e */) = 0;
51
+ };
52
+
53
+ template <class Json>
54
+ class keyword_validator
55
+ {
56
+ std::string absolute_keyword_location_;
57
+ public:
58
+ using self_pointer = keyword_validator<Json>*;
59
+
60
+ keyword_validator(const std::string& absolute_keyword_location)
61
+ : absolute_keyword_location_(absolute_keyword_location)
62
+ {
63
+ }
64
+
65
+ keyword_validator(const keyword_validator&) = delete;
66
+ keyword_validator(keyword_validator&&) = default;
67
+ keyword_validator& operator=(const keyword_validator&) = delete;
68
+ keyword_validator& operator=(keyword_validator&&) = default;
69
+
70
+ virtual ~keyword_validator() = default;
71
+
72
+ const std::string& absolute_keyword_location() const
73
+ {
74
+ return absolute_keyword_location_;
75
+ }
76
+
77
+ void validate(const Json& instance,
78
+ const jsonpointer::json_pointer& instance_location,
79
+ error_reporter& reporter,
80
+ Json& patch) const
81
+ {
82
+ do_validate(instance,
83
+ instance_location,
84
+ reporter,
85
+ patch);
86
+ }
87
+
88
+ virtual jsoncons::optional<Json> get_default_value(const jsonpointer::json_pointer&, const Json&, error_reporter&) const
89
+ {
90
+ return jsoncons::optional<Json>();
91
+ }
92
+
93
+ private:
94
+ virtual void do_validate(const Json& instance,
95
+ const jsonpointer::json_pointer& instance_location,
96
+ error_reporter& reporter,
97
+ Json& patch) const = 0;
98
+ };
99
+
100
+ template <class Json>
101
+ std::vector<schema_location> update_uris(const Json& schema,
102
+ const std::vector<schema_location>& uris,
103
+ const std::vector<std::string>& keys)
104
+ {
105
+ // Exclude uri's that are not plain name identifiers
106
+ std::vector<schema_location> new_uris;
107
+ for (const auto& uri : uris)
108
+ {
109
+ if (!uri.has_identifier())
110
+ new_uris.push_back(uri);
111
+ }
112
+
113
+ // Append the keys for this sub-schema to the uri's
114
+ for (const auto& key : keys)
115
+ {
116
+ for (auto& uri : new_uris)
117
+ {
118
+ auto new_u = uri.append(key);
119
+ uri = schema_location(new_u);
120
+ }
121
+ }
122
+ if (schema.type() == json_type::object_value)
123
+ {
124
+ auto it = schema.find("$id"); // If $id is found, this schema can be referenced by the id
125
+ if (it != schema.object_range().end())
126
+ {
127
+ std::string id = it->value().template as<std::string>();
128
+ // Add it to the list if it is not already there
129
+ if (std::find(new_uris.begin(), new_uris.end(), id) == new_uris.end())
130
+ {
131
+ schema_location relative(id);
132
+ schema_location new_uri = relative.resolve(new_uris.back());
133
+ new_uris.emplace_back(new_uri);
134
+ }
135
+ }
136
+ }
137
+
138
+ return new_uris;
139
+ }
140
+
141
+ } // namespace jsonschema
142
+ } // namespace jsoncons
143
+
144
+ #endif // JSONCONS_JSONSCHEMA_RULE_HPP
@@ -0,0 +1,103 @@
1
+ // Copyright 2017 Daniel Parker
2
+ // Distributed under the Boost license, Version 1.0.
3
+ // (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
4
+
5
+ // See https://github.com/danielaparker/jsoncons for latest version
6
+
7
+ #ifndef JSONCONS_JSONMERGEPATCH_JSONMERGEPATCH_HPP
8
+ #define JSONCONS_JSONMERGEPATCH_JSONMERGEPATCH_HPP
9
+
10
+ #include <string>
11
+ #include <vector>
12
+ #include <memory>
13
+ #include <algorithm> // std::min
14
+ #include <utility> // std::move
15
+ #include <jsoncons/json.hpp>
16
+
17
+ namespace jsoncons {
18
+ namespace mergepatch {
19
+
20
+ template <class Json>
21
+ Json from_diff(const Json& source, const Json& target)
22
+ {
23
+ if (!source.is_object() || !target.is_object())
24
+ {
25
+ return target;
26
+ }
27
+ Json result(json_object_arg);
28
+
29
+ for (const auto& member : source.object_range())
30
+ {
31
+ auto it = target.find(member.key());
32
+ if (it != target.object_range().end())
33
+ {
34
+ if (member.value() != it->value())
35
+ {
36
+ result.try_emplace(member.key(), from_diff(member.value(), it->value()));
37
+ }
38
+ }
39
+ else
40
+ {
41
+ result.try_emplace(member.key(), Json::null());
42
+ }
43
+ }
44
+
45
+ for (const auto& member : target.object_range())
46
+ {
47
+ auto it = source.find(member.key());
48
+ if (it == source.object_range().end())
49
+ {
50
+ result.try_emplace(member.key(), member.value());
51
+ }
52
+ }
53
+
54
+ return result;
55
+ }
56
+
57
+ namespace detail {
58
+ template <class Json>
59
+ Json apply_merge_patch_(Json& target, const Json& patch)
60
+ {
61
+ if (patch.is_object())
62
+ {
63
+ if (!target.is_object())
64
+ {
65
+ target = Json(json_object_arg);
66
+ }
67
+ for (auto& member : patch.object_range())
68
+ {
69
+ auto it = target.find(member.key());
70
+ if (it != target.object_range().end())
71
+ {
72
+ Json item = it->value();
73
+ target.erase(it);
74
+ if (!member.value().is_null())
75
+ {
76
+ target.try_emplace(member.key(), apply_merge_patch_(item, member.value()));
77
+ }
78
+ }
79
+ else if (!member.value().is_null())
80
+ {
81
+ Json item(json_object_arg);
82
+ target.try_emplace(member.key(), apply_merge_patch_(item, member.value()));
83
+ }
84
+ }
85
+ return target;
86
+ }
87
+ else
88
+ {
89
+ return patch;
90
+ }
91
+ }
92
+ } // namespace detail
93
+
94
+ template <class Json>
95
+ void apply_merge_patch(Json& target, const Json& patch)
96
+ {
97
+ target = detail::apply_merge_patch_(target, patch);
98
+ }
99
+
100
+ } // namespace mergepatch
101
+ } // namespace jsoncons
102
+
103
+ #endif