Closed logonv closed 1 year ago
Hi,
Thanks for the detailed example. I can see 2 "mistakes" in this schema:
when
with a schema as 1st parameter must completely match, a match on a partial object needs .unknown()
to validate that object, if you were to validate this in isolation, it would report excess keys as errorswhen
merges then
/otherwise
schemas based on the conditions, what you might not have considered is that arrays can't be deterministically merged, there is no unique way of knowing if by items(A) + items(B)
you meant items(A, B)
or items(A+B)
, and the current way joi does this is by adding your new schema to the list of possibilities, it won't merge it into seasonSchema
Knowing all of this, I would write your schema like that: https://runkit.com/embed/m8hwqfjgjg5c I think it passes all your scenarios, or at least it's a good starting point.
Apologies for the late reply, thanks for your help!
Support plan
Context
We are trying to use JOI with a nextJs 13.4.4 app with node 18.6.0. The same issue can be reproduced on https://npm.runkit.com/joi and that's what's described below.
What are you trying to achieve or the steps to reproduce?
id
,format
,status
andseasons
.format
is eithermovie
orseries
while status is eitherpass
orfail
.seasons
is an array ofseason
objects.id
,seasonNumber
andepisodes
.episodes
is an array ofepisode
objects.id
andname
.format is not
seriesthen the
seasons` key of the root object is forbidden.format
isseries
and thestatus
ispass
there should be a minimum of 2season
objects and 5episodes
.Reproduction can be found here https://runkit.com/logan-runkit/joi-bug
What was the result you got?
Validation passes
What result did you expect?
Validation should fail