nfx-serialization 0.3.0
Cross-platform C++ JSON serialization library with extensible trait capabilities
Loading...
Searching...
No Matches
nfx::serialization::json::SchemaValidator Class Referencefinal

JSON Schema validator for Document instances. More...

#include <nfx/serialization/json/SchemaValidator.h>

Classes

struct  Options
 Configuration options for validation. More...

Public Member Functions

 SchemaValidator ()
 Default constructor - creates empty validator.
 SchemaValidator (const Document &schema)
 Construct validator with schema (default options).
 SchemaValidator (const Document &schema, const Options &options)
 Construct validator with schema.
 SchemaValidator (const SchemaValidator &other)
 Copy constructor.
 SchemaValidator (SchemaValidator &&other) noexcept
 Move constructor.
 ~SchemaValidator ()
 Destructor.
SchemaValidatoroperator= (const SchemaValidator &other)
 Copy assignment operator.
SchemaValidatoroperator= (SchemaValidator &&other) noexcept
 Move assignment operator.
bool load (const Document &schema)
 Load JSON schema from Document.
bool load (std::string_view schemaJson)
 Load JSON schema from string.
bool hasSchema () const
 Check if validator has valid schema loaded.
void clear ()
 Clear loaded schema.
Document schema () const
 Get current schema as Document.
ValidationResult validate (const Document &document) const
 Validate Document against loaded schema.
ValidationResult validateAtPath (const Document &document, std::string_view documentPath="", std::string_view schemaPath="") const
 Validate Document at specific path against schema.
std::string version () const
 Get schema version/draft URI.
SchemaDraft draft () const
 Get detected JSON Schema draft version.
std::string draftString () const
 Get schema draft version as human-readable string.
std::string title () const
 Get schema title.
std::string description () const
 Get schema description.
const Optionsoptions () const noexcept
 Get validation options.

Detailed Description

JSON Schema validator for Document instances.

Provides comprehensive JSON Schema Draft 2020-12 validation capabilities including type checking, constraint validation, object/array validation, and custom validation rules. Supports schema loading from Documents and detailed error reporting with path tracking.

Definition at line 295 of file SchemaValidator.h.

Constructor & Destructor Documentation

◆ SchemaValidator() [1/5]

nfx::serialization::json::SchemaValidator::SchemaValidator ( )

Default constructor - creates empty validator.

Creates validator without schema. Must load schema before validation.

Here is the caller graph for this function:

◆ SchemaValidator() [2/5]

nfx::serialization::json::SchemaValidator::SchemaValidator ( const Document & schema)
explicit

Construct validator with schema (default options).

Parameters
schemaJSON Schema document to use for validation
Here is the call graph for this function:

◆ SchemaValidator() [3/5]

nfx::serialization::json::SchemaValidator::SchemaValidator ( const Document & schema,
const Options & options )

Construct validator with schema.

Parameters
schemaJSON Schema document to use for validation
optionsValidation options
Here is the call graph for this function:

◆ SchemaValidator() [4/5]

nfx::serialization::json::SchemaValidator::SchemaValidator ( const SchemaValidator & other)

Copy constructor.

Parameters
otherThe validator to copy from
Here is the call graph for this function:

◆ SchemaValidator() [5/5]

nfx::serialization::json::SchemaValidator::SchemaValidator ( SchemaValidator && other)
noexcept

Move constructor.

Parameters
otherThe validator to move from
Here is the call graph for this function:

Member Function Documentation

◆ description()

std::string nfx::serialization::json::SchemaValidator::description ( ) const

Get schema description.

Returns
Schema description string, or empty if not specified

◆ draft()

SchemaDraft nfx::serialization::json::SchemaValidator::draft ( ) const

Get detected JSON Schema draft version.

Returns
SchemaDraft enumeration value indicating the draft version

◆ draftString()

std::string nfx::serialization::json::SchemaValidator::draftString ( ) const

Get schema draft version as human-readable string.

Returns
Draft version string (e.g., "2020-12", "07"), or empty if unknown

◆ hasSchema()

bool nfx::serialization::json::SchemaValidator::hasSchema ( ) const

Check if validator has valid schema loaded.

Returns
True if schema is loaded and valid, false otherwise

◆ load() [1/2]

bool nfx::serialization::json::SchemaValidator::load ( const Document & schema)

Load JSON schema from Document.

Parameters
schemaJSON Schema document
Returns
True if schema loaded successfully, false on parse error
Here is the call graph for this function:

◆ load() [2/2]

bool nfx::serialization::json::SchemaValidator::load ( std::string_view schemaJson)

Load JSON schema from string.

Parameters
schemaJsonJSON Schema as string
Returns
True if schema loaded successfully, false on parse error

◆ operator=() [1/2]

SchemaValidator & nfx::serialization::json::SchemaValidator::operator= ( const SchemaValidator & other)

Copy assignment operator.

Parameters
otherThe validator to copy from
Returns
Reference to this validator
Here is the call graph for this function:

◆ operator=() [2/2]

SchemaValidator & nfx::serialization::json::SchemaValidator::operator= ( SchemaValidator && other)
noexcept

Move assignment operator.

Parameters
otherThe validator to move from
Returns
Reference to this validator
Here is the call graph for this function:

◆ options()

const Options & nfx::serialization::json::SchemaValidator::options ( ) const
noexcept

Get validation options.

Returns
Current validation options
Here is the caller graph for this function:

◆ schema()

Document nfx::serialization::json::SchemaValidator::schema ( ) const

Get current schema as Document.

Returns
Current schema Document, or empty Document if no schema loaded
Here is the caller graph for this function:

◆ title()

std::string nfx::serialization::json::SchemaValidator::title ( ) const

Get schema title.

Returns
Schema title string, or empty if not specified

◆ validate()

ValidationResult nfx::serialization::json::SchemaValidator::validate ( const Document & document) const

Validate Document against loaded schema.

Parameters
documentThe JSON document to validate
Returns
ValidationResult with success status and error details
Exceptions
std::runtime_errorif no schema is loaded

◆ validateAtPath()

ValidationResult nfx::serialization::json::SchemaValidator::validateAtPath ( const Document & document,
std::string_view documentPath = "",
std::string_view schemaPath = "" ) const

Validate Document at specific path against schema.

Parameters
documentThe JSON document to validate
documentPathPath within document to validate (empty for root)
schemaPathPath within schema to validate against (empty for root schema)
Returns
ValidationResult with success status and error details

◆ version()

std::string nfx::serialization::json::SchemaValidator::version ( ) const

Get schema version/draft URI.

Returns
Schema $schema URI string, or empty if not specified

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