|
|
@@ -24,8 +24,9 @@ private:
|
|
|
std::map<detail::RootReference, detail::Reference, std::greater<>> canonical_to_absolute_;
|
|
|
|
|
|
public:
|
|
|
- ReferenceManager(A const & root, Keywords const & keywords) : roots_{{{}, root}} {
|
|
|
- prime_impl(root, {}, keywords);
|
|
|
+ ReferenceManager(A const & root, schema::Version version, Keywords const & keywords)
|
|
|
+ : roots_{{{}, root}} {
|
|
|
+ prime_impl(root, {}, version, keywords);
|
|
|
}
|
|
|
|
|
|
std::optional<A> root(detail::RootReference const & root) const {
|
|
|
@@ -84,18 +85,19 @@ public:
|
|
|
}
|
|
|
|
|
|
void prime(Adapter auto const & json, detail::RootReference const & where,
|
|
|
- Keywords const & keywords) {
|
|
|
+ schema::Version version, Keywords const & keywords) {
|
|
|
canonical_to_absolute_.emplace(where, detail::Reference(where));
|
|
|
- prime_impl(json, detail::Reference(where), keywords);
|
|
|
+ prime_impl(json, detail::Reference(where), version, keywords);
|
|
|
}
|
|
|
|
|
|
private:
|
|
|
- void prime_impl(Adapter auto const & json, detail::Reference where, Keywords const & keywords) {
|
|
|
+ void prime_impl(Adapter auto const & json, detail::Reference where, schema::Version version,
|
|
|
+ Keywords const & keywords) {
|
|
|
if (json.type() != adapter::Type::Object) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
- canonicalize(where, json);
|
|
|
+ canonicalize(where, version, json);
|
|
|
|
|
|
for (auto const & [key, value] : json.as_object()) {
|
|
|
auto vit = keywords.find(key);
|
|
|
@@ -106,26 +108,27 @@ private:
|
|
|
if (vit->second.contains(schema::Wraps::Array) && value.type() == adapter::Type::Array) {
|
|
|
size_t index = 0;
|
|
|
for (auto const & elem : value.as_array()) {
|
|
|
- prime_impl(elem, where / key / index, keywords);
|
|
|
+ prime_impl(elem, where / key / index, version, keywords);
|
|
|
++index;
|
|
|
}
|
|
|
} else if (vit->second.contains(schema::Wraps::Object) &&
|
|
|
value.type() == adapter::Type::Object) {
|
|
|
for (auto const & [prop, elem] : value.as_object()) {
|
|
|
- prime_impl(elem, where / key / prop, keywords);
|
|
|
+ prime_impl(elem, where / key / prop, version, keywords);
|
|
|
}
|
|
|
} else if (vit->second.contains(schema::Wraps::Schema)) {
|
|
|
- prime_impl(value, where / key, keywords);
|
|
|
+ prime_impl(value, where / key, version, keywords);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void canonicalize(detail::Reference & where, A const & json) {
|
|
|
+ void canonicalize(detail::Reference & where, schema::Version version, A const & json) {
|
|
|
+ std::string const id = version <= schema::Version::Draft04 ? "id" : "$id";
|
|
|
auto const schema = json.as_object();
|
|
|
|
|
|
detail::RootReference root = where.root();
|
|
|
- if (schema.contains("$id")) {
|
|
|
- root = detail::RootReference(schema["$id"].as_string());
|
|
|
+ if (schema.contains(id)) {
|
|
|
+ root = detail::RootReference(schema[id].as_string());
|
|
|
if (root.uri().empty()) {
|
|
|
root = detail::RootReference(where.uri(), root.anchor());
|
|
|
} else if (root.uri().is_rootless() && not where.uri().empty()) {
|
|
|
@@ -136,7 +139,7 @@ private:
|
|
|
cache(root, where, json);
|
|
|
}
|
|
|
|
|
|
- if (not schema.contains("$anchor")) {
|
|
|
+ if (not schema.contains("$anchor") || version < schema::Version::Draft2019_09) {
|
|
|
return;
|
|
|
}
|
|
|
|