Skip to content

Create default [highly nested] object easily? #413

@gdw2

Description

@gdw2

I've got a pretty massive and nested Joi structure. I'm wondering if there's an easy way to have it spit out a default object. Something like:

Joi.compile(
    {
        baz: 
            {foo: Joi.string().default('bar')}, 
        beef: Joi.string().default('hi')
    }
).validate({});
{ error: null, value: { beef: 'hi' } }

But instead of just returning { beef: 'hi' }, have it return { baz: { foo: 'bar' }, beef: 'hi' }.

Is this currently possible?

I could create baz using Joi.object().default(...), but then I'd have to specify the entire substructure as the default. This would be more difficult to maintain.

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