Skip to content

Commit f643efd

Browse files
committed
Update benchmarks
1 parent 64abcff commit f643efd

3 files changed

Lines changed: 158 additions & 0 deletions

File tree

include/jsoncons/config/version.hpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,15 @@
1313
#define JSONCONS_VERSION_MINOR 4
1414
#define JSONCONS_VERSION_PATCH 1
1515

16+
#define JSONCONS_VERSION_CONCAT_EX(major, minor, patch) \
17+
# major ## "." ## # minor ## "." ## # patch
18+
19+
#define JSONCONS_VERSION_CONCAT(major, minor, patch) \
20+
JSONCONS_VERSION_CONCAT_EX(major, minor, patch)
21+
22+
#define JSONCONS_VERSION \
23+
JSONCONS_VERSION_CONCAT(JSONCONS_VERSION_MAJOR, JSONCONS_VERSION_MINOR, JSONCONS_VERSION_PATCH)
24+
1625
namespace jsoncons {
1726

1827
struct versioning_info

include/jsoncons_ext/jsonschema/json_schema_factory.hpp

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
#include <jsoncons_ext/jsonschema/draft6/schema_validator_factory_6.hpp>
1919
#include <jsoncons_ext/jsonschema/draft7/schema_validator_factory_7.hpp>
2020

21+
#include <jsoncons/allocator_set.hpp>
22+
2123
namespace jsoncons {
2224
namespace jsonschema {
2325

@@ -277,6 +279,79 @@ namespace jsonschema {
277279
return json_schema<Json>(schema_validator_factory_base->get_schema_validator());
278280
}
279281

282+
//
283+
284+
template <typename Alloc,typename TempAlloc,typename Json,typename SchemaResolver>
285+
typename std::enable_if<ext_traits::is_unary_function_object_exact<SchemaResolver,Json,jsoncons::uri>::value,json_schema<Json>>::type
286+
make_json_schema(const allocator_set<Alloc,TempAlloc>& aset, Json sch, const std::string& retrieval_uri, const SchemaResolver& resolver,
287+
evaluation_options options = evaluation_options{})
288+
{
289+
using schema_store_allocator_type = typename std::allocator_traits<TempAlloc>:: template rebind_alloc<std::pair<const jsoncons::uri, schema_validator<Json>*>>;
290+
using schema_store_type = std::map<jsoncons::uri, schema_validator<Json>*, std::less<jsoncons::uri>, schema_store_allocator_type>;
291+
schema_store_type schema_store(aset.get_temp_allocator());
292+
validator_factory_factory<Json> factory_factory{};
293+
294+
std::unordered_map<std::string,bool> vocabulary{};
295+
std::vector<resolve_uri_type<Json>> resolve_funcs = {{meta_resolver<Json>, resolver}};
296+
auto schema_validator_factory_base = factory_factory(std::move(sch), options, &schema_store, resolve_funcs, vocabulary);
297+
298+
schema_validator_factory_base->build_schema(retrieval_uri);
299+
return json_schema<Json>(schema_validator_factory_base->get_schema_validator());
300+
}
301+
302+
template <typename Alloc,typename TempAlloc,typename Json>
303+
json_schema<Json> make_json_schema(const allocator_set<Alloc,TempAlloc>& aset, Json sch, const std::string& retrieval_uri,
304+
evaluation_options options = evaluation_options{})
305+
{
306+
using schema_store_allocator_type = typename std::allocator_traits<TempAlloc>:: template rebind_alloc<std::pair<const jsoncons::uri, schema_validator<Json>*>>;
307+
using schema_store_type = std::map<jsoncons::uri, schema_validator<Json>*, std::less<jsoncons::uri>, schema_store_allocator_type>;
308+
schema_store_type schema_store(aset.get_temp_allocator());
309+
validator_factory_factory<Json> factory_factory{};
310+
311+
std::unordered_map<std::string,bool> vocabulary{};
312+
std::vector<resolve_uri_type<Json>> resolve_funcs = {{meta_resolver<Json>}};
313+
auto schema_validator_factory_base = factory_factory(std::move(sch), options, &schema_store, resolve_funcs, vocabulary);
314+
315+
schema_validator_factory_base->build_schema(retrieval_uri);
316+
return json_schema<Json>(schema_validator_factory_base->get_schema_validator());
317+
}
318+
319+
template <typename Alloc,typename TempAlloc,typename Json,typename SchemaResolver>
320+
typename std::enable_if<ext_traits::is_unary_function_object_exact<SchemaResolver,Json,jsoncons::uri>::value,json_schema<Json>>::type
321+
make_json_schema(const allocator_set<Alloc,TempAlloc>& aset, Json sch, const SchemaResolver& resolver,
322+
evaluation_options options = evaluation_options{})
323+
{
324+
using schema_store_allocator_type = typename std::allocator_traits<TempAlloc>:: template rebind_alloc<std::pair<const jsoncons::uri, schema_validator<Json>*>>;
325+
using schema_store_type = std::map<jsoncons::uri, schema_validator<Json>*, std::less<jsoncons::uri>, schema_store_allocator_type>;
326+
schema_store_type schema_store(aset.get_temp_allocator());
327+
validator_factory_factory<Json> factory_factory{};
328+
329+
std::unordered_map<std::string,bool> vocabulary{};
330+
std::vector<resolve_uri_type<Json>> resolve_funcs = {{meta_resolver<Json>, resolver}};
331+
auto schema_validator_factory_base = factory_factory(std::move(sch), options, &schema_store, resolve_funcs, vocabulary);
332+
333+
schema_validator_factory_base->build_schema();
334+
return json_schema<Json>(schema_validator_factory_base->get_schema_validator());
335+
}
336+
337+
template <typename Alloc,typename TempAlloc,typename Json>
338+
json_schema<Json> make_json_schema(const allocator_set<Alloc,TempAlloc>& aset, Json sch,
339+
evaluation_options options = evaluation_options{})
340+
{
341+
using schema_store_allocator_type = typename std::allocator_traits<TempAlloc>:: template rebind_alloc<std::pair<const jsoncons::uri, schema_validator<Json>*>>;
342+
using schema_store_type = std::map<jsoncons::uri, schema_validator<Json>*,std::less<jsoncons::uri>,schema_store_allocator_type>;
343+
schema_store_type schema_store(aset.get_temp_allocator());
344+
validator_factory_factory<Json> factory_factory{};
345+
346+
std::unordered_map<std::string,bool> vocabulary{};
347+
std::vector<resolve_uri_type<Json>> resolve_funcs = {{meta_resolver<Json>}};
348+
auto schema_validator_factory_base = factory_factory(std::move(sch), options, &schema_store, resolve_funcs, vocabulary);
349+
350+
schema_validator_factory_base->build_schema();
351+
return json_schema<Json>(schema_validator_factory_base->get_schema_validator());
352+
}
353+
354+
280355
} // namespace jsonschema
281356
} // namespace jsoncons
282357

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
// Copyright 2013-2025 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+
#include <jsoncons_ext/jsonschema/jsonschema.hpp>
8+
9+
#include <jsoncons/json.hpp>
10+
#include <jsoncons/utility/byte_string.hpp>
11+
12+
#include <fstream>
13+
#include <iostream>
14+
#include <regex>
15+
#include <catch/catch.hpp>
16+
17+
using jsoncons::json;
18+
using jsoncons::ojson;
19+
namespace jsonschema = jsoncons::jsonschema;
20+
21+
TEST_CASE("jsonschema validation report tests")
22+
{
23+
json schema = json::parse(R"(
24+
{
25+
"$schema": "https://json-schema.org/draft/2020-12/schema",
26+
"$id": "https://test.com/schema",
27+
"$defs": {
28+
"integer": {
29+
"type": "integer"
30+
},
31+
"minimum": {
32+
"minimum": 5
33+
}
34+
},
35+
"type" : "object",
36+
"properties" : {
37+
"passes" : true,
38+
"fails" : false,
39+
"refs" : {"$ref" : "#/$defs/integer"},
40+
"multi" : {
41+
"allOf" : [{"$ref" : "#/$defs/integer"},{"$ref" : "#/$defs/minimum"}]
42+
}
43+
}
44+
}
45+
)");
46+
47+
SECTION("Test 1")
48+
{
49+
ojson expected = ojson::parse(R"(
50+
[
51+
{
52+
"valid": false,
53+
"evaluationPath": "/properties/fails",
54+
"schemaLocation": "https://test.com/schema#/properties/fails",
55+
"instanceLocation": "/fails",
56+
"error": "False schema always fails"
57+
}
58+
]
59+
)");
60+
61+
auto aset = jsoncons::make_alloc_set(std::allocator<char>(),std::allocator<char>());
62+
jsonschema::json_schema<json> compiled = jsonschema::make_json_schema(aset, schema);
63+
64+
json data = json::parse(R"({"fails":"value"})");
65+
66+
jsoncons::json_decoder<ojson> decoder;
67+
compiled.validate(data, decoder);
68+
69+
ojson output = decoder.get_result();
70+
CHECK(expected == output);
71+
//std::cout << pretty_print(output) << "\n";
72+
}
73+
}
74+

0 commit comments

Comments
 (0)