Skip to content

Commit

Permalink
review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
rgoble4 committed May 28, 2018
1 parent 3a84adc commit eaefa17
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
13 changes: 1 addition & 12 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -1603,6 +1603,7 @@ const schema = Joi.object().length(5);

Specify validation rules for unknown keys matching a pattern where:
- `regex` - a regular expression tested against the unknown key names.
- `regex` - may also be a schema object validated against the unknown key names.
- `schema` - the schema object matching keys must validate against.

```js
Expand All @@ -1611,18 +1612,6 @@ const schema = Joi.object({
}).pattern(/\w\d/, Joi.boolean());
```

#### `object.pattern(keySchema, valueSchema)`

Specify validation rules for unknown keys matching a pattern where:
- `keySchema` - the schema object validated against the unknown key names.
- `valueSchema` - the schema object matching keys must validate against.

```js
const schema = Joi.object({
a: Joi.string()
}).pattern(Joi.string(), Joi.boolean());
```

#### `object.and(peers)`

Defines an all-or-nothing relationship between keys where if one of the peers is present, all of them are required as
Expand Down
4 changes: 2 additions & 2 deletions lib/types/object/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,10 +652,10 @@ internals.Object = class extends Any {
for (let i = 0; i < this._inner.patterns.length; ++i) {
const pattern = this._inner.patterns[i];
if (pattern.regex) {
description.patterns.push({ patternRule: pattern.patternRule.toString(), valueRule: pattern.valueRule.describe() });
description.patterns.push({ regex: pattern.patternRule.toString(), rule: pattern.valueRule.describe() });
}
else {
description.patterns.push({ patternRule: pattern.patternRule.describe(), valueRule: pattern.valueRule.describe() });
description.patterns.push({ regex: pattern.patternRule.describe(), rule: pattern.valueRule.describe() });
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions test/types/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -1535,8 +1535,8 @@ describe('object', () => {
},
patterns: [
{
patternRule: '/\\w\\d/i',
valueRule: {
regex: '/\\w\\d/i',
rule: {
type: 'boolean',
truthy: [true],
falsy: [false],
Expand Down Expand Up @@ -1565,15 +1565,15 @@ describe('object', () => {
},
patterns: [
{
patternRule: {
regex: {
invalids: [''],
rules: [{
arg: 'uuidv4',
name: 'guid'
}],
type: 'string'
},
valueRule: {
rule: {
type: 'boolean',
truthy: [true],
falsy: [false],
Expand Down

0 comments on commit eaefa17

Please sign in to comment.