Validates parsed JSON documents against a JSON Schema (Draft 7). More...
#include <phosphor-fsloader/include/PhosphorFsLoader/SchemaValidator.h>
Classes | |
| struct | Error |
| A single schema violation. More... | |
Public Member Functions | |
| SchemaValidator (const QByteArray &schemaJson) | |
| Compile a JSON Schema from its serialized bytes. | |
| ~SchemaValidator () | |
| SchemaValidator (SchemaValidator &&) noexcept | |
| SchemaValidator & | operator= (SchemaValidator &&) noexcept |
| SchemaValidator (const SchemaValidator &)=delete | |
| SchemaValidator & | operator= (const SchemaValidator &)=delete |
| bool | isValid () const |
| True when the schema compiled successfully and the validator is usable. | |
| std::optional< QList< Error > > | validate (const QJsonValue &document) const |
| Validate a parsed JSON document against the compiled schema. | |
Static Public Member Functions | |
| static SchemaValidator | fromResource (const QString &resourcePath, const QLoggingCategory &category) |
| Build a validator from a Qt resource (or file) path, failing closed. | |
Validates parsed JSON documents against a JSON Schema (Draft 7).
Thin, dependency-free wrapper over the vendored valijson engine. The schema-validation library (valijson + its Qt adapter) is an implementation detail confined to the .cpp; this header exposes only Qt/std types so the engine never leaks into the public ABI or into consumers' include closure.
Construct one validator per document type from the serialized schema bytes (typically a schema embedded as a Qt resource), compile it once, and reuse it across every file of that type — schema compilation is the expensive step and validate() is cheap to call repeatedly.
Failure model is fail-closed. If the schema bytes are themselves malformed, isValid() returns false and every validate() call reports a single error rather than silently passing documents through unvalidated.
|
explicit |
Compile a JSON Schema from its serialized bytes.
| schemaJson | UTF-8 JSON text of a Draft 7 schema. A malformed or non-object schema leaves the validator in an invalid state (isValid() == false) instead of throwing. |
| PhosphorFsLoader::SchemaValidator::~SchemaValidator | ( | ) |
|
noexcept |
|
delete |
|
static |
Build a validator from a Qt resource (or file) path, failing closed.
Opens resourcePath and compiles the schema from its bytes. If the resource cannot be opened — for an RCC-embedded schema this means a build regression — it logs a warning at category and returns a validator whose isValid() is false, so every validate() call rejects rather than silently passing documents through unvalidated. The single place the embed-and-fail-closed contract lives, shared by every loader.
| bool PhosphorFsLoader::SchemaValidator::isValid | ( | ) | const |
True when the schema compiled successfully and the validator is usable.
|
delete |
|
noexcept |
| std::optional< QList< Error > > PhosphorFsLoader::SchemaValidator::validate | ( | const QJsonValue & | document | ) | const |
Validate a parsed JSON document against the compiled schema.
| document | Any parsed JSON value (typically a QJsonObject). |
std::nullopt when the document satisfies the schema; otherwise the non-empty list of violations. A validator whose schema failed to compile always returns a one-element list.