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.