|
|
@@ -19,6 +19,7 @@ private:
|
|
|
schema::Version version_;
|
|
|
std::unordered_map<std::string_view, MakeConstraint> make_;
|
|
|
std::unordered_set<std::string_view> permitted_;
|
|
|
+ std::unordered_set<std::string> vocabularies_;
|
|
|
|
|
|
// TODO(samjaffe): Migrate this back to constraintsfactory
|
|
|
std::unordered_set<std::string_view> keywords_{"$defs",
|
|
|
@@ -56,8 +57,10 @@ public:
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- void restrict(std::unordered_set<std::string> const & permitted_keywords) & {
|
|
|
+ void restrict(std::unordered_set<std::string> const & permitted_keywords,
|
|
|
+ std::unordered_set<std::string> const & vocabularies) & {
|
|
|
permitted_.clear();
|
|
|
+ vocabularies_ = vocabularies;
|
|
|
for (auto const & [keyword, _] : make_) {
|
|
|
if (permitted_keywords.contains(std::string(keyword))) {
|
|
|
permitted_.insert(keyword);
|
|
|
@@ -67,6 +70,30 @@ public:
|
|
|
|
|
|
schema::Version version() const { return version_; }
|
|
|
|
|
|
+ bool is_format_assertion() const {
|
|
|
+ // In Draft07 and prior - format assertions were considered enabled by
|
|
|
+ // default. This is - of course - problematic because very few
|
|
|
+ // implementations actually had full support for format constraints.
|
|
|
+ if (version_ < schema::Version::Draft2019_09) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ // Some implementations wouldn't even bother with format constraints, and
|
|
|
+ // others would provide implementations that either missed a number of edge
|
|
|
+ // cases or were flat-out wrong on certail matters.
|
|
|
+ // Therefore - starting in Draft 2019-09, the format keyword is an
|
|
|
+ // annotation by default, instead of an assertion.
|
|
|
+ if (version_ == schema::Version::Draft2019_09) {
|
|
|
+ return permitted_.contains("/vocab/format");
|
|
|
+ }
|
|
|
+
|
|
|
+ // Draft 2020-12 makes this even more explicit - having separate vocabulary
|
|
|
+ // documents for "format as assertion" and "format as annotation". Allowing
|
|
|
+ // validators to add format constraints that are only used for annotating
|
|
|
+ // results.
|
|
|
+ return vocabularies_.contains("/vocab/format-assertion");
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* @brief Is the given "key"word actually a keyword? As in, would
|
|
|
* I expect to resolve a constraint out of it.
|