|
18 | 18 | #include <jsoncons_ext/jsonschema/draft6/schema_validator_factory_6.hpp> |
19 | 19 | #include <jsoncons_ext/jsonschema/draft7/schema_validator_factory_7.hpp> |
20 | 20 |
|
| 21 | +#include <jsoncons/allocator_set.hpp> |
| 22 | + |
21 | 23 | namespace jsoncons { |
22 | 24 | namespace jsonschema { |
23 | 25 |
|
@@ -277,6 +279,79 @@ namespace jsonschema { |
277 | 279 | return json_schema<Json>(schema_validator_factory_base->get_schema_validator()); |
278 | 280 | } |
279 | 281 |
|
| 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 | + |
280 | 355 | } // namespace jsonschema |
281 | 356 | } // namespace jsoncons |
282 | 357 |
|
|
0 commit comments