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

- old
+ new

@@ -8,11 +8,11 @@ ].freeze supports_children def self.allowed_options - super + ATTRIBUTES + %i[additional_items reject filter] + super + ATTRIBUTES + %i[additional_items reject filter parse_json] end def self.dsl_methods super + NodeRegistry.dsl_methods(false) + %i[dsl_add dsl_list dsl_cont] end @@ -71,17 +71,25 @@ return process_json(ATTRIBUTES, json) end def allowed_types - { Array => :array } + if options[:parse_json] + { Array => :array, String => :array } + else + { Array => :array } + end end def _validate(data, result:) super_data = super return if super_data.nil? + # Handle JSON + super_data = parse_if_json(super_data, result: result, allowed_types: { Array => :array }) + return if super_data.nil? + # Preprocess super_data = preprocess_array(super_data) # Validate length length = super_data.size @@ -140,9 +148,11 @@ (@items + [@cont_item]).compact end def cast(value) return default unless value + + value = parse_if_json(value, allowed_types: { Array => :array }) result = [] value.each_with_index do |value_item, index| if cont_item.present? && item_matches?(cont_item, value_item)