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

how to concat array of objects inside an object property #561

Closed
Maxlufs opened this issue Feb 25, 2015 · 1 comment
Closed

how to concat array of objects inside an object property #561

Maxlufs opened this issue Feb 25, 2015 · 1 comment
Assignees
Labels
breaking changes Change that can breaking existing code bug Bug or defect
Milestone

Comments

@Maxlufs
Copy link

Maxlufs commented Feb 25, 2015

Concat'ing arrays of primitive types: (OK)

var s1 = Joi.array().includes(Joi.number());
var s2 = Joi.array().includes(Joi.string());

var schema = s1.concat(s2);
Joi.validate([1,"a"], schema); 
// works fine. allow array of mixed of number and string

Concat'ing arrays of objects: (OK)

var s1 = Joi.array().includes(Joi.object().keys({
    "x": Joi.any()
}));
var s2 = Joi.array().includes(Joi.object().keys({
    "y": Joi.any()
}));

var schema = s1.concat(s2);
Joi.validate([{
    "x":1, 
    "y":2
}], schema);
// works fine. allow array of objects that contain both "x" and "y" properties

Concat'ing objects of arrays of objects: (not OK)

var s1 = Joi.object().keys({
    "prop": Joi.array().includes(Joi.object().keys({
        "x": Joi.any()
    }))
});
var s2 = Joi.object().keys({
    "prop": Joi.array().includes(Joi.object().keys({
        "y": Joi.any()
    }))
});

var schema = s1.concat(s2);
Joi.validate([{
    "prop": []
}], schema); 
// works fine

Joi.validate([{
    "prop": [{
        "x": 1
    }]
}], schema); 
// Uh-oh, prop at position 0 fails because x is not allowed

I can work around it by concat'ing the inner object first then include it into a schema of arrays
Is there a way to deep concat like this using built-in Joi.concat?

Thanks

@Marsup Marsup added this to the 6.0.0 milestone Feb 25, 2015
@Marsup Marsup added bug Bug or defect breaking changes Change that can breaking existing code labels Feb 25, 2015
@Marsup Marsup self-assigned this Feb 25, 2015
@Marsup
Copy link
Collaborator

Marsup commented Feb 25, 2015

This issue has already been fixed in master and is to be released in 6.0.0 which shouldn't be too far. Meanwhile you can test if master works for your case.

@Marsup Marsup closed this as completed Feb 25, 2015
@lock lock bot locked as resolved and limited conversation to collaborators Jan 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
breaking changes Change that can breaking existing code bug Bug or defect
Projects
None yet
Development

No branches or pull requests

2 participants