openapi_parser 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ci.yaml +4 -2
- data/.ruby-version +1 -1
- data/CHANGELOG.md +34 -0
- data/README.md +1 -1
- data/lib/openapi_parser/config.rb +17 -0
- data/lib/openapi_parser/schema_validator/array_validator.rb +7 -3
- data/lib/openapi_parser/schema_validator/minimum_maximum.rb +17 -4
- data/lib/openapi_parser/schema_validator/nil_validator.rb +4 -0
- data/lib/openapi_parser/schema_validator/options.rb +5 -2
- data/lib/openapi_parser/schema_validator/string_validator.rb +12 -9
- data/lib/openapi_parser/schema_validator/type_mismatch_validator.rb +11 -0
- data/lib/openapi_parser/schema_validator.rb +84 -2
- data/lib/openapi_parser/schemas/components.rb +4 -0
- data/lib/openapi_parser/schemas/openapi.rb +20 -0
- data/lib/openapi_parser/schemas/schema.rb +12 -1
- data/lib/openapi_parser/spec_validator/rule.rb +68 -0
- data/lib/openapi_parser/spec_validator/rules/const_in_30.rb +25 -0
- data/lib/openapi_parser/spec_validator/rules/content_encoding_in_30.rb +24 -0
- data/lib/openapi_parser/spec_validator/rules/content_media_type_in_30.rb +25 -0
- data/lib/openapi_parser/spec_validator/rules/content_schema_in_30.rb +25 -0
- data/lib/openapi_parser/spec_validator/rules/dynamic_anchor_in_30.rb +25 -0
- data/lib/openapi_parser/spec_validator/rules/dynamic_ref_in_30.rb +25 -0
- data/lib/openapi_parser/spec_validator/rules/example_singular_deprecation.rb +25 -0
- data/lib/openapi_parser/spec_validator/rules/exclusive_maximum.rb +32 -0
- data/lib/openapi_parser/spec_validator/rules/exclusive_minimum.rb +32 -0
- data/lib/openapi_parser/spec_validator/rules/json_schema_dialect_in_30.rb +19 -0
- data/lib/openapi_parser/spec_validator/rules/nullable_deprecation.rb +25 -0
- data/lib/openapi_parser/spec_validator/rules/path_items_in_30.rb +25 -0
- data/lib/openapi_parser/spec_validator/rules/prefix_items_in_30.rb +25 -0
- data/lib/openapi_parser/spec_validator/rules/type_array_in_30.rb +25 -0
- data/lib/openapi_parser/spec_validator/rules/type_null_in_30.rb +26 -0
- data/lib/openapi_parser/spec_validator/rules/webhooks_in_30.rb +18 -0
- data/lib/openapi_parser/spec_validator/spec_violation.rb +11 -0
- data/lib/openapi_parser/spec_validator.rb +85 -0
- data/lib/openapi_parser/version.rb +1 -1
- data/lib/openapi_parser.rb +3 -0
- data/sig/openapi_parser/config.rbs +3 -0
- data/sig/openapi_parser/schema_validator.rbs +4 -0
- data/sig/openapi_parser/schema_validators/options.rbs +1 -1
- data/sig/openapi_parser/spec_validator.rbs +109 -0
- data/sig/openapi_parser.rbs +2 -0
- metadata +23 -2
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module OpenAPIParser
|
|
2
|
+
class SpecValidator
|
|
3
|
+
module Rules
|
|
4
|
+
# `$dynamicAnchor` is the companion of `$dynamicRef` from JSON Schema
|
|
5
|
+
# 2020-12, declaring the dynamic resolution point. 3.0 has nothing
|
|
6
|
+
# equivalent; the rule flags it on 3.0 documents.
|
|
7
|
+
class DynamicAnchorIn30 < Rule
|
|
8
|
+
def check(root)
|
|
9
|
+
return [] unless version_before?('3.1')
|
|
10
|
+
|
|
11
|
+
violations = []
|
|
12
|
+
each_schema(root) do |schema|
|
|
13
|
+
next unless schema.raw_schema.is_a?(Hash) && schema.raw_schema.key?('$dynamicAnchor')
|
|
14
|
+
|
|
15
|
+
violations << violation(
|
|
16
|
+
path: schema.object_reference,
|
|
17
|
+
message: '`$dynamicAnchor` is a 3.1 addition (from JSON Schema 2020-12); 3.0 has no equivalent',
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
violations
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module OpenAPIParser
|
|
2
|
+
class SpecValidator
|
|
3
|
+
module Rules
|
|
4
|
+
# `$dynamicRef` is a JSON Schema 2020-12 referencing mechanism that
|
|
5
|
+
# 3.1 adopted. 3.0 does not recognize it. The parse layer keeps the
|
|
6
|
+
# value as raw schema data; this rule reports the version mismatch.
|
|
7
|
+
class DynamicRefIn30 < Rule
|
|
8
|
+
def check(root)
|
|
9
|
+
return [] unless version_before?('3.1')
|
|
10
|
+
|
|
11
|
+
violations = []
|
|
12
|
+
each_schema(root) do |schema|
|
|
13
|
+
next unless schema.raw_schema.is_a?(Hash) && schema.raw_schema.key?('$dynamicRef')
|
|
14
|
+
|
|
15
|
+
violations << violation(
|
|
16
|
+
path: schema.object_reference,
|
|
17
|
+
message: '`$dynamicRef` is a 3.1 addition (from JSON Schema 2020-12); 3.0 only knows `$ref`',
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
violations
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module OpenAPIParser
|
|
2
|
+
class SpecValidator
|
|
3
|
+
module Rules
|
|
4
|
+
# In 3.1 the singular `example` keyword on a Schema is deprecated in
|
|
5
|
+
# favor of the JSON Schema `examples` array. The field is still
|
|
6
|
+
# allowed but discouraged, so we report it as a violation.
|
|
7
|
+
class ExampleSingularDeprecation < Rule
|
|
8
|
+
def check(root)
|
|
9
|
+
return [] unless version_at_least?('3.1')
|
|
10
|
+
|
|
11
|
+
violations = []
|
|
12
|
+
each_schema(root) do |schema|
|
|
13
|
+
next unless schema.raw_schema.is_a?(Hash) && schema.raw_schema.key?('example')
|
|
14
|
+
|
|
15
|
+
violations << violation(
|
|
16
|
+
path: schema.object_reference,
|
|
17
|
+
message: 'singular `example` on a Schema is deprecated in 3.1; use the `examples` array',
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
violations
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module OpenAPIParser
|
|
2
|
+
class SpecValidator
|
|
3
|
+
module Rules
|
|
4
|
+
class ExclusiveMaximum < Rule
|
|
5
|
+
def check(root)
|
|
6
|
+
return [] if version.nil?
|
|
7
|
+
|
|
8
|
+
violations = []
|
|
9
|
+
each_schema(root) do |schema|
|
|
10
|
+
value = schema.exclusiveMaximum
|
|
11
|
+
next if value.nil?
|
|
12
|
+
|
|
13
|
+
if version_before?('3.1')
|
|
14
|
+
if value.is_a?(Numeric)
|
|
15
|
+
violations << violation(
|
|
16
|
+
path: schema.object_reference,
|
|
17
|
+
message: 'numeric exclusiveMaximum is a 3.1-only form; in 3.0 use a Boolean modifier paired with `maximum`',
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
elsif value == true || value == false
|
|
21
|
+
violations << violation(
|
|
22
|
+
path: schema.object_reference,
|
|
23
|
+
message: 'Boolean exclusiveMaximum is a 3.0-only form; in 3.1 use a standalone numeric bound',
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
violations
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
module OpenAPIParser
|
|
2
|
+
class SpecValidator
|
|
3
|
+
module Rules
|
|
4
|
+
class ExclusiveMinimum < Rule
|
|
5
|
+
def check(root)
|
|
6
|
+
return [] if version.nil?
|
|
7
|
+
|
|
8
|
+
violations = []
|
|
9
|
+
each_schema(root) do |schema|
|
|
10
|
+
value = schema.exclusiveMinimum
|
|
11
|
+
next if value.nil?
|
|
12
|
+
|
|
13
|
+
if version_before?('3.1')
|
|
14
|
+
if value.is_a?(Numeric)
|
|
15
|
+
violations << violation(
|
|
16
|
+
path: schema.object_reference,
|
|
17
|
+
message: 'numeric exclusiveMinimum is a 3.1-only form; in 3.0 use a Boolean modifier paired with `minimum`',
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
elsif value == true || value == false
|
|
21
|
+
violations << violation(
|
|
22
|
+
path: schema.object_reference,
|
|
23
|
+
message: 'Boolean exclusiveMinimum is a 3.0-only form; in 3.1 use a standalone numeric bound',
|
|
24
|
+
)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
violations
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
end
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module OpenAPIParser
|
|
2
|
+
class SpecValidator
|
|
3
|
+
module Rules
|
|
4
|
+
# `jsonSchemaDialect` is a 3.1 root-level addition; 3.0 has no
|
|
5
|
+
# equivalent.
|
|
6
|
+
class JsonSchemaDialectIn30 < Rule
|
|
7
|
+
def check(root)
|
|
8
|
+
return [] unless version_before?('3.1')
|
|
9
|
+
return [] unless root.raw_schema.is_a?(Hash) && root.raw_schema.key?('jsonSchemaDialect')
|
|
10
|
+
|
|
11
|
+
[violation(
|
|
12
|
+
path: '#/jsonSchemaDialect',
|
|
13
|
+
message: '`jsonSchemaDialect` is a 3.1 root-level addition; 3.0 documents have no such field',
|
|
14
|
+
)]
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module OpenAPIParser
|
|
2
|
+
class SpecValidator
|
|
3
|
+
module Rules
|
|
4
|
+
# `nullable` is a 3.0 keyword that 3.1 removed in favor of
|
|
5
|
+
# `type: [..., "null"]`. The field's mere presence on a 3.1 document
|
|
6
|
+
# is a spec violation, regardless of true/false.
|
|
7
|
+
class NullableDeprecation < Rule
|
|
8
|
+
def check(root)
|
|
9
|
+
return [] unless version_at_least?('3.1')
|
|
10
|
+
|
|
11
|
+
violations = []
|
|
12
|
+
each_schema(root) do |schema|
|
|
13
|
+
next unless schema.raw_schema.is_a?(Hash) && schema.raw_schema.key?('nullable')
|
|
14
|
+
|
|
15
|
+
violations << violation(
|
|
16
|
+
path: schema.object_reference,
|
|
17
|
+
message: '`nullable` was removed in 3.1; use `type: [..., "null"]` instead',
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
violations
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module OpenAPIParser
|
|
2
|
+
class SpecValidator
|
|
3
|
+
module Rules
|
|
4
|
+
# `components.pathItems` is a 3.1 addition. The parse layer accepts it
|
|
5
|
+
# in 3.0 documents permissively; this rule reports the version
|
|
6
|
+
# mismatch.
|
|
7
|
+
class PathItemsIn30 < Rule
|
|
8
|
+
def check(root)
|
|
9
|
+
return [] unless version_before?('3.1')
|
|
10
|
+
|
|
11
|
+
components = root.components
|
|
12
|
+
return [] unless components
|
|
13
|
+
|
|
14
|
+
raw = components.raw_schema
|
|
15
|
+
return [] unless raw.is_a?(Hash) && raw.key?('pathItems')
|
|
16
|
+
|
|
17
|
+
[violation(
|
|
18
|
+
path: "#{components.object_reference}/pathItems",
|
|
19
|
+
message: '`components.pathItems` is a 3.1 addition; 3.0 documents should not declare it',
|
|
20
|
+
)]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module OpenAPIParser
|
|
2
|
+
class SpecValidator
|
|
3
|
+
module Rules
|
|
4
|
+
# `prefixItems` is JSON Schema 2020-12's positional tuple keyword.
|
|
5
|
+
# 3.1 adopts it; 3.0 has no equivalent and parsing it is a spec
|
|
6
|
+
# mismatch the validator should report.
|
|
7
|
+
class PrefixItemsIn30 < Rule
|
|
8
|
+
def check(root)
|
|
9
|
+
return [] unless version_before?('3.1')
|
|
10
|
+
|
|
11
|
+
violations = []
|
|
12
|
+
each_schema(root) do |schema|
|
|
13
|
+
next unless schema.raw_schema.is_a?(Hash) && schema.raw_schema.key?('prefixItems')
|
|
14
|
+
|
|
15
|
+
violations << violation(
|
|
16
|
+
path: schema.object_reference,
|
|
17
|
+
message: '`prefixItems` is a 3.1 addition (from JSON Schema 2020-12); 3.0 has no equivalent',
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
violations
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
module OpenAPIParser
|
|
2
|
+
class SpecValidator
|
|
3
|
+
module Rules
|
|
4
|
+
# 3.1 lets `type` be an Array of primitive type names (e.g.
|
|
5
|
+
# `["string", "null"]`). 3.0 only allowed a single String, so the
|
|
6
|
+
# array form on a 3.0 document is a spec violation.
|
|
7
|
+
class TypeArrayIn30 < Rule
|
|
8
|
+
def check(root)
|
|
9
|
+
return [] unless version_before?('3.1')
|
|
10
|
+
|
|
11
|
+
violations = []
|
|
12
|
+
each_schema(root) do |schema|
|
|
13
|
+
next unless schema.type.is_a?(Array)
|
|
14
|
+
|
|
15
|
+
violations << violation(
|
|
16
|
+
path: schema.object_reference,
|
|
17
|
+
message: '`type` as an Array of primitive names is a 3.1 addition; 3.0 expects a single type String',
|
|
18
|
+
)
|
|
19
|
+
end
|
|
20
|
+
violations
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
module OpenAPIParser
|
|
2
|
+
class SpecValidator
|
|
3
|
+
module Rules
|
|
4
|
+
# `type: "null"` was added by 3.1; 3.0 only allowed the original six
|
|
5
|
+
# primitive type names. The parse layer accepts the literal anyway,
|
|
6
|
+
# so we report the mismatch here. Array-form types like
|
|
7
|
+
# `["string", "null"]` are covered by a separate rule.
|
|
8
|
+
class TypeNullIn30 < Rule
|
|
9
|
+
def check(root)
|
|
10
|
+
return [] unless version_before?('3.1')
|
|
11
|
+
|
|
12
|
+
violations = []
|
|
13
|
+
each_schema(root) do |schema|
|
|
14
|
+
next unless schema.type == 'null'
|
|
15
|
+
|
|
16
|
+
violations << violation(
|
|
17
|
+
path: schema.object_reference,
|
|
18
|
+
message: '`type: "null"` is a 3.1 addition; 3.0 documents have no such primitive',
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
violations
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
module OpenAPIParser
|
|
2
|
+
class SpecValidator
|
|
3
|
+
module Rules
|
|
4
|
+
# `webhooks` is a 3.1 root-level addition; 3.0 has no equivalent.
|
|
5
|
+
class WebhooksIn30 < Rule
|
|
6
|
+
def check(root)
|
|
7
|
+
return [] unless version_before?('3.1')
|
|
8
|
+
return [] unless root.raw_schema.is_a?(Hash) && root.raw_schema.key?('webhooks')
|
|
9
|
+
|
|
10
|
+
[violation(
|
|
11
|
+
path: '#/webhooks',
|
|
12
|
+
message: '`webhooks` is a 3.1 root-level addition; 3.0 documents have no such field',
|
|
13
|
+
)]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
require_relative 'spec_validator/spec_violation'
|
|
2
|
+
require_relative 'spec_validator/rule'
|
|
3
|
+
require_relative 'spec_validator/rules/exclusive_minimum'
|
|
4
|
+
require_relative 'spec_validator/rules/exclusive_maximum'
|
|
5
|
+
require_relative 'spec_validator/rules/content_encoding_in_30'
|
|
6
|
+
require_relative 'spec_validator/rules/content_media_type_in_30'
|
|
7
|
+
require_relative 'spec_validator/rules/prefix_items_in_30'
|
|
8
|
+
require_relative 'spec_validator/rules/json_schema_dialect_in_30'
|
|
9
|
+
require_relative 'spec_validator/rules/type_array_in_30'
|
|
10
|
+
require_relative 'spec_validator/rules/path_items_in_30'
|
|
11
|
+
require_relative 'spec_validator/rules/nullable_deprecation'
|
|
12
|
+
require_relative 'spec_validator/rules/example_singular_deprecation'
|
|
13
|
+
require_relative 'spec_validator/rules/type_null_in_30'
|
|
14
|
+
require_relative 'spec_validator/rules/webhooks_in_30'
|
|
15
|
+
require_relative 'spec_validator/rules/const_in_30'
|
|
16
|
+
require_relative 'spec_validator/rules/dynamic_ref_in_30'
|
|
17
|
+
require_relative 'spec_validator/rules/dynamic_anchor_in_30'
|
|
18
|
+
require_relative 'spec_validator/rules/content_schema_in_30'
|
|
19
|
+
|
|
20
|
+
module OpenAPIParser
|
|
21
|
+
class SpecViolationError < OpenAPIError
|
|
22
|
+
attr_reader :violations
|
|
23
|
+
|
|
24
|
+
def initialize(violations)
|
|
25
|
+
@violations = violations
|
|
26
|
+
super(nil)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def message
|
|
30
|
+
@violations.map(&:to_s).join("\n")
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
class SpecValidator
|
|
35
|
+
def self.run(root)
|
|
36
|
+
new(root).run
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.run!(root, policy:)
|
|
40
|
+
return if policy == :silent
|
|
41
|
+
|
|
42
|
+
violations = run(root)
|
|
43
|
+
return if violations.empty?
|
|
44
|
+
|
|
45
|
+
case policy
|
|
46
|
+
when :warn
|
|
47
|
+
violations.each { |v| warn(v.to_s) }
|
|
48
|
+
when :raise
|
|
49
|
+
raise OpenAPIParser::SpecViolationError.new(violations)
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def initialize(root)
|
|
54
|
+
@root = root
|
|
55
|
+
@version = root.openapi_version
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def run
|
|
59
|
+
rules.flat_map { |klass| klass.new(@version).check(@root) }
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
def rules
|
|
65
|
+
[
|
|
66
|
+
Rules::ExclusiveMinimum,
|
|
67
|
+
Rules::ExclusiveMaximum,
|
|
68
|
+
Rules::ContentEncodingIn30,
|
|
69
|
+
Rules::ContentMediaTypeIn30,
|
|
70
|
+
Rules::PrefixItemsIn30,
|
|
71
|
+
Rules::JsonSchemaDialectIn30,
|
|
72
|
+
Rules::TypeArrayIn30,
|
|
73
|
+
Rules::PathItemsIn30,
|
|
74
|
+
Rules::NullableDeprecation,
|
|
75
|
+
Rules::ExampleSingularDeprecation,
|
|
76
|
+
Rules::TypeNullIn30,
|
|
77
|
+
Rules::WebhooksIn30,
|
|
78
|
+
Rules::ConstIn30,
|
|
79
|
+
Rules::DynamicRefIn30,
|
|
80
|
+
Rules::DynamicAnchorIn30,
|
|
81
|
+
Rules::ContentSchemaIn30,
|
|
82
|
+
]
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
end
|
data/lib/openapi_parser.rb
CHANGED
|
@@ -15,6 +15,7 @@ require 'openapi_parser/request_operation'
|
|
|
15
15
|
require 'openapi_parser/schema_validator'
|
|
16
16
|
require 'openapi_parser/parameter_validator'
|
|
17
17
|
require 'openapi_parser/reference_expander'
|
|
18
|
+
require 'openapi_parser/spec_validator'
|
|
18
19
|
|
|
19
20
|
module OpenAPIParser
|
|
20
21
|
class << self
|
|
@@ -99,6 +100,8 @@ module OpenAPIParser
|
|
|
99
100
|
path_item.set_path_item_to_operation
|
|
100
101
|
end
|
|
101
102
|
|
|
103
|
+
OpenAPIParser::SpecValidator.run!(root, policy: config.strict_specification_version)
|
|
104
|
+
|
|
102
105
|
root
|
|
103
106
|
end
|
|
104
107
|
end
|
|
@@ -9,11 +9,14 @@ module OpenAPIParser
|
|
|
9
9
|
|
|
10
10
|
def initialize: (untyped config) -> untyped
|
|
11
11
|
def allow_empty_date_and_datetime: -> bool
|
|
12
|
+
def date_coerce_class: -> (singleton(Object) | nil)
|
|
12
13
|
def datetime_coerce_class: -> (singleton(Object) | nil)
|
|
13
14
|
def coerce_value: -> bool
|
|
14
15
|
def expand_reference: -> bool
|
|
15
16
|
def strict_response_validation: -> bool
|
|
16
17
|
def strict_reference_validation: -> bool
|
|
18
|
+
KNOWN_STRICT_SPECIFICATION_VERSION_VALUES: Array[Symbol]
|
|
19
|
+
def strict_specification_version: -> (:silent | :warn | :raise)
|
|
17
20
|
def validate_header: -> bool
|
|
18
21
|
def request_validator_options: -> OpenAPIParser::SchemaValidator::Options
|
|
19
22
|
def response_validate_options: -> OpenAPIParser::SchemaValidator::ResponseValidateOptions
|
|
@@ -6,6 +6,7 @@ module OpenAPIParser
|
|
|
6
6
|
@schema: OpenAPIParser::Schemas::Schema
|
|
7
7
|
@coerce_value: bool | nil
|
|
8
8
|
@datetime_coerce_class: singleton(Object) | nil
|
|
9
|
+
@date_coerce_class: singleton(Object) | nil
|
|
9
10
|
@string_validator: OpenAPIParser::SchemaValidator::StringValidator | nil
|
|
10
11
|
@integer_validator: OpenAPIParser::SchemaValidator::IntegerValidator | nil
|
|
11
12
|
@float_validator: OpenAPIParser::SchemaValidator::FloatValidator | nil
|
|
@@ -26,6 +27,9 @@ module OpenAPIParser
|
|
|
26
27
|
|
|
27
28
|
private
|
|
28
29
|
def validator: (Object value, OpenAPIParser::Schemas::Schema schema) -> [OpenAPIParser::SchemaValidator::Base, OpenAPIParser::validate_error]
|
|
30
|
+
def validator_for_type: (String? type) -> OpenAPIParser::SchemaValidator::Base
|
|
31
|
+
def coerce_into_type_array?: (Object value, OpenAPIParser::Schemas::Schema schema) -> bool
|
|
32
|
+
def coerce_into_type_array: (Object value, OpenAPIParser::Schemas::Schema schema, **untyped) -> [Object, OpenAPIParser::validate_error]
|
|
29
33
|
def string_validator: -> OpenAPIParser::SchemaValidator::StringValidator
|
|
30
34
|
def integer_validator: -> OpenAPIParser::SchemaValidator::IntegerValidator
|
|
31
35
|
def float_validator: -> OpenAPIParser::SchemaValidator::FloatValidator
|
|
@@ -6,7 +6,7 @@ module OpenAPIParser
|
|
|
6
6
|
attr_reader coerce_value: bool | nil
|
|
7
7
|
attr_reader datetime_coerce_class: singleton(Object) | nil
|
|
8
8
|
attr_reader validate_header: bool
|
|
9
|
-
def initialize: (?allow_empty_date_and_datetime: bool | nil, ?coerce_value: bool | nil, ?datetime_coerce_class: singleton(Object) | nil, ?validate_header: bool) -> untyped
|
|
9
|
+
def initialize: (?allow_empty_date_and_datetime: bool | nil, ?coerce_value: bool | nil, ?datetime_coerce_class: singleton(Object) | nil, ?date_coerce_class: singleton(Object) | nil, ?validate_header: bool) -> untyped
|
|
10
10
|
end
|
|
11
11
|
|
|
12
12
|
class ResponseValidateOptions
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
module OpenAPIParser
|
|
2
|
+
class SpecViolationError < OpenAPIError
|
|
3
|
+
@violations: Array[OpenAPIParser::SpecValidator::SpecViolation]
|
|
4
|
+
attr_reader violations: Array[OpenAPIParser::SpecValidator::SpecViolation]
|
|
5
|
+
|
|
6
|
+
def initialize: (Array[OpenAPIParser::SpecValidator::SpecViolation] violations) -> void
|
|
7
|
+
def message: () -> String
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
class SpecValidator
|
|
11
|
+
@root: OpenAPIParser::Schemas::OpenAPI
|
|
12
|
+
@version: Gem::Version?
|
|
13
|
+
|
|
14
|
+
def self.run: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecViolation]
|
|
15
|
+
def self.run!: (OpenAPIParser::Schemas::OpenAPI root, policy: (:silent | :warn | :raise)) -> void
|
|
16
|
+
def initialize: (OpenAPIParser::Schemas::OpenAPI root) -> void
|
|
17
|
+
def run: () -> Array[SpecViolation]
|
|
18
|
+
private def rules: () -> Array[singleton(Rule)]
|
|
19
|
+
|
|
20
|
+
class SpecViolation < ::Struct[untyped]
|
|
21
|
+
attr_accessor message: String
|
|
22
|
+
attr_accessor path: String
|
|
23
|
+
attr_accessor rule_name: Symbol
|
|
24
|
+
def to_s: () -> String
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
class Rule
|
|
28
|
+
@version: Gem::Version?
|
|
29
|
+
attr_reader version: Gem::Version?
|
|
30
|
+
|
|
31
|
+
def self.rule_name: () -> Symbol
|
|
32
|
+
def initialize: (Gem::Version? version) -> void
|
|
33
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecViolation]
|
|
34
|
+
def version_before?: (String boundary) -> bool
|
|
35
|
+
def version_at_least?: (String boundary) -> bool
|
|
36
|
+
private def violation: (path: String, message: String) -> SpecViolation
|
|
37
|
+
private def each_schema: (untyped root) ?{ (untyped) -> void } -> untyped
|
|
38
|
+
private def walk: (untyped node, Hash[Integer, bool] visited) { (untyped) -> void } -> void
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
module Rules
|
|
42
|
+
class ExclusiveMinimum < Rule
|
|
43
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
class ExclusiveMaximum < Rule
|
|
47
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
class ContentEncodingIn30 < Rule
|
|
51
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
class ContentMediaTypeIn30 < Rule
|
|
55
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
class PrefixItemsIn30 < Rule
|
|
59
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
class JsonSchemaDialectIn30 < Rule
|
|
63
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
class TypeArrayIn30 < Rule
|
|
67
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
class PathItemsIn30 < Rule
|
|
71
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
class NullableDeprecation < Rule
|
|
75
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
class ExampleSingularDeprecation < Rule
|
|
79
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
class TypeNullIn30 < Rule
|
|
83
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
class WebhooksIn30 < Rule
|
|
87
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
class ConstIn30 < Rule
|
|
91
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
class DynamicRefIn30 < Rule
|
|
95
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
class DynamicAnchorIn30 < Rule
|
|
99
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
class ContentSchemaIn30 < Rule
|
|
103
|
+
def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
|
|
104
|
+
end
|
|
105
|
+
end
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
SpecViolation: singleton(SpecValidator::SpecViolation)
|
|
109
|
+
end
|
data/sig/openapi_parser.rbs
CHANGED
|
@@ -14,6 +14,8 @@ module OpenAPIParser
|
|
|
14
14
|
module Schemas
|
|
15
15
|
class OpenAPI
|
|
16
16
|
def initialize: (Hash[bot, bot] hash, untyped config, uri: OpenAPIParser::readable_uri?, schema_registry: Hash[bot, bot]) -> OpenAPIParser::Schemas::OpenAPI
|
|
17
|
+
def openapi: () -> String?
|
|
18
|
+
def openapi_version: () -> Gem::Version?
|
|
17
19
|
end
|
|
18
20
|
end
|
|
19
21
|
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: openapi_parser
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.4.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- ota42y
|
|
@@ -188,6 +188,7 @@ files:
|
|
|
188
188
|
- lib/openapi_parser/schema_validator/options.rb
|
|
189
189
|
- lib/openapi_parser/schema_validator/properties_number.rb
|
|
190
190
|
- lib/openapi_parser/schema_validator/string_validator.rb
|
|
191
|
+
- lib/openapi_parser/schema_validator/type_mismatch_validator.rb
|
|
191
192
|
- lib/openapi_parser/schema_validator/unspecified_type_validator.rb
|
|
192
193
|
- lib/openapi_parser/schemas.rb
|
|
193
194
|
- lib/openapi_parser/schemas/base.rb
|
|
@@ -207,6 +208,25 @@ files:
|
|
|
207
208
|
- lib/openapi_parser/schemas/response.rb
|
|
208
209
|
- lib/openapi_parser/schemas/responses.rb
|
|
209
210
|
- lib/openapi_parser/schemas/schema.rb
|
|
211
|
+
- lib/openapi_parser/spec_validator.rb
|
|
212
|
+
- lib/openapi_parser/spec_validator/rule.rb
|
|
213
|
+
- lib/openapi_parser/spec_validator/rules/const_in_30.rb
|
|
214
|
+
- lib/openapi_parser/spec_validator/rules/content_encoding_in_30.rb
|
|
215
|
+
- lib/openapi_parser/spec_validator/rules/content_media_type_in_30.rb
|
|
216
|
+
- lib/openapi_parser/spec_validator/rules/content_schema_in_30.rb
|
|
217
|
+
- lib/openapi_parser/spec_validator/rules/dynamic_anchor_in_30.rb
|
|
218
|
+
- lib/openapi_parser/spec_validator/rules/dynamic_ref_in_30.rb
|
|
219
|
+
- lib/openapi_parser/spec_validator/rules/example_singular_deprecation.rb
|
|
220
|
+
- lib/openapi_parser/spec_validator/rules/exclusive_maximum.rb
|
|
221
|
+
- lib/openapi_parser/spec_validator/rules/exclusive_minimum.rb
|
|
222
|
+
- lib/openapi_parser/spec_validator/rules/json_schema_dialect_in_30.rb
|
|
223
|
+
- lib/openapi_parser/spec_validator/rules/nullable_deprecation.rb
|
|
224
|
+
- lib/openapi_parser/spec_validator/rules/path_items_in_30.rb
|
|
225
|
+
- lib/openapi_parser/spec_validator/rules/prefix_items_in_30.rb
|
|
226
|
+
- lib/openapi_parser/spec_validator/rules/type_array_in_30.rb
|
|
227
|
+
- lib/openapi_parser/spec_validator/rules/type_null_in_30.rb
|
|
228
|
+
- lib/openapi_parser/spec_validator/rules/webhooks_in_30.rb
|
|
229
|
+
- lib/openapi_parser/spec_validator/spec_violation.rb
|
|
210
230
|
- lib/openapi_parser/version.rb
|
|
211
231
|
- openapi_parser.gemspec
|
|
212
232
|
- sig/openapi_parser.rbs
|
|
@@ -217,6 +237,7 @@ files:
|
|
|
217
237
|
- sig/openapi_parser/schema_validators/base.rbs
|
|
218
238
|
- sig/openapi_parser/schema_validators/options.rbs
|
|
219
239
|
- sig/openapi_parser/schemas/base.rbs
|
|
240
|
+
- sig/openapi_parser/spec_validator.rbs
|
|
220
241
|
- sig/openapi_parser/version.rbs
|
|
221
242
|
- sig/types.rbs
|
|
222
243
|
- sig/wip_types.rbs
|
|
@@ -238,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
238
259
|
- !ruby/object:Gem::Version
|
|
239
260
|
version: '0'
|
|
240
261
|
requirements: []
|
|
241
|
-
rubygems_version:
|
|
262
|
+
rubygems_version: 4.0.3
|
|
242
263
|
specification_version: 4
|
|
243
264
|
summary: OpenAPI3 parser
|
|
244
265
|
test_files: []
|