|
@@ -28,7 +28,7 @@ protected:
|
|
|
auto visit(jvalidate::detail::Pointer ptr, auto const & cons, JSON & json,
|
|
auto visit(jvalidate::detail::Pointer ptr, auto const & cons, JSON & json,
|
|
|
jvalidate::ValidationResult * result = nullptr, bool annotate_everything = false) {
|
|
jvalidate::ValidationResult * result = nullptr, bool annotate_everything = false) {
|
|
|
JsonCppAdapter const adapter(json);
|
|
JsonCppAdapter const adapter(json);
|
|
|
- ValidationVisitor visitor(node_, adapter, cfg_, regex_, extension_, result);
|
|
|
|
|
|
|
+ ValidationVisitor visitor(node_, adapter, cfg_, regex_, format_, extension_, result);
|
|
|
if (annotate_everything) {
|
|
if (annotate_everything) {
|
|
|
visitor.tracking_ = StoreResults::ForAnything;
|
|
visitor.tracking_ = StoreResults::ForAnything;
|
|
|
}
|
|
}
|
|
@@ -43,10 +43,14 @@ protected:
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void config(jvalidate::ValidationConfig cfg) { cfg_ = cfg; }
|
|
void config(jvalidate::ValidationConfig cfg) { cfg_ = cfg; }
|
|
|
|
|
+ void format(FormatValidator::UserDefinedFormats && fmts) {
|
|
|
|
|
+ format_ = {std::move(fmts), jvalidate::StdRegexEngine::is_regex};
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
private:
|
|
private:
|
|
|
jvalidate::schema::Node node_;
|
|
jvalidate::schema::Node node_;
|
|
|
jvalidate::StdRegexEngine regex_;
|
|
jvalidate::StdRegexEngine regex_;
|
|
|
|
|
+ jvalidate::FormatValidator format_{jvalidate::StdRegexEngine::is_regex};
|
|
|
jvalidate::ValidationConfig cfg_;
|
|
jvalidate::ValidationConfig cfg_;
|
|
|
jvalidate::detail::StubExtensionVisitor extension_;
|
|
jvalidate::detail::StubExtensionVisitor extension_;
|
|
|
};
|
|
};
|
|
@@ -117,13 +121,22 @@ TEST_F(ValidationVisitorTest, EnumConstraintAnnotatesMatchingIndex) {
|
|
|
EXPECT_THAT(result, ErrorAt("enum", "1"));
|
|
EXPECT_THAT(result, ErrorAt("enum", "1"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+TEST_F(ValidationVisitorTest, UnknownFormatIsAccept) {
|
|
|
|
|
+ constraint::FormatConstraint cons{"bogus", Draft2020_12, true};
|
|
|
|
|
+ config({.validate_format = true});
|
|
|
|
|
+
|
|
|
|
|
+ ValidationResult result;
|
|
|
|
|
+ EXPECT_THAT(visit("/format"_jptr, cons, "\"Hello\""_json, &result), Eq(Status::Accept));
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
TEST_F(ValidationVisitorTest, UnimplementedFormatIsError) {
|
|
TEST_F(ValidationVisitorTest, UnimplementedFormatIsError) {
|
|
|
- constraint::FormatConstraint cons{"bogus", true};
|
|
|
|
|
|
|
+ constraint::FormatConstraint cons{"bogus", Draft2020_12, true};
|
|
|
config({.validate_format = true});
|
|
config({.validate_format = true});
|
|
|
|
|
+ format({{"bogus", nullptr}});
|
|
|
|
|
|
|
|
ValidationResult result;
|
|
ValidationResult result;
|
|
|
EXPECT_THAT(visit("/format"_jptr, cons, "\"Hello\""_json, &result), Eq(Status::Reject));
|
|
EXPECT_THAT(visit("/format"_jptr, cons, "\"Hello\""_json, &result), Eq(Status::Reject));
|
|
|
- EXPECT_THAT(result, ErrorAt("format", "bogus is unimplemented"));
|
|
|
|
|
|
|
+ EXPECT_THAT(result, ErrorAt("format", "unimplemented format 'bogus'"));
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|