|
@@ -6,9 +6,11 @@
|
|
|
#include <unordered_map>
|
|
#include <unordered_map>
|
|
|
|
|
|
|
|
#include <jvalidate/detail/anchor.h>
|
|
#include <jvalidate/detail/anchor.h>
|
|
|
|
|
+#include <jvalidate/detail/parser_context.h>
|
|
|
#include <jvalidate/detail/pointer.h>
|
|
#include <jvalidate/detail/pointer.h>
|
|
|
#include <jvalidate/detail/reference.h>
|
|
#include <jvalidate/detail/reference.h>
|
|
|
#include <jvalidate/detail/reference_cache.h>
|
|
#include <jvalidate/detail/reference_cache.h>
|
|
|
|
|
+#include <jvalidate/document_cache.h>
|
|
|
#include <jvalidate/enum.h>
|
|
#include <jvalidate/enum.h>
|
|
|
#include <jvalidate/forward.h>
|
|
#include <jvalidate/forward.h>
|
|
|
#include <jvalidate/uri.h>
|
|
#include <jvalidate/uri.h>
|
|
@@ -19,15 +21,16 @@ public:
|
|
|
using Keywords = std::unordered_map<std::string_view, std::set<schema::Wraps>>;
|
|
using Keywords = std::unordered_map<std::string_view, std::set<schema::Wraps>>;
|
|
|
|
|
|
|
|
private:
|
|
private:
|
|
|
- std::map<detail::RootReference, A> roots_;
|
|
|
|
|
-
|
|
|
|
|
|
|
+ DocumentCache<A> & external_;
|
|
|
detail::ReferenceCache references_;
|
|
detail::ReferenceCache references_;
|
|
|
|
|
|
|
|
|
|
+ std::map<detail::RootReference, A> roots_;
|
|
|
std::multimap<URI, detail::Anchor> dynamic_anchors_;
|
|
std::multimap<URI, detail::Anchor> dynamic_anchors_;
|
|
|
|
|
|
|
|
public:
|
|
public:
|
|
|
- ReferenceManager(A const & root, schema::Version version, Keywords const & keywords)
|
|
|
|
|
- : roots_{{{}, root}} {
|
|
|
|
|
|
|
+ ReferenceManager(DocumentCache<A> & external, A const & root, schema::Version version,
|
|
|
|
|
+ Keywords const & keywords)
|
|
|
|
|
+ : external_(external), roots_{{{}, root}} {
|
|
|
prime_impl(root, {}, version, keywords);
|
|
prime_impl(root, {}, version, keywords);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -47,6 +50,28 @@ public:
|
|
|
return std::nullopt;
|
|
return std::nullopt;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ std::optional<A> load(detail::Reference const & ref, detail::ParserContext<A> const & context) {
|
|
|
|
|
+ if (std::optional<A> in_cache = root(ref.root())) {
|
|
|
|
|
+ return ref.pointer().walk(*in_cache);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ std::optional<A> external = external_.try_load(ref.uri());
|
|
|
|
|
+ if (not external) {
|
|
|
|
|
+ return std::nullopt;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // TODO(samjaffe): Change Versions if needed...
|
|
|
|
|
+ prime(*external, ref.uri(), context.version, context.factory.keywords(context.version));
|
|
|
|
|
+
|
|
|
|
|
+ // May have a sub-id that we map to
|
|
|
|
|
+ if (std::optional<A> in_cache = root(ref.root())) {
|
|
|
|
|
+ return ref.pointer().walk(*in_cache);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Will get called if the external schema does not declare a root document id?
|
|
|
|
|
+ return ref.pointer().walk(*external);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
detail::Reference canonicalize(detail::Reference const & ref,
|
|
detail::Reference canonicalize(detail::Reference const & ref,
|
|
|
detail::Reference const & parent) const {
|
|
detail::Reference const & parent) const {
|
|
|
// Relative URI, not in the HEREDOC (or we set an $id)
|
|
// Relative URI, not in the HEREDOC (or we set an $id)
|