JSON-Schema-Modern-Document-OpenAPI
view release on metacpan or search on metacpan
lib/JSON/Schema/Modern/Document/OpenAPI.pm view on Meta::CPAN
use strict;
use warnings;
package JSON::Schema::Modern::Document::OpenAPI; # git description: v0.019-17-ge120405
# vim: set ts=8 sts=2 sw=2 tw=100 et :
# ABSTRACT: One OpenAPI v3.1 document
# KEYWORDS: JSON Schema data validation request response OpenAPI
our $VERSION = '0.020';
use 5.020; # for fc, unicode_strings features
use Moo;
use strictures 2;
use experimental qw(signatures postderef);
use if "$]" >= 5.022, experimental => 're_strict';
no if "$]" >= 5.031009, feature => 'indirect';
no if "$]" >= 5.033001, feature => 'multidimensional';
no if "$]" >= 5.033006, feature => 'bareword_filehandles';
use JSON::Schema::Modern::Utilities 0.525 qw(assert_keyword_exists assert_keyword_type E canonical_uri get_type);
use Safe::Isa;
use File::ShareDir 'dist_dir';
use Path::Tiny;
use List::Util qw(any pairs);
use Ref::Util 'is_plain_hashref';
use MooX::HandlesVia;
use MooX::TypeTiny 0.002002;
use Types::Standard qw(InstanceOf HashRef Str);
use namespace::clean;
extends 'JSON::Schema::Modern::Document';
use constant DEFAULT_DIALECT => 'https://spec.openapis.org/oas/3.1/dialect/base';
use constant DEFAULT_SCHEMAS => {
# local filename => identifier to add the schema as
'oas/dialect/base.schema.json' => 'https://spec.openapis.org/oas/3.1/dialect/base', # metaschema for json schemas contained within openapi documents
'oas/meta/base.schema.json' => 'https://spec.openapis.org/oas/3.1/meta/base', # vocabulary definition
'oas/schema-base.json' => 'https://spec.openapis.org/oas/3.1/schema-base', # openapi document schema + custom json schema dialect
'oas/schema.json' => 'https://spec.openapis.org/oas/3.1/schema', # the main openapi document schema
};
use constant DEFAULT_METASCHEMA => 'https://spec.openapis.org/oas/3.1/schema-base/latest';
has '+evaluator' => (
required => 1,
);
has '+metaschema_uri' => (
default => DEFAULT_METASCHEMA,
);
has json_schema_dialect => (
is => 'rwp',
isa => InstanceOf['Mojo::URL'],
coerce => sub { $_[0]->$_isa('Mojo::URL') ? $_[0] : Mojo::URL->new($_[0]) },
);
# operationId => document path
has operationIds => (
is => 'bare',
isa => HashRef[Str],
handles_via => 'Hash',
handles => {
_add_operationId => 'set',
get_operationId => 'get',
},
lazy => 1,
default => sub { {} },
);
sub traverse ($self, $evaluator) {
$self->_add_vocab_and_default_schemas;
my $schema = $self->schema;
my $state = {
initial_schema_uri => $self->canonical_uri,
traversed_schema_path => '',
schema_path => '',
data_path => '',
errors => [],
evaluator => $evaluator,
identifiers => [],
configs => {},
spec_version => $evaluator->SPECIFICATION_VERSION_DEFAULT,
( run in 1.563 second using v1.01-cache-2.11-cpan-39bf76dae61 )