Skip to content

Commit

Permalink
[validation] Check for type validating arrays and objects in document (
Browse files Browse the repository at this point in the history
  • Loading branch information
skogsmaskin committed May 22, 2019
1 parent 15d146e commit ebb997a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion packages/@sanity/validation/src/validateDocument.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ function validateObject(obj, type, path, options) {
// Validate fields within object
const fields = type.fields || []
const fieldChecks = fields.map(field => {
const validation = field.type.validation
const validation = field.type && field.type.validation
if (!validation) {
return []
}
Expand All @@ -74,6 +74,16 @@ function validateObject(obj, type, path, options) {
}

function validateArray(items, type, path, options) {
if (!type) {
return [
{
type: 'validation',
level: 'error',
path,
item: new ValidationError('Unable to resolve type for array')
}
]
}
// Validate actual array itself
let arrayChecks = []
if (type.validation) {
Expand Down

0 comments on commit ebb997a

Please sign in to comment.