Phosphor
Qt6 / Wayland library suite for window-management tools
Loading...
Searching...
No Matches
SchemaValidator.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 fuddlesworth
2// SPDX-License-Identifier: LGPL-2.1-or-later
3
4#pragma once
5
6#include <PhosphorFsLoader/phosphorfsloader_export.h>
7
8#include <QtCore/QByteArray>
9#include <QtCore/QJsonValue>
10#include <QtCore/QList>
11#include <QtCore/QString>
12
13#include <memory>
14#include <optional>
15
16class QLoggingCategory;
17
18namespace PhosphorFsLoader {
19
37class PHOSPHORFSLOADER_EXPORT SchemaValidator
38{
39public:
41 struct Error
42 {
46 QString path;
47
49 QString message;
50 };
51
59 explicit SchemaValidator(const QByteArray& schemaJson);
61
63 SchemaValidator& operator=(SchemaValidator&&) noexcept;
65 SchemaValidator& operator=(const SchemaValidator&) = delete;
66
77 [[nodiscard]] static SchemaValidator fromResource(const QString& resourcePath, const QLoggingCategory& category);
78
80 [[nodiscard]] bool isValid() const;
81
90 [[nodiscard]] std::optional<QList<Error>> validate(const QJsonValue& document) const;
91
92private:
93 struct Private;
94 std::unique_ptr<Private> d;
95};
96
104PHOSPHORFSLOADER_EXPORT void logSchemaErrors(const QLoggingCategory& category,
105 const QList<SchemaValidator::Error>& errors);
106
107} // namespace PhosphorFsLoader
Validates parsed JSON documents against a JSON Schema (Draft 7).
Definition SchemaValidator.h:38
static SchemaValidator fromResource(const QString &resourcePath, const QLoggingCategory &category)
Build a validator from a Qt resource (or file) path, failing closed.
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.
SchemaValidator(const QByteArray &schemaJson)
Compile a JSON Schema from its serialized bytes.
SchemaValidator(SchemaValidator &&) noexcept
Definition ContainedFileReader.h:15
PHOSPHORFSLOADER_EXPORT void logSchemaErrors(const QLoggingCategory &category, const QList< SchemaValidator::Error > &errors)
Log each schema violation at category, one per line.
A single schema violation.
Definition SchemaValidator.h:42
QString message
Human-readable description of why the node failed.
Definition SchemaValidator.h:49
QString path
JSON Pointer to the node that failed validation (e.g.
Definition SchemaValidator.h:46