How to use validate with a nested value?

I’m building an API following the JSON API spec and primarily want to validate the values that exist under data/attributes, for example:

data: {
  type: 'examples',
  attributes: {
    foo: 'foobar',
    bar: 'barfoo'
  }
}

How do I reference data/attributes/foo when using validate? I’ve tried the following forms

validate(custom_validation: [%i(data attributes foo)]) do |foo| ... end
validate(custom_validation: %i(data attributes foo)) do |foo| ... end
validate(custom_validation: { data: { attributes: :foo } }) do |foo| ... end

The validation I’m doing uses externally provided data schema.with(extra_data: ...).call(params) and validate has been the only way I’ve found lets me use that extra data in my validations.

Found my solution but was stumped by a possible bug in dry-validation. I shouldn’t be adding the call to validate at the root of the schema. I should put it down into the nested schema where the property is that I want to validate is.

This works:

required(:data).schema do
  required(:attributes).schema do
    required(:foo).filled
    
    validate(valid_foo?: [:foo]) do |value|
      # have access to :foo here
      # errors will populate as { data: { attributes: { foo: [...] } } }
    end
  end
end

Nested values should work when you use a path (using an array of symbols) so please report an issue about this and I’ll fix it in the next release.