MQTTSuite
Loading...
Searching...
No Matches
issue-255-error-message-limit-precision.cpp
Go to the documentation of this file.
1#include <nlohmann/json-schema.hpp>
2#include <stdexcept>
3
4using nlohmann::json;
5using nlohmann::json_schema::json_validator;
6
7static const json schema = R"(
8{
9 "$schema": "http://json-schema.org/draft-07/schema#",
10 "$id": "arc.schema.json",
11 "properties": {
12 "angle": {
13 "type": "number",
14 "description": "Radians, from -π to π.",
15 "minimum": -3.14159265358979323846,
16 "maximum": 3.14159265358979323846
17 }
18 }
19})"_json;
20
22{
23 void error(const nlohmann::json::json_pointer &ptr, const json &instance, const std::string &message) override
24 {
25 if (message != "instance exceeds maximum of 3.141592653589793")
26 throw std::invalid_argument("Precision print does not work.");
27 }
28};
29
30int main(void)
31{
32 json_validator validator;
33
34 auto instance = R"({ "angle": 3.1415927410125732 })"_json;
35
38 validator.validate(instance, err);
39
40 return 0;
41}
void error(const nlohmann::json::json_pointer &ptr, const json &instance, const std::string &message) override
json validate(const json &, error_handler &, const json_uri &initial_uri=json_uri("#")) const
int main()
Definition format.cpp:34
static const json schema