mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-25 22:42:04 +02:00
Added support for 'const' field to json validator
This commit is contained in:
@@ -105,6 +105,14 @@ static std::string enumCheck(JsonValidator & validator, const JsonNode & baseSch
|
||||
return validator.makeErrorMessage("Key must have one of predefined values");
|
||||
}
|
||||
|
||||
static std::string constCheck(JsonValidator & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
||||
{
|
||||
if (data == schema)
|
||||
return "";
|
||||
|
||||
return validator.makeErrorMessage("Key must have have constant value");
|
||||
}
|
||||
|
||||
static std::string typeCheck(JsonValidator & validator, const JsonNode & baseSchema, const JsonNode & schema, const JsonNode & data)
|
||||
{
|
||||
static const std::unordered_map<std::string, JsonNode::JsonType> stringToType =
|
||||
@@ -496,6 +504,7 @@ JsonValidator::TValidatorMap createCommonFields()
|
||||
ret["anyOf"] = anyOfCheck;
|
||||
ret["oneOf"] = oneOfCheck;
|
||||
ret["enum"] = enumCheck;
|
||||
ret["const"] = constCheck;
|
||||
ret["type"] = typeCheck;
|
||||
ret["not"] = notCheck;
|
||||
ret["$ref"] = refCheck;
|
||||
|
||||
Reference in New Issue
Block a user