Allow :any on a nested subtree

For my use case, I need to enable Dry::Schema.config.validate_keys = true to report any key typos and extra keys. This seems to work fine, except for one issue. I have a certain key that should allow an arbitrary nested structure within it, but :any unexpectedly seems to trigger validation errors if the structure is anything other than a primitive or a 1d array.

Here’s a minimal example of the problematic behavior:

require 'dry/schema'

Dry::Schema.config.validate_keys = true  # must keep

AnyKeySchema = Dry::Schema.Params do
  # I also tried this to opt out of validation locally
  # for this node, it seems to have no effect
  config.validate_keys = false 

  required(:any_type).filled(:any)
end

TestSchema = Dry::Schema.Params do
  required(:any_key).filled(AnyKeySchema)
end

config = {
  # these work OK:
  # 'any_key' => {'any_type' => [1, 2, 3]},
  # 'any_key' => {'any_type' => 41},
  # 'any_key' => {'any_type' => 'str'},

  # these fail:
  'any_key' => {'any_type' => [[1, 2, 3]]} 
  # {'any_type' => {'foo': 42}}
}

result = TestSchema.call(config)
p result.success?
p result.errors.to_h

Output:

false
{:any_key=>{:any_type=>{0=>{1=>["is not allowed"], 2=>["is not allowed"], 3=>["is not allowed"]}}}}

I’m expecting:

true
{}

I’m comfortable using config.validate_keys = false to locally disable all validation for the node in question, but this seems to have no effect.

To be clear, this type needs to support literally anything: plain strings, integers, booleans, arrays, hashes with any subtree structure (2d arrays, hashes of arrays, hashes of hashes, 33d arrays, etc).

How can I create a genuine “any” type that disregards all validation recursively on its entire subtree?

I forgot to mention: the above question is respective of dry-schema 1.10.6.

json-schema seems to suffice as a workaround, so I suppose I’ll need to switch to that for the time being:

require 'json-schema' # 3.0.0

any_key_schema = {
  'type' => 'object',
  'additionalProperties' => false,
  'required' => ['any_type'],
  'properties' => {
    'any_type' => {
      'type' => 'any'
    }
  }
}
  
test_schema = {
  'type' => 'object',
  'required' => ['any_key'],
  'additionalProperties' => false,
  'properties' => {
    'any_key' => any_key_schema
  }
}

config = {'any_key' => {'any_type' => {'foo' => [[[[[42]]]]]}}}
p JSON::Validator.fully_validate(test_schema, config) # => [] as expected