Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/JSON/Schema/Modern/Vocabulary/OpenAPI.pm |
Statements | Executed 36 statements in 781µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 26µs | 28µs | BEGIN@1.321 | Module::Runtime::
5 | 1 | 1 | 22µs | 22µs | _traverse_keyword_externalDocs | JSON::Schema::Modern::Vocabulary::OpenAPI::
1 | 1 | 1 | 16µs | 606µs | BEGIN@11 | JSON::Schema::Modern::Vocabulary::OpenAPI::
1 | 1 | 1 | 11µs | 50µs | BEGIN@17 | JSON::Schema::Modern::Vocabulary::OpenAPI::
1 | 1 | 1 | 10µs | 34µs | BEGIN@13 | JSON::Schema::Modern::Vocabulary::OpenAPI::
1 | 1 | 1 | 10µs | 22µs | BEGIN@14 | JSON::Schema::Modern::Vocabulary::OpenAPI::
1 | 1 | 1 | 9µs | 9µs | BEGIN@9 | JSON::Schema::Modern::Vocabulary::OpenAPI::
1 | 1 | 1 | 7µs | 14µs | BEGIN@15 | JSON::Schema::Modern::Vocabulary::OpenAPI::
1 | 1 | 1 | 7µs | 15µs | BEGIN@16 | JSON::Schema::Modern::Vocabulary::OpenAPI::
1 | 1 | 1 | 6µs | 28µs | BEGIN@2.322 | Module::Runtime::
1 | 1 | 1 | 5µs | 187µs | BEGIN@10 | JSON::Schema::Modern::Vocabulary::OpenAPI::
1 | 1 | 1 | 5µs | 78µs | BEGIN@12 | JSON::Schema::Modern::Vocabulary::OpenAPI::
1 | 1 | 1 | 5µs | 147µs | BEGIN@18 | JSON::Schema::Modern::Vocabulary::OpenAPI::
1 | 1 | 1 | 1µs | 1µs | keywords | JSON::Schema::Modern::Vocabulary::OpenAPI::
1 | 1 | 1 | 1µs | 1µs | vocabulary | JSON::Schema::Modern::Vocabulary::OpenAPI::
0 | 0 | 0 | 0s | 0s | _eval_keyword_discriminator | JSON::Schema::Modern::Vocabulary::OpenAPI::
0 | 0 | 0 | 0s | 0s | _eval_keyword_example | JSON::Schema::Modern::Vocabulary::OpenAPI::
0 | 0 | 0 | 0s | 0s | _eval_keyword_externalDocs | JSON::Schema::Modern::Vocabulary::OpenAPI::
0 | 0 | 0 | 0s | 0s | _eval_keyword_xml | JSON::Schema::Modern::Vocabulary::OpenAPI::
0 | 0 | 0 | 0s | 0s | _traverse_keyword_discriminator | JSON::Schema::Modern::Vocabulary::OpenAPI::
0 | 0 | 0 | 0s | 0s | _traverse_keyword_example | JSON::Schema::Modern::Vocabulary::OpenAPI::
0 | 0 | 0 | 0s | 0s | _traverse_keyword_xml | JSON::Schema::Modern::Vocabulary::OpenAPI::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | 2 | 25µs | 2 | 30µs | # spent 28µs (26+2) within Module::Runtime::BEGIN@1.321 which was called:
# once (26µs+2µs) by Module::Runtime::require_module at line 1 # spent 28µs making 1 call to Module::Runtime::BEGIN@1.321
# spent 2µs making 1 call to strict::import |
2 | 2 | 37µs | 2 | 50µs | # spent 28µs (6+22) within Module::Runtime::BEGIN@2.322 which was called:
# once (6µs+22µs) by Module::Runtime::require_module at line 2 # spent 28µs making 1 call to Module::Runtime::BEGIN@2.322
# spent 22µs making 1 call to warnings::import |
3 | package JSON::Schema::Modern::Vocabulary::OpenAPI; | ||||
4 | # vim: set ts=8 sts=2 sw=2 tw=100 et : | ||||
5 | # ABSTRACT: Implementation of the JSON Schema OpenAPI vocabulary | ||||
6 | |||||
7 | 1 | 1µs | our $VERSION = '0.037'; | ||
8 | |||||
9 | 2 | 26µs | 1 | 9µs | # spent 9µs within JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@9 which was called:
# once (9µs+0s) by Module::Runtime::require_module at line 9 # spent 9µs making 1 call to JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@9 |
10 | 2 | 23µs | 2 | 369µs | # spent 187µs (5+182) within JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@10 which was called:
# once (5µs+182µs) by Module::Runtime::require_module at line 10 # spent 187µs making 1 call to JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@10
# spent 182µs making 1 call to Moo::import |
11 | 3 | 33µs | 3 | 1.20ms | # spent 606µs (16+590) within JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@11 which was called:
# once (16µs+590µs) by Module::Runtime::require_module at line 11 # spent 606µs making 1 call to JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@11
# spent 574µs making 1 call to strictures::import
# spent 15µs making 1 call to strictures::VERSION |
12 | 2 | 28µs | 2 | 151µs | # spent 78µs (5+73) within JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@12 which was called:
# once (5µs+73µs) by Module::Runtime::require_module at line 12 # spent 78µs making 1 call to JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@12
# spent 73µs making 1 call to experimental::import |
13 | 2 | 22µs | 2 | 37µs | # spent 34µs (10+24) within JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@13 which was called:
# once (10µs+24µs) by Module::Runtime::require_module at line 13 # spent 34µs making 1 call to JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@13
# spent 3µs making 1 call to if::import |
14 | 2 | 18µs | 2 | 23µs | # spent 22µs (10+12) within JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@14 which was called:
# once (10µs+12µs) by Module::Runtime::require_module at line 14 # spent 22µs making 1 call to JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@14
# spent 1µs making 1 call to if::unimport |
15 | 2 | 18µs | 2 | 14µs | # spent 14µs (7+7) within JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@15 which was called:
# once (7µs+7µs) by Module::Runtime::require_module at line 15 # spent 14µs making 1 call to JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@15
# spent 0s making 1 call to if::unimport |
16 | 2 | 19µs | 2 | 15µs | # spent 15µs (7+8) within JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@16 which was called:
# once (7µs+8µs) by Module::Runtime::require_module at line 16 # spent 15µs making 1 call to JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@16
# spent 0s making 1 call to if::unimport |
17 | 3 | 27µs | 3 | 89µs | # spent 50µs (11+39) within JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@17 which was called:
# once (11µs+39µs) by Module::Runtime::require_module at line 17 # spent 50µs making 1 call to JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@17
# spent 35µs making 1 call to Exporter::import
# spent 4µs making 1 call to UNIVERSAL::VERSION |
18 | 2 | 440µs | 2 | 289µs | # spent 147µs (5+142) within JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@18 which was called:
# once (5µs+142µs) by Module::Runtime::require_module at line 18 # spent 147µs making 1 call to JSON::Schema::Modern::Vocabulary::OpenAPI::BEGIN@18
# spent 142µs making 1 call to namespace::clean::import |
19 | |||||
20 | 1 | 2µs | 1 | 472µs | with 'JSON::Schema::Modern::Vocabulary'; # spent 472µs making 1 call to Moo::with |
21 | |||||
22 | # spent 1µs within JSON::Schema::Modern::Vocabulary::OpenAPI::vocabulary which was called:
# once (1µs+0s) by JSON::Schema::Modern::add_vocabulary at line 718 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm | ||||
23 | 1 | 3µs | 'https://spec.openapis.org/oas/3.1/vocab/base' => 'draft2020-12', | ||
24 | } | ||||
25 | |||||
26 | # spent 1µs within JSON::Schema::Modern::Vocabulary::OpenAPI::keywords which was called:
# once (1µs+0s) by JSON::Schema::Modern::_traverse_subschema at line 480 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm | ||||
27 | 1 | 3µs | qw(discriminator example externalDocs xml); | ||
28 | } | ||||
29 | |||||
30 | sub _traverse_keyword_discriminator ($self, $schema, $state) { | ||||
31 | return if not assert_keyword_type($state, $schema, 'object'); | ||||
32 | |||||
33 | # "the discriminator field MUST be a required field" | ||||
34 | return E($state, 'missing required field propertyName') | ||||
35 | if not exists $schema->{discriminator}{propertyName}; | ||||
36 | return E({ %$state, _schema_path_suffix => 'propertyName' }, 'discriminator propertyName is not a string') | ||||
37 | if not is_type('string', $schema->{discriminator}{propertyName}); | ||||
38 | |||||
39 | my $valid = 1; | ||||
40 | if (exists $schema->{discriminator}{mapping}) { | ||||
41 | return if not assert_keyword_type({ %$state, _schema_path_suffix => 'mapping' }, $schema, 'object'); | ||||
42 | return E({ %$state, _schema_path_suffix => 'mapping' }, 'discriminator mapping is not an object ') | ||||
43 | if not is_type('object', $schema->{discriminator}{mapping}); | ||||
44 | foreach my $mapping_key (sort keys $schema->{discriminator}{mapping}->%*) { | ||||
45 | my $uri = $schema->{discriminator}{mapping}{$mapping_key}; | ||||
46 | $valid = E({ %$state, _schema_path_suffix => [ 'mapping', $mapping_key ] }, 'discriminator mapping value for "%s" is not a string', $mapping_key), next if not is_type('string', $uri); | ||||
47 | } | ||||
48 | } | ||||
49 | |||||
50 | $valid = E($state, 'missing sibling keyword: one of oneOf, anyOf, allOf') | ||||
51 | if not grep exists $schema->{$_}, qw(oneOf anyOf allOf); | ||||
52 | |||||
53 | return 1; | ||||
54 | } | ||||
55 | |||||
56 | sub _eval_keyword_discriminator ($self, $data, $schema, $state) { | ||||
57 | # Note: the spec is unclear of the expected behaviour when the data instance is not an object | ||||
58 | return 1 if not is_type('object', $data); | ||||
59 | |||||
60 | my $discriminator_key = $schema->{discriminator}{propertyName}; | ||||
61 | |||||
62 | # property with name <propertyName> MUST be present in the data payload | ||||
63 | return E($state, 'missing required discriminator field "%s"', $discriminator_key) | ||||
64 | if not exists $data->{$discriminator_key}; | ||||
65 | |||||
66 | my $discriminator_value = $data->{$discriminator_key}; | ||||
67 | |||||
68 | # if /components/$discriminator_value exists, that schema must validate | ||||
69 | my $uri = Mojo::URL->new->fragment(jsonp('', qw(components schemas), $discriminator_value)) | ||||
70 | ->to_abs($state->{initial_schema_uri}); | ||||
71 | if (my $component_schema_info = $state->{evaluator}->_fetch_from_uri($uri)) { | ||||
72 | $state = { %$state, _schema_path_suffix => 'propertyName' }; | ||||
73 | } | ||||
74 | elsif (exists $schema->{discriminator}{mapping} and exists $schema->{discriminator}{mapping}{$discriminator_value}) { | ||||
75 | # use 'mapping' to determine which schema to use. | ||||
76 | $uri = Mojo::URL->new($schema->{discriminator}{mapping}{$discriminator_value}); | ||||
77 | $state = { %$state, _schema_path_suffix => [ 'mapping', $discriminator_value ] }; | ||||
78 | } | ||||
79 | else { | ||||
80 | # If the discriminator value does not match an implicit or explicit mapping, no schema can be | ||||
81 | # determined and validation SHOULD fail. | ||||
82 | return E($state, 'invalid %s: "%s"', $discriminator_key, $discriminator_value); | ||||
83 | } | ||||
84 | |||||
85 | return E($state, 'subschema for %s: %s is invalid', $discriminator_key, $discriminator_value) | ||||
86 | if not $self->eval_subschema_at_uri($data, $schema, $state, $uri); | ||||
87 | return 1; | ||||
88 | } | ||||
89 | |||||
90 | sub _traverse_keyword_example { 1 } | ||||
91 | |||||
92 | sub _eval_keyword_example ($self, $data, $schema, $state) { | ||||
93 | annotate_self($state, $schema); | ||||
94 | } | ||||
95 | |||||
96 | # until we do something with these values, we do not bother checking the structure | ||||
97 | 5 | 13µs | # spent 22µs within JSON::Schema::Modern::Vocabulary::OpenAPI::_traverse_keyword_externalDocs which was called 5 times, avg 4µs/call:
# 5 times (22µs+0s) by JSON::Schema::Modern::_traverse_subschema at line 492 of /Users/ether/git/JSON-Schema-Modern/lib/JSON/Schema/Modern.pm, avg 4µs/call | ||
98 | |||||
99 | sub _eval_keyword_externalDocs { goto \&_eval_keyword_example } | ||||
100 | |||||
101 | # until we do something with these values, we do not bother checking the structure | ||||
102 | sub _traverse_keyword_xml { 1 } | ||||
103 | |||||
104 | sub _eval_keyword_xml { goto \&_eval_keyword_example } | ||||
105 | |||||
106 | 1 | 9µs | 1; | ||
107 | |||||
108 | 1 | 34µs | 1 | 301µs | __END__ # spent 301µs making 1 call to B::Hooks::EndOfScope::XS::__ANON__[B/Hooks/EndOfScope/XS.pm:26] |