|
| | pJsonSchemaValidator (const pjson &aSchema, const Options &aOptions=Options()) |
| | Compiles aSchema (deep-copied with the default allocator) and all resolved resources. Resolver failures, malformed references, and duplicate IDs/anchors are reported through isSchemaValid() and schemaErrors(); allocation failure may still throw std::bad_alloc.
|
| |
| | ~pJsonSchemaValidator () |
| | Destroys the compiled schema.
|
| |
| bool | validate (const pjson &aInstance) const noexcept |
| | Returns whether aInstance conforms to the compiled schema. Never throws.
|
| |
| bool | validate (const pjson &aInstance, std::vector< Error > &aErrors) const noexcept |
| | Validates and appends discovered failures to aErrors. If schema compilation failed, appends schemaErrors() instead. Never throws.
|
| |
| bool | isSchemaValid () const noexcept |
| | Returns whether dialect and required-vocabulary compilation succeeded.
|
| |
| const std::vector< Error > & | schemaErrors () const noexcept |
| | Returns immutable schema-compilation diagnostics (paths address the schema).
|
| |
| const std::string & | dialect () const noexcept |
| | Returns the effective dialect URI selected by $schema or the option default.
|
| |
| const pjson & | schema () const noexcept |
| | Returns the compiled schema value (read-only).
|
| |
| const Options & | options () const noexcept |
| | Returns the options in effect for this validator. Construction-only resolver pointers are cleared in this snapshot.
|
| |
Validates pjson values against a schema (itself a pjson value).
Validates pjson values using the subset or Draft 2020-12 contract.
Construct once from a schema; validate many instances. The schema is deep-copied on construction, so the caller's schema value may change or be destroyed afterward. Validation never throws and never mutates its inputs. Construction resolves and owns external resources; validate() is read-only and may be called concurrently when each caller uses its own error vector.
Dialect contract: default construction implements the named subset dialect. Options::draft2020() selects official Draft 2020-12, bundled meta-schema validation, and per-resource vocabulary activation. Custom meta-schemas require explicit resolver-based loading. Unknown optional vocabularies are annotations and unknown required vocabularies fail compilation.
Supported keywords (subset defaults and required Draft 2020-12 vocabularies): type, enum, const, $ref, $dynamicRef, $id, $anchor, $dynamicAnchor; properties, patternProperties, propertyNames, required, dependentRequired, dependencies, dependentSchemas, additionalProperties, unevaluatedProperties, minProperties, maxProperties; items, prefixItems, contains, minContains, maxContains, minItems, maxItems, uniqueItems, unevaluatedItems; minimum, maximum, exclusiveMinimum, exclusiveMaximum, multipleOf; minLength, maxLength, pattern, format; allOf, anyOf, oneOf, not, if, then, else. A boolean schema (true/false) accepts/rejects everything. By default unknown or unsupported keywords are ignored; strict() rejects unsupported standard keywords. External references require an explicit Resolver; pjson never performs network I/O. Regular expressions use a private Unicode-aware ECMAScript engine, including property escapes.
pJsonSchemaValidator is a standalone helper declared in <pjson_schema.h> and built from focused private schema translation units. It is a pure consumer of pjson's public API and never touches the DOM's internal storage, so the core pjson class carries no schema or regex state. The implementation is isolated in its own translation unit for future optional-library packaging. Construct one validator from a schema (deep-copied on construction) and reuse it to validate many instances; validation never throws and never mutates its inputs. Default options implement pjson's explicitly named subset dialect; Options::draft2020() selects the required Draft 2020-12 vocabularies, bundled meta-schema validation, and per-resource vocabulary activation. A root $schema or Options::defaultDialectUri selects the effective dialect; unsupported dialects and required vocabularies fail compilation. Inspect isSchemaValid(), schemaErrors(), and dialect() before trusting validation results.
- See also
- ByteDance::pJsonSchemaValidator::Options
-
ByteDance::pJsonSchemaValidator::Error
Definition at line 74 of file pjson_schema.h.