NAME
std/data/json/schema/output - JSON Schema validation output objects.
SYNOPSIS
from std/data/json/schema import
RequiredPropertyError,
TypeMismatchError,
validate;
let result := validate( schema, instance );
if ( not result.valid() ) {
for ( let error in result.errors() ) {
say( error.keywordLocation() _ " " _ error.error() );
if ( error instanceof TypeMismatchError ) {
say( "type problem" );
}
}
}
IMPLEMENTATION SUPPORT
This module is supported by all implementations of ZuzuScript.
DESCRIPTION
This module defines the object output model for JSON Schema validation. It is modelled on the Basic output shape from JSON Schema Core, but each error is a real Zuzu object instead of a plain Dict. The class hierarchy lets callers use instanceof to distinguish broad categories and precise keyword failures.
The hierarchy starts with ValidationError. Most keyword failures are grouped under MissingValueError, UnexpectedValueError, or WrongValueError. Applicator keywords can also produce SubschemaError, whose children are stored as weak links to avoid retaining a whole validation tree only through parent summary errors.
EXPORTS
Classes
ValidationResultStructured result returned by
validate.valid()Returns the boolean validation status.
errors()Returns an array of
ValidationErrorobjects.to_Dict()Returns a Basic-style
Dict. Errors are converted with their ownto_Dict()method.
ValidationErrorBase class for all validation errors.
Methods:
keywordLocation()JSON Pointer location of the failing keyword inside the schema.
absoluteKeywordLocation()Absolute keyword URI when known, otherwise
null.instanceLocation()JSON Pointer location of the failing instance value.
error()Human-readable error message.
keyword()The keyword that produced the error, when known.
details()Keyword-specific structured detail, when present.
to_Dict()Converts the error to a Basic-style
Dict.
Snake-case aliases are provided for the location methods:
keyword_location(),absolute_keyword_location(), andinstance_location().MissingValueErrorBase class for failures where a required value is absent. Subclasses are
RequiredPropertyError,DependentRequiredPropertyError,MinItemsError,MinPropertiesError, andMinContainsError.UnexpectedValueErrorBase class for failures where a value is present but not allowed. Subclasses are
AdditionalPropertiesError,UnevaluatedPropertiesError,AdditionalItemsError,UnevaluatedItemsError,MaxItemsError,MaxPropertiesError,MaxContainsError, andNotMatchedError.WrongValueErrorBase class for failures where a value is present but does not meet a constraint. Subclasses are
FalseSchemaError,TypeMismatchError,EnumMismatchError,ConstMismatchError,MultipleOfError,MinimumError,MaximumError,ExclusiveMinimumError,ExclusiveMaximumError,MinLengthError,MaxLengthError,PatternError,FormatError,UnknownFormatError,UniqueItemsError,PropertyNamesError,ContentEncodingError,ContentMediaTypeError,AllOfError,AnyOfError,OneOfError, andIfThenElseError.SubschemaErrorSummary error for the message
A subschema had errors.. Thesuberrors()method returns live child errors that are still reachable. Children are added withadd_suberror(error)andadd_suberrors(errors).ReferenceResolutionErrorError class for failures while resolving
$refor$dynamicRef.
COPYRIGHT AND LICENCE
std/data/json/schema/output is copyright Toby Inkster.
It is free software; you may redistribute it and/or modify it under the terms of either the Artistic License 1.0 or the GNU General Public License version 2.