mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
JsonUtils & improvements (#476)
* add JsonUtils * update * repair * update * ident * Schema correct msg other adjusts * fix effDel, ExceptionLog, cleanup * fix travis qt5.2 * not so funny * use Qthread interrupt instead abort bool * update services
This commit is contained in:
@@ -25,7 +25,7 @@ public:
|
||||
// create the validator
|
||||
QJsonSchemaChecker schemaChecker;
|
||||
schemaChecker.setSchema(schemaTree);
|
||||
|
||||
|
||||
QStringList messages = schemaChecker.getMessages();
|
||||
|
||||
if (!schemaChecker.validate(configTree).first)
|
||||
@@ -40,7 +40,7 @@ public:
|
||||
json = configTree;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static QJsonObject readConfig(const QString& path)
|
||||
{
|
||||
QFile file(path);
|
||||
@@ -54,7 +54,7 @@ public:
|
||||
//Allow Comments in Config
|
||||
QString config = QString(file.readAll());
|
||||
config.remove(QRegularExpression("([^:]?\\/\\/.*)"));
|
||||
|
||||
|
||||
QJsonDocument doc = QJsonDocument::fromJson(config.toUtf8(), &error);
|
||||
file.close();
|
||||
|
||||
@@ -94,7 +94,7 @@ public:
|
||||
QByteArray schema = schemaData.readAll();
|
||||
QJsonDocument doc = QJsonDocument::fromJson(schema, &error);
|
||||
schemaData.close();
|
||||
|
||||
|
||||
if (error.error != QJsonParseError::NoError)
|
||||
{
|
||||
// report to the user the failure and their locations in the document.
|
||||
|
@@ -22,6 +22,8 @@
|
||||
/// - addtionalProperties
|
||||
/// - minItems
|
||||
/// - maxItems
|
||||
/// - minLength
|
||||
/// - maxLength
|
||||
|
||||
class QJsonSchemaChecker
|
||||
{
|
||||
@@ -39,7 +41,7 @@ public:
|
||||
/// @brief Validate a JSON structure
|
||||
/// @param value The JSON value to check
|
||||
/// @param ignoreRequired Ignore the "required" keyword in hyperion schema. Default is false
|
||||
/// @return The first boolean is true when the arguments is valid according to the schema. The second is true when the schema contains no errors
|
||||
/// @return The first boolean is true when the arguments is valid according to the schema. The second is true when the schema contains no errors
|
||||
/// @return TODO: Check the Schema in SetSchema() function and remove the QPair result
|
||||
///
|
||||
QPair<bool, bool> validate(const QJsonObject & value, bool ignoreRequired = false);
|
||||
@@ -84,7 +86,7 @@ private:
|
||||
/// @param[in] schema The specified type (as json-value)
|
||||
///
|
||||
void checkType(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue);
|
||||
|
||||
|
||||
///
|
||||
/// Checks is required properties of an json-object exist and if all properties are of the
|
||||
/// correct format. If this is not the case _error is set to true and an error-message is added
|
||||
@@ -127,7 +129,7 @@ private:
|
||||
/// Checks if the given value is hugher than the specified value. If this is the
|
||||
/// case _error is set to true and an error-message is added to the message-queue.
|
||||
///
|
||||
/// @param value The given value
|
||||
/// @param value The given value
|
||||
/// @param schema The minimum size specification (as json-value)
|
||||
///
|
||||
void checkMinLength(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue);
|
||||
@@ -136,7 +138,7 @@ private:
|
||||
/// Checks if the given value is smaller than the specified value. If this is the
|
||||
/// case _error is set to true and an error-message is added to the message-queue.
|
||||
///
|
||||
/// @param value The given value
|
||||
/// @param value The given value
|
||||
/// @param schema The maximum size specification (as json-value)
|
||||
///
|
||||
void checkMaxLength(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue);
|
||||
|
Reference in New Issue
Block a user