hapijs / hapijs/joi

At least one of arrays nodes must be filled

Open
#2,694 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
21.2k
Forks
1.5k
Avg merge
4h 57m
Merged PRs (30d)
14

Description

#### Support plan

* *is this issue currently blocking your project?* (yes/no): NO
* *is this issue affecting a production system?* (yes/no): NO

#### Context

* *node version*: v14.17.0
* *module version*: 17.4.2
* *environment* (e.g. node, browser, native): node and browser
* *used with* (e.g. hapi application, another framework, standalone, ...): standalone
* *any other relevant information*:

#### How can we help?

At least one of arrays nodes must be filled, If all arrays nodes are empty, abort validation.

```js
const validator = Joi.array().items(Joi.object({
day: Joi.string().required(),
nodes: Joi.array().items(Joi.array().items(Joi.number()).length(2))
})).length(7)

//not valid
const week = [
{day: 'monday', nodes: []},
{day: 'tuesday', nodes: []},
{day: 'wednessday', nodes: []},
]

//valid
const week = [
{day: 'monday', nodes: [[5,7]]},
{day: 'tuesday', nodes: []},
{day: 'wednessday', nodes: []},
]
```

Contributor guide

Open the contributing guide

Research direction

Reproduce the reported Joi.array().items() schema with the invalid and valid week examples from the issue. Start by tracing how Joi validates the nested nodes arrays and review nearby validation tests; done means all-empty nodes are rejected while a week with at least one populated nodes array is accepted.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
backend-api-design
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.