Skip to content

Commit

Permalink
[schema] Don't allow object types without a name when used with a blo…
Browse files Browse the repository at this point in the history
…ck type
  • Loading branch information
skogsmaskin committed Jan 19, 2019
1 parent fca0e85 commit 3c65c11
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion packages/@sanity/schema/src/sanity/validation/types/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,25 @@ export default (typeDef, visitorContext) => {
HELP_IDS.ARRAY_OF_INVALID
)
])
const of = ofIsArray ? typeDef.of : []

// Don't allow object types without a name in block arrays
const hasObjectTypesWithoutName = of.some(
type => type.type === 'object' && typeof type.name === 'undefined'
)
const hasBlockType = of.some(ofType => ofType.type === 'block')
if (hasBlockType && hasObjectTypesWithoutName) {
problems.push(
error(
"The array type's 'of' attribute can't have an object type without a .name when used in together with a block type",
HELP_IDS.ARRAY_OF_INVALID
)
)
}

return {
...typeDef,
of: (ofIsArray ? typeDef.of : []).map(visitorContext.visit),
of: of.map(visitorContext.visit),
_problems: problems
}
}

0 comments on commit 3c65c11

Please sign in to comment.