Browse Source

fix default value was ignored during json validation if a value could have multiple possible types

Kolja Strohm 7 months ago
parent
commit
2ef8a8675d
1 changed files with 18 additions and 0 deletions
  1. 18 0
      JSON.cpp

+ 18 - 0
JSON.cpp

@@ -1073,6 +1073,24 @@ void JSONMissingOneOf::printInvalidInfo(int indent) const
 JSONValue* JSONMissingOneOf::getValidPart(
     RCArray<JSONValidationResult>* removedPartsValidationResults)
 {
+    for (XML::Element* e : expected)
+    {
+        if (e->hasAttribute("default"))
+        {
+            JSONValue *default = Parser::getValue(e->getAttributeValue("default"));
+            if (default)
+            {
+                JSONValue *valid = JSONValidator(
+                    dynamic_cast<XML::Element*>(e->getThis()))
+                    .getValidParts(default, removedPartsValidationResults);
+                default->release();
+                if (valid)
+                {
+					return valid;
+				}
+            }
+        }
+    }
     if (removedPartsValidationResults)
     {
         removedPartsValidationResults->add(