Skip to content

defaults in alternatives with a match mode set are not returned #2535

@nlundquist

Description

@nlundquist

Support plan

  • is this issue currently blocking your project? (yes/no): yes
  • is this issue affecting a production system? (yes/no): no

Context

  • node version: 12.x
  • module version with issue: 17.3.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

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

Properties with defaults should be applied, even if they're part of an alternative subschema with a match mode.

const joi = require('joi')
const s = joi.alternatives().try(
  joi.object({ 
    lol: joi.string().default('rofl')
  }).unknown(), 
  joi.object({ 
    foo: joi.string().default('bar'), 
    baz: joi.string() 
  })
).match('all')
const { value, error } = s.validate({ baz: 'bing' })

What was the result you got?

error === undefined
value === { baz: 'bing' }

What result did you expect?

error === undefined
value === { lol: 'rofl', foo: 'bar', baz: 'bing' }

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