openapi_parser 2.7.0 → 2.8.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6332e2e24a629533ff6ae7159cff7b51db53a2e451bd527743610122ed3bb994
4
- data.tar.gz: 88b477bdea9749ebe10b0bf7214529152cbed08e53290ea3657ca17e6d1970d6
3
+ metadata.gz: 692fe438d163494e486fd8f95df4346f1bc2bbc83fd1ecbfd751da1c946f41b4
4
+ data.tar.gz: cd650f7d43d6c3911a11e10387778199ec9ab09f563c978a1989839a11124693
5
5
  SHA512:
6
- metadata.gz: 69fb1000151935a4636ba3bd98edf9f1e1e221ebea86e4a3cf23348b7452ecf49e2047e9be42322713f438ed56855a20cf52647f0cc08077efc95631839d8e49
7
- data.tar.gz: 72287aa48edfe2dae9894006b2da9e90c14c5b552bb5cbc598bd166f931ab25e6283167c0b6afda3d7270761487edc83739f73686c3c9e739724049ac23f6d10
6
+ metadata.gz: 06be112cf0f5e793510d57dbf851a79375f9df3f6bb5f5dd7cba0e4ffd6ef3f0ee44dcb4d4be6487d3f4c9fb30da65ab3815f97278f1314ceb0327e260ba4899
7
+ data.tar.gz: f65c447ee885a7b758d01b7ee65409b12ee4f8b3090f7f1dfe75ae4d520fe843493c79f2af2588fef209590d744198d7f16dc165da0dd8077f4c58ac390a854a
data/CHANGELOG.md CHANGED
@@ -1,5 +1,16 @@
1
1
  ## Unreleased
2
2
 
3
+ ## 2.8.0 (2026-11-16)
4
+ * match an exact `additionalOperations` key before a standard method in 3.2 documents, so a `Get` request finds `additionalOperations.Get` rather than `get` ([OpenAPI 3.2](https://spec.openapis.org/oas/v3.2.0.html#path-item-object), [RFC 9110 §9.1](https://www.rfc-editor.org/rfc/rfc9110.html#section-9.1))
5
+ * check the keywords next to `$ref` in Schema Objects of OpenAPI 3.1 documents, such as `{ $ref: ..., maxLength: 3 }`. They were ignored before, so a value that passed may now fail. A Reference Object, and any object in a 3.0 document, still ignores them. Readers such as `Schema#type` still return the values of the referenced schema
6
+ * accept a value that matches exactly one `oneOf` member as it is when `coerce_value` is on, and keep it uncoerced. `"1"` for `oneOf: [integer, string]` failed with `NotOneOf` before, because coercion made it match both
7
+ * read strings as decimal numbers when `coerce_value` is on. For `type: integer`, `"010"` is now `10`, not octal `8`, and `"0x10"`, `"0b10"` and `"0o10"` are rejected. For `type: number`, hexadecimal such as `"0x10"` is rejected. This changes `"010"` from `8` to `10` without an error, so check any client that sends zero-padded integers (#251)
8
+ * support the `propertyNames` keyword (OpenAPI 3.1): every property name of an object is checked against its schema, and the first name that fails returns the error from that schema, such as `InvalidPattern` or `MoreThanMaxLength`. Names are checked as strings even when `coerce_value` is on. It was ignored before, so a value that passed may now fail
9
+ * add `SpecValidator` rule `PropertyNamesIn30`: detect `propertyNames` in 3.0 documents (3.1 addition)
10
+ * check `enum` on objects and arrays (OpenAPI 3.0 and 3.1). A value now has to equal one of the members, as in JSON Schema: objects are compared by keys and values, and arrays element by element in order. It was ignored before, so a value that passed may now fail. In particular, `enum` written next to `items`, such as `{ type: array, items: { type: string }, enum: [a, b] }`, now rejects every array. To limit the elements, move `enum` into `items`
11
+ * support the `patternProperties` keyword (OpenAPI 3.1): a property whose name matches a pattern is now checked against that pattern's schema, as well as its `properties` schema. Such a property is no longer an additional property, so `additionalProperties` does not apply to it. It was ignored before, so a value that passed may now fail, and a value that failed on `additionalProperties` may now pass
12
+ * add `SpecValidator` rule `PatternPropertiesIn30`: detect `patternProperties` in 3.0 documents (3.1 addition)
13
+
3
14
  ## 2.7.0 (2026-11-06)
4
15
  * match `additionalOperations` method names case-sensitively ([OpenAPI 3.2](https://spec.openapis.org/oas/v3.2.0.html#path-item-object), [RFC 9110 §9.1](https://www.rfc-editor.org/rfc/rfc9110.html#section-9.1)). Standard methods still match their fixed fields in any case
5
16
  * check the keywords next to `allOf`, `anyOf` and `oneOf` (OpenAPI 3.0 and 3.1), such as `{ allOf: [...], required: [a] }`, and all of these keywords when a schema has more than one. They were ignored before, so a value that passed may now fail. In particular, `additionalProperties: false` next to `allOf` now rejects the properties defined only in `allOf`, as in JSON Schema
data/README.md CHANGED
@@ -127,7 +127,7 @@ OpenAPIParser.parse(schema, strict_specification_version: :raise)
127
127
 
128
128
  Detected mismatches:
129
129
 
130
- - 3.1 additions in 3.0 documents: `const`, `prefixItems`, array-form `type`, `type: "null"`, `webhooks`, `jsonSchemaDialect`, `components.pathItems`, `$dynamicRef`, `$dynamicAnchor`, `contentEncoding`, `contentMediaType`, `contentSchema`, `$defs`, `dependentRequired`, boolean schemas
130
+ - 3.1 additions in 3.0 documents: `const`, `prefixItems`, array-form `type`, `type: "null"`, `webhooks`, `jsonSchemaDialect`, `components.pathItems`, `$dynamicRef`, `$dynamicAnchor`, `contentEncoding`, `contentMediaType`, `contentSchema`, `$defs`, `dependentRequired`, `propertyNames`, `patternProperties`, boolean schemas
131
131
  - the 3.0 Boolean vs 3.1 numeric forms of `exclusiveMinimum` / `exclusiveMaximum`
132
132
  - 3.2 additions in earlier documents: `$self`, the `query` operation, `additionalOperations`, `components.mediaTypes`, Tag `summary` / `parent` / `kind`, Server `name`, Example `dataValue` / `serializedValue`, XML `nodeType`, Security Scheme `deprecated` / `oauth2MetadataUrl` and the `deviceAuthorization` flow, Media Type and Encoding `itemSchema` / `itemEncoding` / `prefixEncoding`, Discriminator `defaultMapping`, Parameter `in: querystring` and `style: cookie`, Response `summary`
133
133
  - keywords removed or deprecated by the declared version: `nullable` and singular schema `example` in 3.1+, XML `attribute: true` / `wrapped: true` and Parameter `allowEmptyValue` in 3.2
@@ -1,5 +1,8 @@
1
1
  # loader base class for create OpenAPI::Schemas::Base object
2
2
  class OpenAPIParser::SchemaLoader::Creator < OpenAPIParser::SchemaLoader::Base
3
+ # these do not change validation, so a `$ref` with only these stays a Reference
4
+ REF_ANNOTATIONS = %w[$ref $comment title description summary deprecated default example examples readOnly writeOnly].freeze
5
+
3
6
  # @param [String] variable_name
4
7
  # @param [Hash] options
5
8
  def initialize(variable_name, options)
@@ -35,6 +38,15 @@ class OpenAPIParser::SchemaLoader::Creator < OpenAPIParser::SchemaLoader::Base
35
38
  check_schema.kind_of?(::Hash)
36
39
  end
37
40
 
41
+ # 3.1: a Schema Object applies the keywords next to `$ref`. A Reference Object,
42
+ # and any object in 3.0, ignores them.
43
+ def reference_class(target_object, schema)
44
+ return OpenAPIParser::Schemas::Reference unless @klass == OpenAPIParser::Schemas::Schema && target_object.root.use_3_1_features?
45
+ return OpenAPIParser::Schemas::Reference unless schema.keys.any? { |key| !REF_ANNOTATIONS.include?(key) && !key.start_with?('x-') }
46
+
47
+ OpenAPIParser::Schemas::SchemaWithRef
48
+ end
49
+
38
50
  def escape_reference(str)
39
51
  str.to_s.gsub('~', '~0').gsub('/', '~1')
40
52
  end
@@ -45,7 +57,7 @@ class OpenAPIParser::SchemaLoader::Creator < OpenAPIParser::SchemaLoader::Base
45
57
  if @allow_data_type && !check_object_schema?(schema)
46
58
  schema
47
59
  elsif allow_reference?(target_object) && check_reference_schema?(schema)
48
- OpenAPIParser::Schemas::Reference.new(ref, target_object, target_object.root, schema)
60
+ reference_class(target_object, schema).new(ref, target_object, target_object.root, schema)
49
61
  else
50
62
  @klass.new(ref, target_object, target_object.root, schema)
51
63
  end
@@ -30,6 +30,8 @@ class OpenAPIParser::SchemaValidator
30
30
  schema.all_of.each do |s|
31
31
  if s.type == "object"
32
32
  remaining_keys -= (s.properties || {}).keys
33
+ patterns = (s.pattern_properties || {}).keys
34
+ remaining_keys = remaining_keys.reject { |key| patterns.any? { |pattern| key =~ /#{pattern}/ } }
33
35
  nested_additional_properties = true if s.additional_properties
34
36
  else
35
37
  # If this is not allOf having array of objects inside, but e.g. having another anyOf/oneOf nested
@@ -1,5 +1,7 @@
1
1
  class OpenAPIParser::SchemaValidator
2
2
  class ArrayValidator < Base
3
+ include ::OpenAPIParser::SchemaValidator::Enumable
4
+
3
5
  # @param [Array] value
4
6
  # @param [OpenAPIParser::Schemas::Schema] schema
5
7
  def coerce_and_validate(value, schema, **_keyword_args)
@@ -26,7 +28,7 @@ class OpenAPIParser::SchemaValidator
26
28
 
27
29
  value.each_index { |idx| value[idx] = coerced_values[idx] } if @coerce_value
28
30
 
29
- [value, nil]
31
+ check_enum_include(value, schema)
30
32
  end
31
33
 
32
34
  def validate_max_min_items(value, schema)
@@ -4,6 +4,9 @@ class OpenAPIParser::SchemaValidator
4
4
  include ::OpenAPIParser::SchemaValidator::MinimumMaximum
5
5
  include ::OpenAPIParser::SchemaValidator::MultipleOf
6
6
 
7
+ # Float() has no base argument and reads hexadecimal such as "0x10" and "0x1p3".
8
+ HEXADECIMAL = /\A\s*[+-]?0x/i.freeze
9
+
7
10
  # validate float value by schema
8
11
  # @param [Object] value
9
12
  # @param [OpenAPIParser::Schemas::Schema] schema
@@ -30,6 +33,8 @@ class OpenAPIParser::SchemaValidator
30
33
  end
31
34
 
32
35
  def coerce(value)
36
+ return value if value.kind_of?(String) && value.match?(HEXADECIMAL)
37
+
33
38
  Float(value)
34
39
  rescue ArgumentError, TypeError
35
40
  value
@@ -41,7 +41,8 @@ class OpenAPIParser::SchemaValidator
41
41
  return value.finite? && value == value.floor ? value.to_i : value if value.kind_of?(Float)
42
42
 
43
43
  begin
44
- Integer(value)
44
+ # Base 10, so "010" is 10 rather than octal 8, and 0x, 0b and 0o are rejected.
45
+ Integer(value, 10)
45
46
  rescue ArgumentError, TypeError
46
47
  value
47
48
  end
@@ -1,5 +1,6 @@
1
1
  class OpenAPIParser::SchemaValidator
2
2
  class ObjectValidator < Base
3
+ include ::OpenAPIParser::SchemaValidator::Enumable
3
4
  include ::OpenAPIParser::SchemaValidator::PropertiesNumber
4
5
 
5
6
  # @param [Hash] value
@@ -10,6 +11,7 @@ class OpenAPIParser::SchemaValidator
10
11
  return OpenAPIParser::ValidateError.build_error_result(value, schema) unless value.kind_of?(Hash)
11
12
 
12
13
  properties = schema.properties || {}
14
+ pattern_properties = schema.pattern_properties || {}
13
15
  additional_properties = schema.additional_properties
14
16
 
15
17
  required_set = schema.required ? schema.required.to_set : Set.new
@@ -25,11 +27,14 @@ class OpenAPIParser::SchemaValidator
25
27
  remaining_keys.delete('discriminator')
26
28
  end
27
29
 
30
+ property_names_error = check_property_names(value, schema)
31
+ return [nil, property_names_error] if property_names_error
32
+
28
33
  coerced_values = value.map do |name, v|
29
- s = properties[name]
30
- coerced, err = if s
34
+ property_schemas = [properties[name], *matching_pattern_schemas(name, pattern_properties)].compact
35
+ coerced, err = if !property_schemas.empty?
31
36
  remaining_keys.delete(name)
32
- validatable.validate_schema(v, s)
37
+ validate_property(v, property_schemas)
33
38
  # TODO: better handling for parent_all_of with additional_properties
34
39
  elsif !parent_all_of && additional_properties.is_a?(OpenAPIParser::Schemas::Schema)
35
40
  remaining_keys.delete(name)
@@ -58,11 +63,44 @@ class OpenAPIParser::SchemaValidator
58
63
 
59
64
  value.merge!(coerced_values.to_h) if @coerce_value
60
65
 
66
+ value, err = check_enum_include(value, schema)
67
+ return [nil, err] if err
68
+
61
69
  check_properties_number(value, schema)
62
70
  end
63
71
 
64
72
  private
65
73
 
74
+ # Property names are always strings, so they are checked without coercion.
75
+ # A name like "5" does not become 5 for `propertyNames: { type: integer }`.
76
+ # @return [OpenAPIParser::OpenAPIError, nil]
77
+ def check_property_names(value, schema)
78
+ property_names = schema.property_names
79
+ return unless property_names
80
+
81
+ validator = OpenAPIParser::SchemaValidator.new(nil, property_names, OpenAPIParser::SchemaValidator::Options.new)
82
+ value.each_key do |name|
83
+ _, err = validator.validate_schema(name, property_names)
84
+ return err if err
85
+ end
86
+ nil
87
+ end
88
+
89
+ # @param [String] name
90
+ # @param [Hash{String => OpenAPIParser::Schemas::Schema}] pattern_properties
91
+ # @return [Array<OpenAPIParser::Schemas::Schema>] the schemas whose pattern matches the name
92
+ def matching_pattern_schemas(name, pattern_properties)
93
+ # Same regular expression handling as the pattern keyword (StringValidator#pattern_validate)
94
+ pattern_properties.select { |pattern, _| name =~ /#{pattern}/ }.values
95
+ end
96
+
97
+ # Check the value against each schema in turn, passing on the coerced value.
98
+ # @return [Array] coerced value and error
99
+ def validate_property(value, schemas)
100
+ steps = schemas.map { |s| ->(current) { validatable.validate_schema(current, s) } }
101
+ validatable.validate_in_order(value, steps)
102
+ end
103
+
66
104
  # @return [OpenAPIParser::NotExistDependentRequiredKey, nil]
67
105
  def check_dependent_required(value, schema)
68
106
  dependent_required = schema.dependent_required
@@ -10,6 +10,14 @@ class OpenAPIParser::SchemaValidator
10
10
  return validate_discriminator_schema(schema.discriminator, value, candidate_schemas: schema.one_of)
11
11
  end
12
12
 
13
+ # A value that matches a member as it is does not need coercion. Coercion
14
+ # could make it match other members too, like "1" for [integer, string].
15
+ if @coerce_value
16
+ literal_matches = schema.one_of.select { |s| validatable.valid_without_coercion?(value, s) }
17
+ return validatable.validate_schema(value, literal_matches.first) if literal_matches.one?
18
+ return [nil, OpenAPIParser::NotOneOf.new(value, schema.object_reference)] if literal_matches.size > 1
19
+ end
20
+
13
21
  # if multiple schemas are satisfied, it's not valid
14
22
  matched = schema.one_of.map { |s| validatable.validate_schema(value, s) }.select { |_coerced, err| err.nil? }
15
23
  if matched.one?
@@ -80,6 +80,7 @@ class OpenAPIParser::SchemaValidator
80
80
  # @param [OpenAPIParser::Schemas::Schema] schema
81
81
  def validate_schema(value, schema, **keyword_args)
82
82
  return [value, nil] unless schema
83
+ return validate_schema_with_ref(value, schema, **keyword_args) if schema.is_a?(OpenAPIParser::Schemas::SchemaWithRef)
83
84
 
84
85
  # 3.1: a boolean schema accepts (`true`) or rejects (`false`) any value,
85
86
  # including null.
@@ -114,6 +115,15 @@ class OpenAPIParser::SchemaValidator
114
115
  integer_validator.coerce_and_validate(value, schema)
115
116
  end
116
117
 
118
+ # @param [Object] value
119
+ # @param [OpenAPIParser::Schemas::Schema] schema
120
+ # @return [Boolean] whether the value is valid as it is, without coerce_value
121
+ def valid_without_coercion?(value, schema)
122
+ @validator_without_coercion ||= self.class.new(value, schema, Options.new(allow_empty_date_and_datetime: @allow_empty_date_and_datetime))
123
+ _value, err = @validator_without_coercion.validate_schema(value, schema)
124
+ err.nil?
125
+ end
126
+
117
127
  # Run the steps in order, each with the value coerced by the steps before it.
118
128
  # Keywords check JSON values. A coerced value of another class, like DateTime,
119
129
  # is only the output form, so the later steps check the original value.
@@ -137,6 +147,19 @@ class OpenAPIParser::SchemaValidator
137
147
  JSON_VALUE_CLASSES.any? { |klass| value.is_a?(klass) }
138
148
  end
139
149
 
150
+ # `$ref` and the keywords next to it both apply. The one with `type` goes first,
151
+ # so that the other sees the coerced value.
152
+ # @return [Array] coerced value and error
153
+ def validate_schema_with_ref(value, schema, **keyword_args)
154
+ target = schema.ref_target
155
+ return validate_schema(value, schema.ref_siblings, **keyword_args) unless target.is_a?(OpenAPIParser::Schemas::Schema)
156
+
157
+ steps = [target, schema.ref_siblings].partition(&:type).flatten.map do |s|
158
+ ->(input) { validate_schema(input, s, **keyword_args) }
159
+ end
160
+ validate_in_order(value, steps)
161
+ end
162
+
140
163
  # @return [Array<OpenAPIParser::SchemaValidator::Base>]
141
164
  def composition_validators(schema)
142
165
  validators = []
@@ -23,14 +23,16 @@ module OpenAPIParser::Schemas
23
23
  return PRE_3_2_METHODS.include?(method.to_s) ? public_send(method.to_s) : nil
24
24
  end
25
25
 
26
- method_name = method.to_s.downcase
27
- return public_send(method_name) if STANDARD_METHODS.include?(method_name)
26
+ # an exact additionalOperations key wins, so `Get` isn't routed to `get`
27
+ additional = additional_operation(method.to_s)
28
+ return additional if additional
28
29
 
29
- additional_operation(method.to_s)
30
+ method_name = method.to_s.downcase
31
+ STANDARD_METHODS.include?(method_name) ? public_send(method_name) : nil
30
32
  end
31
33
 
32
34
  def set_path_item_to_operation
33
- STANDARD_METHODS.each { |method| operation(method)&.set_parent_path_item(self) }
35
+ STANDARD_METHODS.each { |method| public_send(method)&.set_parent_path_item(self) }
34
36
  additional_operations&.each_value { |op| op.set_parent_path_item(self) }
35
37
  end
36
38
 
@@ -103,6 +103,10 @@ module OpenAPIParser::Schemas
103
103
  # @return [Schema, nil]
104
104
  openapi_attr_object :not, Schema, reference: true
105
105
 
106
+ # @!attribute [r] property_names
107
+ # @return [Schema, nil]
108
+ openapi_attr_object :property_names, Schema, reference: true, schema_key: :propertyNames
109
+
106
110
  # @!attribute [r] items
107
111
  # @return [Schema, nil]
108
112
  openapi_attr_object :items, Schema, reference: true
@@ -119,6 +123,10 @@ module OpenAPIParser::Schemas
119
123
  # @return [Hash{String => Schema}, nil]
120
124
  openapi_attr_hash_object :properties, Schema, reference: true
121
125
 
126
+ # @!attribute [r] pattern_properties
127
+ # @return [Hash{String => Schema}, nil] schemas for properties whose names match the regular expression keys (OpenAPI 3.1+)
128
+ openapi_attr_hash_object :pattern_properties, Schema, reference: true, schema_key: :patternProperties
129
+
122
130
  # @!attribute [r] defs
123
131
  # @return [Hash{String => Schema}, nil] reusable schemas for `$ref` (OpenAPI 3.1+)
124
132
  openapi_attr_hash_object :defs, Schema, reference: true, schema_key: :$defs
@@ -0,0 +1,39 @@
1
+ module OpenAPIParser::Schemas
2
+ # A Schema Object with `$ref` and other keywords next to it (OpenAPI 3.1).
3
+ #
4
+ # The referenced schema is shared, so the keywords cannot be merged into it.
5
+ # The `$ref` is the base of this schema, so readers see the referenced schema,
6
+ # as they do with a plain `$ref`. The validator checks both schemas.
7
+ class SchemaWithRef < Schema
8
+ # @return [Schema, Reference] Reference only when it cannot be resolved
9
+ attr_reader :ref_target
10
+
11
+ # @return [Schema] the keywords next to `$ref`
12
+ attr_reader :ref_siblings
13
+
14
+ (Schema.public_instance_methods(false) - [:load_data]).each do |name|
15
+ define_method(name) do
16
+ ref_target.public_send(name) if ref_target.respond_to?(name)
17
+ end
18
+ end
19
+
20
+ def load_data
21
+ siblings = raw_schema.reject { |key, _| key == '$ref' }
22
+ @raw_schema = raw_schema.slice('$ref')
23
+ @ref_target = Reference.new("#{object_reference}/$ref", self, root, raw_schema)
24
+ @ref_siblings = Schema.new(object_reference, self, root, siblings)
25
+ @_openapi_all_child_objects = { @ref_target.object_reference => @ref_target, "#{object_reference}/siblings" => @ref_siblings }
26
+ nil
27
+ end
28
+
29
+ def expand_reference(root, validate_references)
30
+ new_object = expand_object(root, @ref_target, validate_references)
31
+ if new_object
32
+ _update_child_object(@ref_target, new_object)
33
+ @ref_target = new_object
34
+ end
35
+ @ref_siblings.expand_reference(root, validate_references)
36
+ nil
37
+ end
38
+ end
39
+ end
@@ -14,5 +14,6 @@ require_relative 'schemas/responses'
14
14
  require_relative 'schemas/components'
15
15
  require_relative 'schemas/media_type'
16
16
  require_relative 'schemas/schema'
17
+ require_relative 'schemas/schema_with_ref'
17
18
  require_relative 'schemas/header'
18
19
  require_relative 'schemas/info'
@@ -0,0 +1,25 @@
1
+ module OpenAPIParser
2
+ class SpecValidator
3
+ module Rules
4
+ # `patternProperties` is a JSON Schema 2020-12 keyword that 3.1 adopted.
5
+ # 3.0 Schema Objects do not define it. The validator checks it regardless
6
+ # of version; this rule reports the version mismatch.
7
+ class PatternPropertiesIn30 < 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?('patternProperties')
14
+
15
+ violations << violation(
16
+ path: schema.object_reference,
17
+ message: '`patternProperties` is a 3.1 addition (from JSON Schema 2020-12); 3.0 Schema Objects do not define it',
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
+ # `propertyNames` is a JSON Schema 2020-12 keyword that 3.1 adopted.
5
+ # 3.0 Schema Objects do not define it. The validator checks it regardless
6
+ # of version; this rule reports the version mismatch.
7
+ class PropertyNamesIn30 < 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?('propertyNames')
14
+
15
+ violations << violation(
16
+ path: schema.object_reference,
17
+ message: '`propertyNames` is a 3.1 addition (from JSON Schema 2020-12); 3.0 Schema Objects do not define it',
18
+ )
19
+ end
20
+ violations
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -19,6 +19,8 @@ require_relative 'spec_validator/rules/dynamic_anchor_in_30'
19
19
  require_relative 'spec_validator/rules/content_schema_in_30'
20
20
  require_relative 'spec_validator/rules/defs_in_30'
21
21
  require_relative 'spec_validator/rules/dependent_required_in_30'
22
+ require_relative 'spec_validator/rules/property_names_in_30'
23
+ require_relative 'spec_validator/rules/pattern_properties_in_30'
22
24
  require_relative 'spec_validator/rules/allow_empty_value_deprecation'
23
25
  require_relative 'spec_validator/rules/xml_node_type_before_32'
24
26
  require_relative 'spec_validator/rules/xml_attribute_deprecation'
@@ -102,6 +104,8 @@ module OpenAPIParser
102
104
  Rules::ContentSchemaIn30,
103
105
  Rules::DefsIn30,
104
106
  Rules::DependentRequiredIn30,
107
+ Rules::PropertyNamesIn30,
108
+ Rules::PatternPropertiesIn30,
105
109
  Rules::AllowEmptyValueDeprecation,
106
110
  Rules::XmlNodeTypeBefore32,
107
111
  Rules::XmlAttributeDeprecation,
@@ -1,3 +1,3 @@
1
1
  module OpenAPIParser
2
- VERSION = '2.7.0'.freeze
2
+ VERSION = '2.8.0'.freeze
3
3
  end
@@ -25,6 +25,7 @@ module OpenAPIParser
25
25
  def validate_data: -> Object
26
26
  def validate_schema: (Object value, OpenAPIParser::Schemas::Schema schema, **bot) -> [Object, OpenAPIParser::validate_error]
27
27
  def validate_integer: (Object value, OpenAPIParser::Schemas::Schema schema) -> [Object, OpenAPIParser::validate_error]
28
+ def valid_without_coercion?: (Object value, OpenAPIParser::Schemas::Schema schema) -> bool
28
29
  def validate_in_order: (Object value, Array[untyped] steps) -> [Object, OpenAPIParser::validate_error]
29
30
 
30
31
  private
@@ -118,6 +118,14 @@ module OpenAPIParser
118
118
  def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
119
119
  end
120
120
 
121
+ class PropertyNamesIn30 < Rule
122
+ def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
123
+ end
124
+
125
+ class PatternPropertiesIn30 < Rule
126
+ def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
127
+ end
128
+
121
129
  class AllowEmptyValueDeprecation < Rule
122
130
  def check: (OpenAPIParser::Schemas::OpenAPI root) -> Array[SpecValidator::SpecViolation]
123
131
  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.7.0
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ota42y
@@ -209,6 +209,7 @@ files:
209
209
  - lib/openapi_parser/schemas/response.rb
210
210
  - lib/openapi_parser/schemas/responses.rb
211
211
  - lib/openapi_parser/schemas/schema.rb
212
+ - lib/openapi_parser/schemas/schema_with_ref.rb
212
213
  - lib/openapi_parser/spec_validator.rb
213
214
  - lib/openapi_parser/spec_validator/rule.rb
214
215
  - lib/openapi_parser/spec_validator/rules/additional_operations_before_32.rb
@@ -232,7 +233,9 @@ files:
232
233
  - lib/openapi_parser/spec_validator/rules/media_types_before_32.rb
233
234
  - lib/openapi_parser/spec_validator/rules/nullable_deprecation.rb
234
235
  - lib/openapi_parser/spec_validator/rules/path_items_in_30.rb
236
+ - lib/openapi_parser/spec_validator/rules/pattern_properties_in_30.rb
235
237
  - lib/openapi_parser/spec_validator/rules/prefix_items_in_30.rb
238
+ - lib/openapi_parser/spec_validator/rules/property_names_in_30.rb
236
239
  - lib/openapi_parser/spec_validator/rules/query_method_before_32.rb
237
240
  - lib/openapi_parser/spec_validator/rules/querystring_before_32.rb
238
241
  - lib/openapi_parser/spec_validator/rules/response_summary_before_32.rb