40#include <unordered_map>
115 inline const std::string&
path() const noexcept;
121 inline const std::
string&
message() const noexcept;
258 std::string_view
path,
265 std::vector<ValidationError> m_errors;
393 bool load( std::string_view schemaJson );
434 const Document& document, std::string_view documentPath =
"", std::string_view schemaPath =
"" )
const;
492 std::string_view path,
494 size_t currentDepth = 0 ) const;
499 void validateRequired(
502 void validateProperties(
505 std::string_view path,
507 size_t currentDepth = 0 ) const;
509 void validateNumericConstraints(
512 void validateStringConstraints(
521 void validateAdditionalProperties(
527 std::string_view path,
529 size_t currentDepth = 0 ) const;
534 std::string_view path,
536 size_t currentDepth = 0 ) const;
541 std::string_view path,
543 size_t currentDepth = 0 ) const;
548 std::string_view path,
550 size_t currentDepth = 0 ) const;
555 std::string_view path,
557 size_t currentDepth = 0 ) const;
562 std::string_view path,
564 size_t currentDepth = 0 ) const;
566 void validateIfThenElse(
569 std::string_view path,
571 size_t currentDepth = 0 ) const;
577 bool referenceExists( std::string_view reference ) const noexcept;
578 Document resolveReference( std::string_view reference ) const;
579 std::
string actualType( const
Document& document, std::string_view path ) const noexcept;
580 Document extractSubDocument( const
Document& sourceDocument, std::string_view path ) const;
581 void buildAnchorIndex();
582 void scanForAnchors( const
Document&
schema, const std::
string& currentPath );
584 std::
string draftToString() const noexcept;
590 static constexpr
size_t DEFAULT_MAX_DEPTH = 64;
593 bool m_schemaLoaded = false;
594 bool m_strictMode = false;
595 size_t m_maxDepth = DEFAULT_MAX_DEPTH;
597 mutable std::unordered_map<std::
string,
Document> m_refCache;
598 std::unordered_map<std::
string, std::
string> m_anchorIndex;
602#include "detail/SchemaValidator.inl"
SchemaDraft
Enumeration of supported JSON Schema draft versions.
@ Draft04
JSON Schema Draft 4.
@ Draft201909
JSON Schema Draft 2019-09.
@ Draft07
JSON Schema Draft 7.
@ Draft202012
JSON Schema Draft 2020-12 (current).
@ Unknown
Schema draft version is not recognized or not specified.
@ Draft06
JSON Schema Draft 6.
JSON Document type with low-level and high-level APIs.
Low-level JSON value storage type.
Represents a single JSON schema validation error.
ValidationError(std::string path, std::string message, std::string constraint, std::string expectedValue={}, std::string actualValue={})
Construct validation error.
const std::string & path() const noexcept
Get the JSON path where validation failed.
~ValidationError()=default
Destructor.
const std::string & expectedValue() const noexcept
Get expected value or constraint.
std::string toString() const
Get formatted error string.
ValidationError(const ErrorEntry &entry)
Construct validation error from ErrorEntry struct.
const std::string & constraint() const noexcept
Get the constraint type that failed.
const std::string & message() const noexcept
Get human-readable error message.
const std::string & actualValue() const noexcept
Get actual value found in document.
Simple error entry structure for convenient ValidationError construction.
std::string actualValue
Actual value found in document.
std::string constraint
Schema constraint that failed.
std::string expectedValue
Expected value or constraint.
std::string path
JSON path where error occurred.
std::string message
Human-readable error message.
Result of JSON schema validation operation.
const ValidationError & error(size_t index) const
Get validation error by index.
bool hasErrors() const noexcept
Check if validation failed.
~ValidationResult()=default
Destructor.
ValidationResult()=default
Construct successful validation result.
ValidationResult(std::vector< ValidationError > errors)
Construct validation result with errors.
std::string errorSummary() const
Get formatted error summary.
bool isValid() const noexcept
Check if validation was successful.
size_t errorCount() const noexcept
Get number of validation errors.
const std::vector< ValidationError > & errors() const noexcept
Get all validation errors.
void addError(const ValidationError::ErrorEntry &entry)
Add validation error from ErrorEntry.
std::string draftString() const
Get schema draft version as human-readable string.
std::string version() const
Get schema version/draft URI.
SchemaValidator(SchemaValidator &&other) noexcept
Move constructor.
ValidationResult validate(const Document &document) const
Validate Document against loaded schema.
SchemaValidator(const Document &schema)
Construct validator with schema (default options).
SchemaValidator & operator=(SchemaValidator &&other) noexcept
Move assignment operator.
const Options & options() const noexcept
Get validation options.
SchemaValidator()
Default constructor - creates empty validator.
bool hasSchema() const
Check if validator has valid schema loaded.
SchemaValidator(const Document &schema, const Options &options)
Construct validator with schema.
SchemaValidator & operator=(const SchemaValidator &other)
Copy assignment operator.
SchemaDraft draft() const
Get detected JSON Schema draft version.
void clear()
Clear loaded schema.
bool load(const Document &schema)
Load JSON schema from Document.
bool load(std::string_view schemaJson)
Load JSON schema from string.
ValidationResult validateAtPath(const Document &document, std::string_view documentPath="", std::string_view schemaPath="") const
Validate Document at specific path against schema.
SchemaValidator(const SchemaValidator &other)
Copy constructor.
std::string description() const
Get schema description.
Document schema() const
Get current schema as Document.
~SchemaValidator()
Destructor.
std::string title() const
Get schema title.
Configuration options for validation.
size_t maxDepth
Maximum recursion depth (0 = unlimited).
bool strictMode
If true, unknown properties cause validation failure.