Skip to content

Rename multiple keys to another name #1239

@samueljoli

Description

@samueljoli

Context

  • node version: 6
  • joi version: 10.3.x
  • environment (node, browser):
  • used with (hapi, standalone, ...):
  • any other relevant information:

What are you trying to achieve or the steps to reproduce ?

const caseInsensitiveOverrides = ['marketcode', 'MarketCode', 'MARKETCODE'];

const schema = Joi.object({
  marketCode  : Joi.string(),
}).rename(caseInsensitiveOverrides, 'marketCode')

I have a need for my params to be case insensitive and would like to implement that by using the rename api. It would be nice if I could pass rename a list of keys that whenever present would rename to a default key.

Example:
=> /route?marketCode=191
=> /route?marketcode=191
=> /route?MARKETCODE=191

I would expect each permutation to be validated and that in my handler the return value would be...

request.query.marketCode // => 191

Metadata

Metadata

Assignees

Labels

featureNew functionality or improvement

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions