I’m working with dry-schema
and nested attributes, and was wondering about the intended behaviour when generating full messages.
Currently, it seems like only the leaf attribute name is included in the message.
schema = Dry::Schema.JSON do
required(:capacity).hash do
required(:min).filled(:integer)
required(:max).filled(:integer)
end
required(:duration).hash do
required(:min).filled(:integer)
required(:max).filled(:integer)
end
end
schema.call(capacity: { min: 10 }, duration: {}).errors(full: true).messages
=> [
#<Dry::Schema::Message text="max is missing" path=[:capacity, :max] predicate=:key? input={:min=>10}>,
#<Dry::Schema::Message text="min is missing" path=[:duration, :min] predicate=:key? input={}>,
#<Dry::Schema::Message text="max is missing" path=[:duration, :max] predicate=:key? input={}>
]
In my use, it would make sense for the whole path to be indicated when generating full
messages, e.g. "capacity.max is missing"
.
I can of course work around it by using non-full
messages, and instead build them myself using path.join(".")
etc. But if this is not the intended behaviour, I could file it as a bug on GitHub.