mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-27 22:49:25 +02:00
Implement if check for json schemas
This commit is contained in:
@@ -119,6 +119,13 @@ static std::string notCheck(JsonValidator & validator, const JsonNode & baseSche
|
|||||||
return "";
|
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)
|
static std::string enumCheck(JsonValidator & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
||||||
{
|
{
|
||||||
for(const auto & enumEntry : schema.Vector())
|
for(const auto & enumEntry : schema.Vector())
|
||||||
@@ -544,6 +551,8 @@ JsonValidator::TValidatorMap createCommonFields()
|
|||||||
ret["type"] = typeCheck;
|
ret["type"] = typeCheck;
|
||||||
ret["not"] = notCheck;
|
ret["not"] = notCheck;
|
||||||
ret["$ref"] = refCheck;
|
ret["$ref"] = refCheck;
|
||||||
|
ret["if"] = ifCheck;
|
||||||
|
ret["then"] = emptyCheck; // implemented as part of "if check"
|
||||||
|
|
||||||
// fields that don't need implementation
|
// fields that don't need implementation
|
||||||
ret["title"] = emptyCheck;
|
ret["title"] = emptyCheck;
|
||||||
|
|||||||
Reference in New Issue
Block a user