Skip to content

Commit

Permalink
Clarify referenced parameter resolution
Browse files Browse the repository at this point in the history
See #1798
  • Loading branch information
adamreisnz committed May 7, 2019
1 parent 2d6f1b5 commit c62ac45
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 c62ac45

Please sign in to comment.