Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
nlundquist opened this issue Jan 7, 2021 · 1 comment · Fixed by #2536
Closed

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

nlundquist opened this issue Jan 7, 2021 · 1 comment · Fixed by #2536
Assignees
Labels
bug Bug or defect
Milestone

Comments

@nlundquist
Copy link

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' }
@nlundquist
Copy link
Author

Could you take a look at this when you have a chance @hueniverse ?

Have some work that depends on this and would appreciate any help getting this into a release so I can get off my fork.

@hueniverse hueniverse self-assigned this Feb 8, 2021
@hueniverse hueniverse added the bug Bug or defect label Feb 8, 2021
@hueniverse hueniverse added this to the 17.4.0 milestone Feb 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug or defect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants