Skip to content

Commit

Permalink
[validation] Allow disabling validation for field and document types
Browse files Browse the repository at this point in the history
  • Loading branch information
rexxars committed Mar 5, 2018
1 parent a7abf4b commit b22e0cc
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion packages/@sanity/validation/src/inferFromSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const inferFromSchemaType = require('./inferFromSchemaType')
function inferFromSchema(schema) {
const typeNames = schema.getTypeNames()
typeNames.forEach(typeName => {
inferFromSchemaType(schema.get(typeName), {types: []})
inferFromSchemaType(schema.get(typeName))
})
return schema
}
Expand Down
7 changes: 6 additions & 1 deletion packages/@sanity/validation/src/inferFromSchemaType.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
const Rule = require('./Rule')

// eslint-disable-next-line complexity
function inferFromSchemaType(typeDef, isRoot = true) {
function inferFromSchemaType(typeDef) {
if (typeDef.validation === false) {
typeDef.validation = []
return typeDef
}

const isInitialized =
Array.isArray(typeDef.validation) &&
typeDef.validation.every(item => typeof item.validate === 'function')
Expand Down
2 changes: 1 addition & 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) {
const fieldChecks = fields.map(field => {
const validation = field.type.validation
if (!validation) {
return null
return []
}

const fieldPath = appendPath(path, field.name)
Expand Down

0 comments on commit b22e0cc

Please sign in to comment.