Allow alternative validations to be provided for collections and fragments of different types
As discussed with @jure, because there are only two data types available in PubSweet (Collection and Fragment), they need to be re-used when an application has more than two types of data.
A property can be used to distinguish between different types of Collection or Fragment (e.g. fragmentType
).
In order to be able to validate the different types of Fragment using Joi, the other properties must be moved from the top level into a new child property (data
, say).
I think the validation would then look something like this:
fragment: {
fragmentType: Joi.valid('foo', 'bar'),
data: Joi.alternatives()
.when('fragmentType', {is: 'foo', then: Joi.object({ … })})
.when('fragmentType', {is: 'bar', then: Joi.object({ … })})
},