hyperion.ng
QJsonSchemaChecker.h
1 #pragma once
2 
3 #include <QJsonDocument>
4 #include <QJsonObject>
5 #include <QJsonValue>
6 #include <QJsonArray>
7 #include <QStringList>
8 #include <QPair>
9 
27 
29 {
30 public:
32  virtual ~QJsonSchemaChecker();
33 
38  bool setSchema(const QJsonObject & schema);
39 
47  QPair<bool, bool> validate(const QJsonObject & value, bool ignoreRequired = false);
48 
55  QJsonObject getAutoCorrectedConfig(const QJsonObject & value, bool ignoreRequired = false);
56 
60  const QStringList & getMessages() const;
61 
62 private:
70  void validate(const QJsonValue &value, const QJsonObject & schema);
71 
77  void setMessage(const QString & message);
78 
79 private:
80  // attribute check functions
88  void checkType(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue);
89 
98  void checkProperties(const QJsonObject & value, const QJsonObject & schema);
99 
108  void checkAdditionalProperties(const QJsonObject & value, const QJsonValue & schema, const QStringList & ignoredProperties);
109 
117  void checkMinimum(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue);
118 
126  void checkMaximum(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue);
127 
135  void checkMinLength(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue);
136 
144  void checkMaxLength(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue);
145 
152  void checkItems(const QJsonValue & value, const QJsonObject & schema);
153 
161  void checkMinItems(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue);
162 
170  void checkMaxItems(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue);
171 
179  void checkUniqueItems(const QJsonValue & value, const QJsonValue & schema);
180 
188  void checkEnum(const QJsonValue & value, const QJsonValue & schema, const QJsonValue & defaultValue);
189 
190 private:
192  QJsonObject _qSchema;
194  bool _ignoreRequired;
196  QString _correct;
198  QJsonObject _autoCorrected;
200  QStringList _currentPath;
202  QStringList _messages;
204  bool _error;
206  bool _schemaError;
207 };
QPair< bool, bool > validate(const QJsonObject &value, bool ignoreRequired=false)
Validate a JSON structure.
Definition: QJsonSchemaChecker.cpp:29
const QStringList & getMessages() const
Definition: QJsonSchemaChecker.cpp:157
QJsonObject getAutoCorrectedConfig(const QJsonObject &value, bool ignoreRequired=false)
Auto correct a JSON structure.
Definition: QJsonSchemaChecker.cpp:45
JsonSchemaChecker is a very basic implementation of json schema.
Definition: QJsonSchemaChecker.h:28
bool setSchema(const QJsonObject &schema)
Definition: QJsonSchemaChecker.cpp:20