Empty arrays of struct type error as invalid value
Open
Nobody has claimed this yet.
bug
help wanted
- Dominant language
- Ruby
- Stars
- 492
- Forks
- 123
- PR merge metrics
- No merged PRs in 30d
Description
When an array of type struct is defined for a schema and an empty array is specified, the empty array is reported as the wrong type. This is not the case for a basic type.
# incorrect w/ struct
Class.new(Dry::Validation::Contract) { params { required(:list).array(Dry.Struct(name: 'string')) } }.new.call(list: [])
=> #<Dry::Validation::Result{:list=>{}} errors={:list=>["must be an array"]}>
# correct w/o struct
Class.new(Dry::Validation::Contract) { params { required(:list).array(:string) } }.new.call(list: [])
=> #<Dry::Validation::Result{:list=>[]} errors={}>
I'm not quite sure why dry-schema thinks it's not an array being passed in.
- dry-schema 1.5.5
- dry-validation 1.5.6
- dry-struct 1.3.0
- dry-types 1.4.0
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the struct-array example from the issue and compare it with the basic-type array example. Trace the schema entry point created by required(:list).array(Dry.Struct(...)) to find why [] is reported as invalid, then verify that an empty struct array succeeds without errors while invalid element values remain rejected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- ruby
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100