| 155 | } |
| 156 | |
| 157 | void Item::validate() |
| 158 | { |
| 159 | |
| 160 | nlohmann::json_schema::json_validator val( |
| 161 | [this](const nlohmann::json_uri& json_uri, nlohmann::json& json) { |
| 162 | json = m_connector.getJson(json_uri.url()); |
| 163 | }, |
| 164 | [](const std::string &, const std::string &) {} |
| 165 | ); |
| 166 | |
| 167 | // Validate against base Item schema first |
| 168 | NL::json schemaJson = m_connector.getJson(m_schemaUrls.item); |
| 169 | val.set_root_schema(schemaJson); |
| 170 | try { |
| 171 | val.validate(m_json); |
| 172 | } |
| 173 | catch (std::exception &e) |
| 174 | { |
| 175 | throw stac_error(m_id, "item", |
| 176 | "STAC schema validation Error in root schema: " + |
| 177 | m_schemaUrls.item + ". \n\n" + e.what()); |
| 178 | } |
| 179 | |
| 180 | // Validate against stac extensions if present |
| 181 | if (m_json.contains("stac_extensions")) |
| 182 | { |
| 183 | NL::json extensions = stacValue(m_json, "stac_extensions"); |
| 184 | for (auto& extSchemaUrl: extensions) |
| 185 | { |
| 186 | std::string url = stacValue<std::string>(extSchemaUrl, "", m_json); |
| 187 | |
| 188 | try { |
| 189 | NL::json schemaJson = m_connector.getJson(url); |
| 190 | val.set_root_schema(schemaJson); |
| 191 | val.validate(m_json); |
| 192 | } |
| 193 | catch (std::exception& e) { |
| 194 | std::string msg = |
| 195 | "STAC Validation Error in extension: " + url + |
| 196 | ". Errors found: \n" + e.what(); |
| 197 | throw stac_error(m_id, "item", msg); |
| 198 | |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | void validateForFilter(NL::json json) |
| 205 | { |
no test coverage detected