mirror of
https://github.com/vcmi/vcmi.git
synced 2024-11-24 08:32:34 +02:00
Fixed silent errors on invalid Json references in schemas
This commit is contained in:
parent
9c4475385b
commit
27b75dbbea
@ -17,7 +17,7 @@
|
||||
"additionalItems" :
|
||||
{
|
||||
"description" : "Following items that contain expression elements",
|
||||
"$ref" : "#/definitions/buidingRequirement"
|
||||
"$ref" : "#/definitions/buildingRequirement"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
@ -728,7 +728,11 @@ namespace
|
||||
//node must be validated using schema pointed by this reference and not by data here
|
||||
//Local reference. Turn it into more easy to handle remote ref
|
||||
if (boost::algorithm::starts_with(URI, "#"))
|
||||
URI = validator.usedSchemas.back() + URI;
|
||||
{
|
||||
const std::string name = validator.usedSchemas.back();
|
||||
const std::string nameClean = name.substr(0, name.find('#'));
|
||||
URI = nameClean + URI;
|
||||
}
|
||||
return check(URI, data, validator);
|
||||
}
|
||||
|
||||
@ -739,9 +743,16 @@ namespace
|
||||
auto checker = formats.find(schema.String());
|
||||
if (checker != formats.end())
|
||||
{
|
||||
std::string result = checker->second(data);
|
||||
if (!result.empty())
|
||||
errors += validator.makeErrorMessage(result);
|
||||
if (data.isString())
|
||||
{
|
||||
std::string result = checker->second(data);
|
||||
if (!result.empty())
|
||||
errors += validator.makeErrorMessage(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
errors += validator.makeErrorMessage("Format value must be string: " + schema.String());
|
||||
}
|
||||
}
|
||||
else
|
||||
errors += validator.makeErrorMessage("Unsupported format type: " + schema.String());
|
||||
|
@ -1279,9 +1279,19 @@ const JsonNode & JsonUtils::getSchema(const std::string & URI)
|
||||
|
||||
// check if json pointer if present (section after hash in string)
|
||||
if(posHash == std::string::npos || posHash == URI.size() - 1)
|
||||
return getSchemaByName(filename);
|
||||
{
|
||||
auto const & result = getSchemaByName(filename);
|
||||
if (result.isNull())
|
||||
logMod->error("Error: missing schema %s", URI);
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return getSchemaByName(filename).resolvePointer(URI.substr(posHash + 1));
|
||||
{
|
||||
auto const & result = getSchemaByName(filename).resolvePointer(URI.substr(posHash + 1));
|
||||
if (result.isNull())
|
||||
logMod->error("Error: missing schema %s", URI);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
void JsonUtils::merge(JsonNode & dest, JsonNode & source, bool ignoreOverride, bool copyMeta)
|
||||
|
Loading…
Reference in New Issue
Block a user