logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

JSON::Schema::Modern::Error - Contains a single error from a JSON Schema evaluation

Attributes

keyword
       The keyword that produced the error; might be "undef".

   instance_location
       The path in the instance where the error occurred; encoded as per the JSON Pointer specification (RFC
       6901 <https://datatracker.ietf.org/doc/html/rfc6901>).

   keyword_location
       The schema path taken during evaluation to arrive at the error; encoded as per the JSON Pointer
       specification (RFC 6901 <https://datatracker.ietf.org/doc/html/rfc6901>).

   absolute_keyword_location
       The canonical URI or URI reference of the location in the schema where the error occurred; not defined,
       if there is no base URI for the schema and no $ref was followed. Note that this is not a fragmentless URI
       in most cases, as the indicated error will occur at a path below the position where the most recent
       identifier had been declared in the schema. Further, if the schema never declared an absolute base URI
       (containing a scheme), this URI won't be absolute either.

   error
       The actual error string.

   exception
       Indicates the error's severity is sufficient to stop evaluation.

   recommended_response
       A tuple, consisting of "[ integer, string ]", indicating the recommended HTTP response code and string to
       use for this error (if validating an HTTP request). This could exist for things like a failed
       authentication check in OpenAPI validation, in which case it would contain "[ 401, 'Unauthorized' ]".

       The string can be omitted at construction time, in which case it will be populated from the standard list
       of error strings corresponding to HTTP response codes (see RFC9110 §15).

   depth
       An integer which indicates how many subschemas deep this error was generated from. Can be used to
       construct a tree-like structure of errors.

Author

       Karen Etheridge <ether@cpan.org>

Description

       An instance of this class holds one error from evaluating a JSON Schema with JSON::Schema::Modern.

Methods

TO_JSON
       Returns a data structure suitable for serialization. Corresponds to one output unit as specified in
       <https://json-schema.org/draft/2020-12/json-schema-core#section-12.3> and
       <https://json-schema.org/draft/2020-12/output/schema>, except that "instanceLocation" and
       "keywordLocation" are JSON pointers, not URI fragments, even in draft2019-09. (See the "strict_basic"
       "output_format" in JSON::Schema::Modern, only available in that version, if the distinction is important
       to you.)

   dump
       Returns a JSON string representing the error object, according to the specification <https://json-
       schema.org/draft/2019-09/json-schema-core.html#rfc.section.10>.

Name

       JSON::Schema::Modern::Error - Contains a single error from a JSON Schema evaluation

Support

       Bugs may be submitted through <https://github.com/karenetheridge/JSON-Schema-Modern/issues>.

       I am also usually active on irc, as 'ether' at "irc.perl.org" and "irc.libera.chat".

       You can also find me on the JSON Schema Slack server <https://json-schema.slack.com> and OpenAPI Slack
       server <https://open-api.slack.com>, which are also great resources for finding help.

Synopsis

         use JSON::Schema::Modern;
         my $js = JSON::Schema::Modern->new;
         my $result = $js->evaluate($data, $schema);
         my @errors = $result->errors;

         my $message = $errors[0]->error;
         my $instance_location = $errors[0]->instance_location;

         my $errors_encoded = encode_json(\@errors);

Version

       version 0.611

See Also