Skip to content

Joi.any().default(<object>).describe() throws validation errors #2134

@tuckbick

Description

@tuckbick

Context

  • node version: 10.16.2
  • joi version: 16.1.1
  • environment (node, browser): node
  • used with (hapi, standalone, ...): standalone
  • any other relevant information:

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

const schema = Joi.object({
    foo: Joi.string().default('bar')
}).default({
    foo: 'bar'
});

schema.describe(); // throws ValidationError

Which result you had ?

ValidationError: {
  "type": "object",
  "flags": {
    "default" [1]: {
      "foo": "bar"
    }
  },
  "keys": {
    "foo": {
      "type": "string",
      "flags": {
        "default": "bar"
      }
    }
  }
}
    
[1] "flags.default" does not match any of the allowed types

What did you expect ?

Proper output of schema.describe(). It's my understanding that objects can be passed to default() and the provided default on the overall schema matches the described schema. I'm confused as to why this would fail.

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