lib/schemacop/v3/hash_node.rb in schemacop-3.0.28 vs lib/schemacop/v3/hash_node.rb in schemacop-3.0.29

- old
+ new

@@ -12,11 +12,11 @@ supports_children(name: true) attr_reader :properties def self.allowed_options - super + ATTRIBUTES - %i[dependencies] + %i[additional_properties ignore_obsolete_properties] + super + ATTRIBUTES - %i[dependencies] + %i[additional_properties ignore_obsolete_properties parse_json] end def self.dsl_methods super + NodeRegistry.dsl_methods(true) + %i[dsl_dep dsl_add] end @@ -76,17 +76,25 @@ return process_json(ATTRIBUTES, json) end def allowed_types - { Hash => :object } + if options[:parse_json] + { Hash => :object, String => :string } + else + { Hash => :object } + end end def _validate(data, result: Result.new) super_data = super return if super_data.nil? + # Handle JSON + super_data = parse_if_json(super_data, result: result, allowed_types: { Hash => :object }) + return if super_data.nil? + original_data_hash = super_data.dup data_hash = super_data.with_indifferent_access if original_data_hash.size != data_hash.size ambiguous_properties = original_data_hash.keys - data_hash.keys @@ -167,9 +175,10 @@ def children @properties.values end def cast(data) + data = parse_if_json(data, allowed_types: { Hash => :object }) result = {}.with_indifferent_access data ||= default return nil if data.nil? data_hash = data.dup.with_indifferent_access