Skip to content

Joi.build() does not work with complex extension bases #2380

@brianle1301

Description

@brianle1301

Support plan

  • which support plan is this issue covered by? (e.g. Community, Core, Plus, or Enterprise): Communtiy
  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: 12.16.1
  • module version with issue: 17.1.0
  • last module version without issue: N/A
  • environment (e.g. node, browser, native): node
  • used with (e.g. hapi application, another framework, standalone, ...): standalone
  • any other relevant information: N/A

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

I'm extending a schema with a complex array base:

const custom = Joi.extend({
    type: 'test',
    base: Joi.array().items(Joi.string().required());
});

const schema = custom.test();

schema.validate(['x']); // No errors

const description = schema.describe(); 
const newSchema = custom.build(description);

newSchema.validate(['x']); // "value" does not contain 1 required value(s)

What was the result you got?

A validation error on what is supposed to be valid

What result did you expect?

No error.

Metadata

Metadata

Assignees

Labels

bugBug or defect

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions