MQTTSuite
Loading...
Searching...
No Matches
json_schema_validator Class Reference
Collaboration diagram for json_schema_validator:

Public Member Functions

void insert_schema (json &s, std::vector< nlohmann::json_uri > base_uris)
void insert_schema (json &s, std::vector< nlohmann::json_uri > base_uris)

Public Attributes

std::vector< jsonschemas_
std::map< nlohmann::json_uri, const json * > schema_store_

Detailed Description

Definition at line 89 of file id-ref.cpp.

Member Function Documentation

◆ insert_schema() [1/2]

void json_schema_validator::insert_schema ( json & s,
std::vector< nlohmann::json_uri > base_uris )
inline

Definition at line 96 of file id-ref.cpp.

97 {
98 auto id = s.find("$id");
99 if (id != s.end())
100 base_uris.push_back(base_uris.back().derive(id.value()));
101
102 for (auto &u : base_uris)
103 schema_store_[u] = &s;
104
105 for (auto i = s.begin();
106 i != s.end();
107 ++i) {
108
109 switch (i.value().type()) {
110 case json::value_t::object: { // child is object, thus a schema
111 std::vector<nlohmann::json_uri> subschema_uri = base_uris;
112
113 for (auto &ss : subschema_uri)
114 ss = ss.append(nlohmann::json_uri::escape(i.key()));
115
116 insert_schema(i.value(), subschema_uri);
117 } break;
118
119 case json::value_t::string:
120 // this schema is a reference
121 if (i.key() == "$ref") {
122 auto id = base_uris.back().derive(i.value());
123 i.value() = id.to_string();
124 }
125
126 break;
127
128 default:
129 break;
130 }
131 }
132 }
std::map< nlohmann::json_uri, const json * > schema_store_
Definition id-ref.cpp:93
void insert_schema(json &s, std::vector< nlohmann::json_uri > base_uris)
Definition id-ref.cpp:96
static std::string escape(const std::string &)
Definition json-uri.cpp:137

References nlohmann::json_uri::append(), nlohmann::json_uri::derive(), nlohmann::json_uri::escape(), insert_schema(), schema_store_, and nlohmann::json_uri::to_string().

Referenced by insert_schema(), and main().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ insert_schema() [2/2]

void json_schema_validator::insert_schema ( json & s,
std::vector< nlohmann::json_uri > base_uris )
inline

Definition at line 96 of file id-ref.cpp.

97 {
98 auto id = s.find("$id");
99 if (id != s.end())
100 base_uris.push_back(base_uris.back().derive(id.value()));
101
102 for (auto &u : base_uris)
103 schema_store_[u] = &s;
104
105 for (auto i = s.begin();
106 i != s.end();
107 ++i) {
108
109 switch (i.value().type()) {
110 case json::value_t::object: { // child is object, thus a schema
111 std::vector<nlohmann::json_uri> subschema_uri = base_uris;
112
113 for (auto &ss : subschema_uri)
114 ss = ss.append(nlohmann::json_uri::escape(i.key()));
115
116 insert_schema(i.value(), subschema_uri);
117 } break;
118
119 case json::value_t::string:
120 // this schema is a reference
121 if (i.key() == "$ref") {
122 auto id = base_uris.back().derive(i.value());
123 i.value() = id.to_string();
124 }
125
126 break;
127
128 default:
129 break;
130 }
131 }
132 }

Member Data Documentation

◆ schema_store_

std::map< nlohmann::json_uri, const json * > json_schema_validator::schema_store_

Definition at line 93 of file id-ref.cpp.

Referenced by insert_schema(), and main().

◆ schemas_

std::vector< json > json_schema_validator::schemas_

Definition at line 92 of file id-ref.cpp.


The documentation for this class was generated from the following file: