std/data/json/schema/output

Standard Library documentation

JSON Schema validation output objects.

Module

Name
std/data/json/schema/output
Area
Standard Library
Source
modules/std/data/json/schema/output.zzm

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

  • ValidationResult

    Structured result returned by validate.

    • valid()

      Returns the boolean validation status.

    • errors()

      Returns an array of ValidationError objects.

    • to_Dict()

      Returns a Basic-style Dict. Errors are converted with their own to_Dict() method.

  • ValidationError

    Base 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(), and instance_location().

  • MissingValueError

    Base class for failures where a required value is absent. Subclasses are RequiredPropertyError, DependentRequiredPropertyError, MinItemsError, MinPropertiesError, and MinContainsError.

  • UnexpectedValueError

    Base class for failures where a value is present but not allowed. Subclasses are AdditionalPropertiesError, UnevaluatedPropertiesError, AdditionalItemsError, UnevaluatedItemsError, MaxItemsError, MaxPropertiesError, MaxContainsError, and NotMatchedError.

  • WrongValueError

    Base 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, and IfThenElseError.

  • SubschemaError

    Summary error for the message A subschema had errors.. The suberrors() method returns live child errors that are still reachable. Children are added with add_suberror(error) and add_suberrors(errors).

  • ReferenceResolutionError

    Error class for failures while resolving $ref or $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.