MNX Document Model
Loading...
Searching...
No Matches
Validation.h
1/*
2 * Copyright (C) 2025, Robert Patterson
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22#pragma once
23
24#include <string>
25#include <vector>
26#include <unordered_set>
27
28#include "util/IdMapping.h"
29
30namespace mnx {
31
32class Document;
33
38namespace validation {
39
43{
46 struct Error
47 {
49 Error(const json_pointer& ptr, const json& inst, const std::string& msg)
50 : instance(inst), pointer(ptr), message(msg) {}
51
54 std::string message;
55
58 std::string to_string(int indent = -1) const
59 {
60 return "At " + pointer.to_string() + " of " + instance.dump(indent) + " - " + message;
61 }
62 };
63 std::vector<Error> errors;
64
66 explicit operator bool() const { return errors.empty(); }
67};
68
72{
73 using ValidationResult::ValidationResult;
74
75 std::unordered_map<std::string, json_pointer> lyricLines;
79};
80
85ValidationResult schemaValidate(const Document& document, const std::optional<std::string>& jsonSchema = std::nullopt);
86
91
92} // namespace validation
93} // namespace mnx
Represents an MNX document and provides methods for loading and saving.
Definition Document.h:87
ValidationResult schemaValidate(const Document &document, const std::optional< std::string > &jsonSchema)
Validates a document against a JSON schema.
Definition SchemaValidate.cpp:30
SemanticValidationResult semanticValidate(const Document &document)
Validates the semantics of the input MNX document.
Definition SemanticValidate.cpp:386
object model for MNX format
json::json_pointer json_pointer
JSON pointer class for MNX.
Definition BaseTypes.h:197
nlohmann::ordered_json json
JSON class for MNX.
Definition BaseTypes.h:196
Returns the results of semantic validation.
Definition Validation.h:72
std::unordered_map< std::string, json_pointer > lyricLines
Definition Validation.h:75
All the information about a specific error.
Definition Validation.h:47
json instance
instance containing the error
Definition Validation.h:52
json_pointer pointer
the location of the instance in the top level
Definition Validation.h:53
Error(const json_pointer &ptr, const json &inst, const std::string &msg)
constructor
Definition Validation.h:49
std::string message
a message describing the error
Definition Validation.h:54
std::string to_string(int indent=-1) const
Converts the error to a string. (Matches the schema validator's default message.)
Definition Validation.h:58
Encapsulates a schema validation result.
Definition Validation.h:43
std::vector< Error > errors
errors encountered
Definition Validation.h:63