nfx-json 1.5.2
Modern C++20 JSON library with schema validation and generation
Loading...
Searching...
No Matches
nfx::json::ValidationError Class Referencefinal

Represents a single JSON schema validation error. More...

#include <nfx/json/SchemaValidator.h>

Classes

struct  ErrorEntry
 Simple error entry structure for convenient ValidationError construction. More...

Public Member Functions

 ValidationError (const ErrorEntry &entry)
 Construct validation error from ErrorEntry struct.
 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 & path () const noexcept
 Get the JSON path where validation failed.
const std::string & message () const noexcept
 Get human-readable error message.
const std::string & constraint () const noexcept
 Get the constraint type that failed.
const std::string & expectedValue () const noexcept
 Get expected value or constraint.
const std::string & actualValue () const noexcept
 Get actual value found in document.
std::string toString () const
 Get formatted error string.

Detailed Description

Represents a single JSON schema validation error.

Contains detailed information about validation failures including the failed constraint, document path, expected vs actual values, and human-readable error messages.

Definition at line 55 of file SchemaValidator.h.

Constructor & Destructor Documentation

◆ ValidationError() [1/2]

nfx::json::ValidationError::ValidationError ( const ErrorEntry & entry)
explicit

Construct validation error from ErrorEntry struct.

Parameters
entryError entry with all validation details

◆ ValidationError() [2/2]

nfx::json::ValidationError::ValidationError ( std::string path,
std::string message,
std::string constraint,
std::string expectedValue = {},
std::string actualValue = {} )

Construct validation error.

Parameters
pathJSON path where validation failed
messageHuman-readable error description
constraintThe schema constraint that failed (e.g., "type", "minLength")
expectedValueExpected value or constraint (optional)
actualValueActual value found in document (optional)

Member Function Documentation

◆ actualValue()

const std::string & nfx::json::ValidationError::actualValue ( ) const
inlinenoexcept

Get actual value found in document.

Returns
Actual value string, or empty if not applicable

◆ constraint()

const std::string & nfx::json::ValidationError::constraint ( ) const
inlinenoexcept

Get the constraint type that failed.

Returns
Constraint name (e.g., "type", "minLength", "required")

◆ expectedValue()

const std::string & nfx::json::ValidationError::expectedValue ( ) const
inlinenoexcept

Get expected value or constraint.

Returns
Expected value string, or empty if not applicable

◆ message()

const std::string & nfx::json::ValidationError::message ( ) const
inlinenoexcept

Get human-readable error message.

Returns
Error description

◆ path()

const std::string & nfx::json::ValidationError::path ( ) const
inlinenoexcept

Get the JSON path where validation failed.

Returns
Path string (e.g., "/users/0/email")

◆ toString()

std::string nfx::json::ValidationError::toString ( ) const

Get formatted error string.

Returns
Complete formatted error message with path and details

The documentation for this class was generated from the following file: