42namespace nfx::serialization::json
113 inline const std::string&
path() const noexcept {
return m_error.path; }
119 inline const std::string&
message() const noexcept {
return m_error.message; }
125 inline const std::string&
constraint() const noexcept {
return m_error.constraint; }
131 inline const std::string&
expectedValue() const noexcept {
return m_error.expectedValue; }
137 inline const std::string&
actualValue() const noexcept {
return m_error.actualValue; }
193 inline bool isValid() const noexcept {
return m_errors.empty(); }
199 inline bool hasErrors() const noexcept {
return !m_errors.empty(); }
205 inline size_t errorCount() const noexcept {
return m_errors.size(); }
215 inline const std::vector<ValidationError>&
errors() const noexcept {
return m_errors; }
256 std::string_view message,
257 std::string_view constraint,
258 std::string_view expectedValue = {},
259 std::string_view actualValue = {} );
262 std::vector<ValidationError> m_errors;
389 bool load( std::string_view schemaJson );
428 std::string_view documentPath =
"",
429 std::string_view schemaPath =
"" )
const;
Generic document abstraction for JSON serialization.
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.
Generic JSON document abstraction for serialization.
Represents a single JSON schema validation error.
const std::string & expectedValue() const noexcept
Get expected value or constraint.
const std::string & path() const noexcept
Get the JSON path where validation failed.
const std::string & message() const noexcept
Get human-readable error message.
std::string toString() const
Get formatted error string.
const std::string & actualValue() const noexcept
Get actual value found in document.
ValidationError(std::string path, std::string message, std::string constraint, std::string expectedValue={}, std::string actualValue={})
Construct validation error.
~ValidationError()=default
Destructor.
const std::string & constraint() const noexcept
Get the constraint type that failed.
ValidationError(const ErrorEntry &entry)
Construct validation error from ErrorEntry struct.
Simple error entry structure for convenient ValidationError construction.
std::string expectedValue
Expected value or constraint.
std::string path
JSON path where error occurred.
std::string message
Human-readable error message.
std::string constraint
Schema constraint that failed.
std::string actualValue
Actual value found in document.
Result of JSON schema validation operation.
~ValidationResult()=default
Destructor.
const std::vector< ValidationError > & errors() const noexcept
Get all validation errors.
bool hasErrors() const noexcept
Check if validation failed.
ValidationResult()=default
Construct successful validation result.
void addError(std::string_view path, std::string_view message, std::string_view constraint, std::string_view expectedValue={}, std::string_view actualValue={})
Add validation error with details.
void addError(const ValidationError &error)
Add validation error to result.
size_t errorCount() const noexcept
Get number of validation errors.
std::string errorSummary() const
Get formatted error summary.
void addError(const ValidationError::ErrorEntry &entry)
Add validation error from ErrorEntry.
ValidationResult(std::vector< ValidationError > errors)
Construct validation result with errors.
const ValidationError & error(size_t index) const
Get validation error by index.
bool isValid() const noexcept
Check if validation was successful.
SchemaDraft draft() const
Get detected JSON Schema draft version.
~SchemaValidator()
Destructor.
SchemaValidator(const SchemaValidator &other)
Copy constructor.
bool load(const Document &schema)
Load JSON schema from Document.
std::string description() const
Get schema description.
ValidationResult validate(const Document &document) const
Validate Document against loaded schema.
void clear()
Clear loaded schema.
std::string draftString() const
Get schema draft version as human-readable string.
std::string version() const
Get schema version/draft URI.
bool hasSchema() const
Check if validator has valid schema loaded.
SchemaValidator(SchemaValidator &&other) noexcept
Move constructor.
Document schema() const
Get current schema as Document.
SchemaValidator(const Document &schema)
Construct validator with schema (default options).
SchemaValidator(const Document &schema, const Options &options)
Construct validator with schema.
const Options & options() const noexcept
Get validation options.
SchemaValidator & operator=(SchemaValidator &&other) noexcept
Move assignment operator.
std::string title() const
Get schema title.
ValidationResult validateAtPath(const Document &document, std::string_view documentPath="", std::string_view schemaPath="") const
Validate Document at specific path against schema.
bool load(std::string_view schemaJson)
Load JSON schema from string.
SchemaValidator()
Default constructor - creates empty validator.
SchemaValidator & operator=(const SchemaValidator &other)
Copy assignment operator.
Configuration options for validation.
size_t maxDepth
Maximum recursion depth (0 = unlimited).
bool strictMode
If true, unknown properties cause validation failure.