Skip to content

Error when .rename() from undefined #614

@JbIPS

Description

@JbIPS

Hi,
here's what I'm trying to do :
I've got this Joi schema

var validateQuery = core.Joi.object().keys({
  clientId: core.Joi.string().required(),
  redirectUri: core.Joi.string().required().regex(/^[a-z0-9]*:\/\/[^*]*/i),
  responseType: core.Joi.string().required().valid(['code', 'token']),
}).rename('client_id', 'clientId', {override: true})
  .rename('redirect_uri', 'redirectUri', {override: true})
  .rename('response_type', 'responseType', {override: true});

and I'm validating this object

  redirectUri: 'http://whatever.com',
  responseType: 'token',
  clientId: '240f17d59129425093d9ec805009e75e' }

This give me [ValidationError: child "clientId" fails because ["clientId" is required]]. Changing clientId to client_id in my object works fine, but rename() shouldn't delete my keys if the rename isn't necessary, right? I think this behavior is comming from this commit but maybe it's on purpose and I missed something.

Is that a bug or a feature ?

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