Permalink
Browse files

Move the ‘Validation.prototype.validateSchema’ method into a separate…

… file
  • Loading branch information...
1 parent f14c194 commit fd18de535ca9f95b2db94638ba1e9c748d065ba0 @Baggz committed Mar 8, 2012
Showing with 79 additions and 0 deletions.
  1. +79 −0 src/engines/json/validateSchema.js
@@ -0,0 +1,79 @@
+/**
+ * Validation.validateSchema
+ *
+ * @param {object} instance
+ * @param {object} schema
+ * @param {boolean} singleError
+ * @param {function} callback
+ */
+Validation.prototype.validateSchema = function(instance, schema, path, callback) {
+
+ // Reference na this
+ var self = this;
+
+ /**
+ * {
+ * type: 'object',
+ * properties: {
+ * ...
+ * }
+ * }
+ * — or —
+ * {
+ * type: 'array',
+ * items: {
+ * ...
+ * }
+ */
+ if (['object', 'array'].indexOf(schema.type) !== -1) {
+ return self.validateProperty(path, instance, schema, function(error) {
+
+ /**
+ * {
+ * type: 'object',
+ * properties: {
+ * ...
+ * }
+ * }
+ */
+ if (schema.properties) {
+ return self.validateProperties(instance, schema, path, callback);
+
+ /**
+ * {
+ * type: 'array',
+ * items: {
+ * type: 'string'
+ * ...
+ * }
+ * }
+ */
+ } else if (schema.items) {
+ return self.validateItems(instance, schema, path, callback);
+
+ /**
+ * {
+ * type: 'array'
+ * }
+ * — or —
+ * {
+ * type: 'object'
+ * }
+ */
+ } else {
+ return callback();
+ }
+
+ });
+
+ /**
+ * {
+ * type: 'string',
+ * length: ...
+ * }
+ */
+ } else {
+ return self.validateProperty(path, instance, schema, callback);
+ }
+
+};

0 comments on commit fd18de5

Please sign in to comment.