lib/schemacop/v3/hash_node.rb in schemacop-3.0.17 vs lib/schemacop/v3/hash_node.rb in schemacop-3.0.18
- old
+ new
@@ -12,11 +12,11 @@
supports_children(name: true)
attr_reader :properties
def self.allowed_options
- super + ATTRIBUTES - %i[dependencies] + %i[additional_properties]
+ super + ATTRIBUTES - %i[dependencies] + %i[additional_properties ignore_obsolete_properties]
end
def self.dsl_methods
super + NodeRegistry.dsl_methods(true) + %i[dsl_dep dsl_add]
end
@@ -139,11 +139,11 @@
match = property_patterns.keys.find { |p| p.match?(name.to_s) }
if match
result.in_path(name) do
property_patterns[match]._validate(additional_property, result: result)
end
- else
+ elsif !options[:ignore_obsolete_properties]
result.error "Obsolete property #{name.to_s.inspect}."
end
elsif options[:additional_properties].is_a?(Node)
result.in_path(name) do
options[:additional_properties]._validate(additional_property, result: result)
@@ -233,12 +233,22 @@
@options[:type] = :object
unless @options[:additional_properties].nil? || @options[:additional_properties].is_a?(TrueClass) || @options[:additional_properties].is_a?(FalseClass)
fail Schemacop::Exceptions::InvalidSchemaError, 'Option "additional_properties" must be a boolean value'
end
+ # Cannot set additional_properties and ignore_obsolete_properties option to true at the same time
+ if @options[:additional_properties].is_a?(TrueClass) && options[:ignore_obsolete_properties].is_a?(TrueClass)
+ fail Schemacop::Exceptions::InvalidSchemaError, 'Cannot set "additional_properties" and "ignore_obsolete_properties" to true at the same time'
+ end
+
# Default the additional_properties option to false if it's not given
if @options[:additional_properties].nil?
@options[:additional_properties] = false
+ end
+
+ # Default the ignore_obsolete_properties option to false if it's not given
+ if @options[:ignore_obsolete_properties].nil?
+ @options[:ignore_obsolete_properties] = false
end
end
def validate_self
unless options[:min_properties].nil? || options[:min_properties].is_a?(Integer)