33#ifndef PRAVEENJSON_SCHEMA_H
34#define PRAVEENJSON_SCHEMA_H
81 typedef bool (*Resolver)(
const std::string& aDocumentUri,
pjson& aSchema,
void* aContext);
131 const std::string& aSchemaLocation,
const std::string& aKeyword,
132 const std::string& aMessage);
210 bool validate(
const pjson& aInstance, std::vector<Error>& aErrors)
const noexcept;
216 static const
char* documentedSubsetVocabularyUri() noexcept;
218 static const
char* draft2020DialectUri() noexcept;
220 bool isSchemaValid() const noexcept;
222 const std::vector<
Error>& schemaErrors() const noexcept;
224 const std::
string& dialect() const noexcept;
228 const
pjson& schema() const noexcept;
Validates pjson values against a schema (itself a pjson value).
~pJsonSchemaValidator()
Destroys the compiled schema.
bool validate(const pjson &aInstance, std::vector< Error > &aErrors) const noexcept
Validates and appends discovered failures to aErrors. If schema compilation failed,...
bool validate(const pjson &aInstance) const noexcept
Returns whether aInstance conforms to the compiled schema. Never throws.
pJsonSchemaValidator(const pjson &aSchema, const Options &aOptions=Options())
Compiles aSchema (deep-copied with the default allocator) and all resolved resources....
static const char * documentedSubsetDialectUri() noexcept
URI naming pjson's explicitly documented JSON Schema subset dialect.
Owning, mutable JSON value with deep-copy semantics.
Namespace containing the pjson public API.
One schema-compilation or instance-validation failure.
std::string instanceLocation
JSON Pointer into the instance; empty is root.
Code code
Stable machine-readable failure category.
std::string message
Human-readable diagnostic, not a stable API token.
Code
Stable machine-readable failure category. keyword identifies the precise keyword when several keyword...
@ UnsupportedVocabulary
A required vocabulary is unsupported.
@ AllocationFailure
Validation could not allocate required temporary state.
@ StringConstraint
A string assertion failed.
@ ConstMismatch
The instance does not satisfy const.
@ RegexFailure
A pattern was invalid or rejected by safety policy.
@ CombinatorMismatch
A logical applicator did not satisfy its contract.
@ ArrayConstraint
An array assertion failed.
@ UnsupportedKeyword
Strict mode found an unsupported standard keyword.
@ ReferenceFailure
A schema reference could not be resolved.
@ EnumMismatch
The instance does not satisfy enum.
@ ObjectConstraint
An object assertion failed.
@ ResolverFailure
The caller's external resolver could not load a schema.
@ FalseSchema
A false boolean schema rejected the instance.
@ ReferenceCycle
Reference evaluation encountered a cycle.
@ InvalidSchema
A schema or keyword has an invalid shape or value.
@ ResourceLimit
A compilation, validation, or diagnostic limit was hit.
@ TypeMismatch
The instance does not satisfy type.
@ FormatMismatch
A known asserted format failed.
@ UnsupportedDialect
The selected schema dialect is unsupported.
@ NumericConstraint
A numeric assertion failed.
std::string keyword
Triggering keyword; empty for whole-schema failures.
Category
Distinguishes an instance-validation failure from an invalid or unsupported schema contract discovere...
@ InstanceValidation
The instance violates a valid schema.
Error(Code aCode, Category aCategory, const std::string &aInstanceLocation, const std::string &aSchemaLocation, const std::string &aKeyword, const std::string &aMessage)
Constructs a fully located diagnostic.
std::string schemaLocation
Pointer or retrieval URI plus fragment for the schema.
std::vector< Error > causes
Optional bounded combinator branch failures. Constructs an empty diagnostic.
Category category
Compilation or instance-validation phase.
Bounds schema work and controls dialect, format, and resolver policy.
bool collectNestedCauses
Retains bounded anyOf/oneOf branch failures.
static Options trustedRegex()
Disables only regex restrictions; all other defaults remain enabled.
void * resolverContext
Construction-only opaque resolver context.
size_t maxRefResolutions
Resolved-reference budget. Validation work units (default 1,000,000); zero selects that hard ceiling.
static Options strict()
Returns the defaults with strict fail-closed subset mode enabled.
bool allowUnsafeRegex
Permits unrestricted ECMAScript regex (default false). Recursive validation depth (default and absolu...
Resolver resolver
Construction-only external-schema resolver.
std::string defaultDialectUri
Dialect used when $schema is absent.
size_t maxRegexSubjectBytes
0 = unlimited (default: 4096).
bool strictSubset
Rejects unsupported standard keywords when true. Applies $ref siblings using pjson's modern subset se...
static Options draft2020()
Selects the official Draft 2020-12 dialect, modern $ref semantics, annotation-only format,...
bool refSiblings
True when $ref siblings must also be evaluated. Allows an unknown absolute $schema URI to be resolved...
size_t maxValidationDepth
Recursive validation depth budget. Resolved references (default 1024); zero selects the hard ceiling ...
static Options modernSubset()
Selects modern subset semantics: $ref siblings apply and format is annotation-only unless the caller ...
size_t maxValidationWork
Total validation work-unit budget. Reported errors (default 100); zero selects the hard ceiling of 10...
size_t maxRegexPatternBytes
0 = unlimited (default: 256).
std::string retrievalUri
Initial base URI for a root without $id. Dialect used when the root schema has no $schema....
size_t maxResolvedDocuments
External-document budget (default 32).
bool stopAfterFirstError
Stops compilation or validation after the first error.
size_t maxErrors
Collected top-level and nested diagnostic budget.
size_t maxResolvedBytes
Compact resolved-DOM byte budget (default 16 MiB). Selects bounded safe-regex, traversal,...
bool resolveCustomDialects
Enables explicit custom meta-schema resolution. Retrieval URI used as the initial base when the root ...
bool validateFormats
Validates known string formats (default true).