NAME
JSON::Schema::Modern::Document - One JSON Schema document
VERSION
version 0.575
SYNOPSIS
use JSON::Schema::Modern::Document;
my $document = JSON::Schema::Modern::Document->new(
canonical_uri => 'https://example.com/v1/schema',
metaschema_uri => 'https://example.com/my/custom/metaschema',
schema => $schema,
);
my $foo_definition = $document->get('/$defs/foo');
my %resource_index = $document->resource_index;
my sanity_check = $document->validate;
DESCRIPTION
This class represents one JSON Schema document, to be used by JSON::Schema::Modern.
ATTRIBUTES
schema
The actual raw data representing the schema.
canonical_uri
When passed in during construction, this represents the initial URI by which the document should be known. It is overwritten with the root schema's $id
property when one exists, and as such can be considered the canonical URI for the document as a whole.
metaschema_uri
Sets the metaschema that is used to describe the document (or more specifically, any JSON Schemas contained within the document), which determines the specification version and vocabularies used during evaluation. Does not override any $schema
keyword actually present in the schema document.
evaluator
A JSON::Schema::Modern object. Optional, unless custom metaschemas are used.
resource_index
An index of URIs to subschemas (JSON pointer to reach the location, and the canonical URI of that location) for all identifiable subschemas found in the document. An entry for URI ''
is added only when no other suitable identifier can be found for the root schema.
This attribute should only be used by JSON::Schema::Modern and not intended for use externally (you should use the public accessors in JSON::Schema::Modern instead).
When called as a method, returns the flattened list of tuples (path, uri). You can also use resource_pairs
which returns a list of tuples as arrayrefs.
canonical_uri_index
An index of JSON pointers (from the document root) to canonical URIs. This is the inversion of "resource_index" and is constructed as that is built up.
errors
A list of JSON::Schema::Modern::Error objects that resulted when the schema document was originally parsed. (If a syntax error occurred, usually there will be just one error, as parse errors halt the parsing process.) Documents with errors cannot be evaluated.
METHODS
path_to_canonical_uri
Given a JSON pointer (a path) within this document, returns the canonical URI corresponding to that location. Only fragmentless URIs can be looked up in this manner, so it is only suitable for finding the canonical URI corresponding to a subschema known to have an $id
keyword.
contains
Check if "schema" contains a value that can be identified with the given JSON Pointer. See "contains" in Mojo::JSON::Pointer.
get
Extract value from "schema" identified by the given JSON Pointer. See "get" in Mojo::JSON::Pointer.
validate
Evaluates the document against its metaschema. See "evaluate" in JSON::Schema::Modern. For regular JSON Schemas this is redundant with creating the document in the first place (which also includes a validation check), but for some subclasses of this class, additional things might be checked that are not caught by document creation.
TO_JSON
Returns a data structure suitable for serialization. See "schema".
SEE ALSO
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 and OpenAPI Slack server, which are also great resources for finding help.
AUTHOR
Karen Etheridge <ether@cpan.org>
COPYRIGHT AND LICENCE
This software is copyright (c) 2020 by Karen Etheridge.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.