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:
brindosch
2017-10-12 11:55:03 +02:00
committed by GitHub
parent 47641012ee
commit 838008568a
42 changed files with 940 additions and 701 deletions

View File

@@ -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.

View File

@@ -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);