mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
JSON Auto correction + hyperion schema split for better readability (#452)
* revoke schema split * add "getAutoCorrectedConfig" function * revoke schema split * revoke schema split * revoke schema split * Prevent compiler error if none grabber is available * revoke schema split * add "getAutoCorrectedConfig" function * revoke schema split * remove "configMigrator" * remove "configMigrator" * Change TestConfigFile to show how the autocorrection works * revoke schema split * revoke schema split * remove "ConfigMigrator" * remove "ConfigMigrator" * remove "ConfigMigratorBase" * remove "ConfigMigratorBase" * Add QJsonUtils.h * added ability "ignore-required" It has been added the ability to correct the configuration without having to pay attention to the keyword "required" in the hyperion schema * Allow Comments in Hyperion Schema * add ability to ignore the "required" keyword in hyperion schema * add ability to ignore the "required" keyword in hyperion schema * add ability to ignore the "required" keyword in hyperion schema * //Allow Comments in Hyperion Schema * Update jsonschema.py to version 0.8.0 to support ... references in json schema * add RefResolver from jsonschema.py to resolve references in hyperion schema * remove dupe code * split the hyperion schema in separatly files For better readability * add function "resolveReferences" to resolve references in hyperion schema. * remove CURRENT_CONFIG_VERSION * remove CURRENT_CONFIG_VERSION * split the hyperion schema in separatly files For better readability * Create schema-backgroundEffect.json * Add the rest of the Hyperion schema via upload * Remove Comments in config file * Add return variable to function writeJson(). fix function resolveReferences(). edit function load() to handle QPair result from schemaChecker. * edit function validate() to return QPair variable * fit function loadEffectDefinition() * fit function checkJson() * Expand error check by dividing "_error" variable in "_error" and "_schemaError". Replace variable "bool" in validate() in QPair * Extend function "cmd_cfg_set" to handle auto correction * Extend function "loadConfig" to handle auto correction * fix function loadConfig()
This commit is contained in:
committed by
brindosch
parent
622a171808
commit
5bd020a570
@@ -25,17 +25,14 @@ public:
|
||||
// create the validator
|
||||
QJsonSchemaChecker schemaChecker;
|
||||
schemaChecker.setSchema(schemaTree);
|
||||
|
||||
bool valid = schemaChecker.validate(configTree);
|
||||
|
||||
QStringList messages = schemaChecker.getMessages();
|
||||
for (int i = 0; i < messages.size(); ++i)
|
||||
{
|
||||
std::cout << messages[i].toStdString() << std::endl;
|
||||
}
|
||||
|
||||
if (!valid)
|
||||
|
||||
if (!schemaChecker.validate(configTree).first)
|
||||
{
|
||||
for (int i = 0; i < messages.size(); ++i)
|
||||
std::cout << messages[i].toStdString() << std::endl;
|
||||
|
||||
std::cerr << "Validation failed for configuration file: " << config.toStdString() << std::endl;
|
||||
return -3;
|
||||
}
|
||||
@@ -54,6 +51,7 @@ public:
|
||||
throw std::runtime_error(QString("Configuration file not found: '" + path + "' (" + file.errorString() + ")").toStdString());
|
||||
}
|
||||
|
||||
//Allow Comments in Config
|
||||
QString config = QString(file.readAll());
|
||||
config.remove(QRegularExpression("([^:]?\\/\\/.*)"));
|
||||
|
||||
@@ -112,23 +110,62 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
throw std::runtime_error(QString("ERROR: Json schema wrong: " + error.errorString() + " at Line: " + QString::number(errorLine)
|
||||
+ ", Column: " + QString::number(errorColumn)).toStdString()
|
||||
);
|
||||
throw std::runtime_error(QString("ERROR: Json schema wrong: " + error.errorString() +
|
||||
" at Line: " + QString::number(errorLine) +
|
||||
", Column: " + QString::number(errorColumn)).toStdString());
|
||||
}
|
||||
|
||||
return doc.object();
|
||||
return resolveReferences(doc.object());
|
||||
}
|
||||
|
||||
static void writeJson(const QString& filename, QJsonObject& jsonTree)
|
||||
static QJsonObject resolveReferences(const QJsonObject& schema)
|
||||
{
|
||||
QJsonObject result;
|
||||
|
||||
for (QJsonObject::const_iterator i = schema.begin(); i != schema.end(); ++i)
|
||||
{
|
||||
QString attribute = i.key();
|
||||
const QJsonValue & attributeValue = *i;
|
||||
|
||||
if (attribute == "$ref" && attributeValue.isString())
|
||||
{
|
||||
try
|
||||
{
|
||||
result = readSchema(":/" + attributeValue.toString());
|
||||
}
|
||||
catch (std::runtime_error& error)
|
||||
{
|
||||
throw std::runtime_error(error.what());
|
||||
}
|
||||
}
|
||||
else if (attributeValue.isObject())
|
||||
result.insert(attribute, resolveReferences(attributeValue.toObject()));
|
||||
else
|
||||
result.insert(attribute, attributeValue);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static bool writeJson(const QString& filename, QJsonObject& jsonTree)
|
||||
{
|
||||
QJsonDocument doc;
|
||||
|
||||
doc.setObject(jsonTree);
|
||||
QByteArray configData = doc.toJson(QJsonDocument::Indented);
|
||||
|
||||
|
||||
QFile configFile(filename);
|
||||
configFile.open(QIODevice::WriteOnly | QIODevice::Truncate);
|
||||
if (!configFile.open(QFile::WriteOnly | QFile::Truncate))
|
||||
return false;
|
||||
|
||||
configFile.write(configData);
|
||||
|
||||
QFile::FileError error = configFile.error();
|
||||
if (error != QFile::NoError)
|
||||
return false;
|
||||
|
||||
configFile.close();
|
||||
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
Reference in New Issue
Block a user