| 453 | } |
| 454 | |
| 455 | void cross_schema_example() |
| 456 | { |
| 457 | json schema = json::parse(R"( |
| 458 | { |
| 459 | "$schema": "https://json-schema.org/draft/2020-12/schema", |
| 460 | "$id": "https://example.com/schema", |
| 461 | "$defs": { |
| 462 | "foo": { |
| 463 | "$schema": "http://json-schema.org/draft-07/schema#", |
| 464 | "$id": "schema/foo", |
| 465 | "definitions" : { |
| 466 | "bar" : { |
| 467 | "type" : "string" |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | }, |
| 472 | "properties" : { |
| 473 | "thing" : { |
| 474 | "$ref" : "schema/foo#/definitions/bar" |
| 475 | } |
| 476 | } |
| 477 | } |
| 478 | )"); |
| 479 | jsonschema::json_schema<json> compiled = jsonschema::make_json_schema(schema); |
| 480 | |
| 481 | json data = json::parse(R"({"thing" : 10})"); |
| 482 | |
| 483 | jsoncons::json_decoder<ojson> decoder; |
| 484 | compiled.validate(data, decoder); |
| 485 | ojson output = decoder.get_result(); |
| 486 | std::cout << pretty_print(output) << "\n\n"; |
| 487 | } |
| 488 | |
| 489 | void optional_format_example() |
| 490 | { |
no test coverage detected