Prechádzať zdrojové kódy

test/fix: properly record errors when "deep" within a not constraint

Sam Jaffe 2 týždňov pred
rodič
commit
6302cd0e01

+ 1 - 1
include/jvalidate/validation_visitor.h

@@ -828,7 +828,7 @@ private:
     }
     // Update the annotation/error content only if a failure is being reported,
     // or if we are in an "if" schema.
-    if ((rval == Status::Reject or tracking_ == StoreResults::ForAnything) and result_) {
+    if (should_annotate(rval)) {
       result_->merge(std::move(result));
     }
     return rval;

+ 18 - 2
tests/annotation_test.cxx

@@ -1,5 +1,3 @@
-#include <string_view>
-
 #include <gmock/gmock.h>
 #include <gtest/gtest.h>
 
@@ -75,6 +73,24 @@ TEST(Annotation, NotSchemaFlipsAnnotationRule) {
   EXPECT_THAT(result, ErrorAt(""_jptr, "/not"_jptr, "minimum", "6 >= 5"));
 }
 
+TEST(Annotation, NotSchemaPropogatesDeeply) {
+  auto const schema = R"({
+    "not": {
+      "properties": {
+        "A": {
+          "enum": [ 1, 3, 4 ]
+        }
+      }
+    }
+  })"_json;
+
+  auto const instance = R"({"A": 3})"_json;
+
+  jvalidate::ValidationResult result = validate(schema, instance);
+
+  EXPECT_THAT(result, ErrorAt("/A"_jptr, "/not/properties/A"_jptr, "enum", "1"));
+}
+
 TEST(Annotation, PathFollowsSchemaNotConstraintModel) {
   auto const schema = R"({
     "$comment": "disallow is implemented in the form of NotConstraint[TypeConstraint]",