Skip to content

Commit

Permalink
Merge pull request #1804 from adamreisnz/patch-1
Browse files Browse the repository at this point in the history
Clarify referenced parameter resolution
  • Loading branch information
Marsup authored May 8, 2019
2 parents 2d6f1b5 + c62ac45 commit 3029ea6
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions API.md
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,17 @@ The `params` of `rules` rely on the fact that all engines, even though not state
params: { options: Joi.object({ param1: Joi.number().required(), param2: Joi.string() }) }
```

To resolve referenced `params` in you `validate` or `setup` functions, you can use the following approach:
```js
validate(params, value, state, options) {
let {foo} = params;
if (Joi.isRef(foo)) {
foo = foo(state.reference || state.parent, options);
}
//...
}
```

Any of the `coerce`, `pre` and `validate` functions should use `this.createError(type, context, state, options[, flags])` to create and return errors.
This function potentially takes 5 arguments:
* `type` - the dotted type of the error matching predefined language elements or the ones defined in your extension. **Required**.
Expand Down

0 comments on commit 3029ea6

Please sign in to comment.