Permalink
Browse files

The ‘uniqueItems’ attribute is now fully compliant with the JSON Sche…

…ma Internet Draft
  • Loading branch information...
1 parent 9e31432 commit 7772c039ee4cef8908c1056eace18b9627179fe1 @Baggz committed Mar 14, 2012
Showing with 34 additions and 14 deletions.
  1. +34 −14 src/engines/json/attributes/uniqueItems.js
@@ -1,19 +1,39 @@
-/**
- * UniqueItems
- */
-var uniqueItemsAttribute = function uniqueItems(property, propertyValue, attributeValue, propertyAttributes, callback) {
+(function() {
- var self = this;
+ /**
+ * UniqueItems
+ */
+ var attribute = function uniqueItems(property, propertyValue, attributeValue, propertyAttributes, callback) {
- each(propertyValue, function(index, value) {
- if ((propertyValue.indexOf(value) < index)) {
- self.addError();
- }
- });
+ var self = this;
- return callback();
+ each(propertyValue, function(index, value) {
-};
+ if (isString(value)) {
+ if ((propertyValue.indexOf(value) < index)) {
+ self.addError();
+ }
+ }
-// Export
-Validation.prototype.addAttribute('uniqueItems', uniqueItemsAttribute);
+ if (isObject(value) || isArray(value)) {
+ propertyValue.forEach(function(subValue, subIndex) {
+
+ if (subIndex !== index) {
+ if (isEqual(value, subValue)) {
+ self.addError();
+ }
+ }
+
+ });
+ }
+
+ });
+
+ return callback();
+
+ };
+
+ // Export
+ Validation.prototype.addAttribute('uniqueItems', attribute);
+
+}());

0 comments on commit 7772c03

Please sign in to comment.