1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-09-16 09:26:28 +02:00

Implement if check for json schemas

This commit is contained in:
Ivan Savenko
2025-05-29 17:07:15 +03:00
parent 2cd29c1893
commit 87d5347e50

View File

@@ -119,6 +119,13 @@ static std::string notCheck(JsonValidator & validator, const JsonNode & baseSche
return "";
}
static std::string ifCheck(JsonValidator & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
{
if (validator.check(schema, data).empty())
return validator.check(baseSchema["then"], data);
return "";
}
static std::string enumCheck(JsonValidator & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
{
for(const auto & enumEntry : schema.Vector())
@@ -544,6 +551,8 @@ JsonValidator::TValidatorMap createCommonFields()
ret["type"] = typeCheck;
ret["not"] = notCheck;
ret["$ref"] = refCheck;
ret["if"] = ifCheck;
ret["then"] = emptyCheck; // implemented as part of "if check"
// fields that don't need implementation
ret["title"] = emptyCheck;