3 var SCALAR_TYPES = ['number', 'integer', 'string', 'boolean', 'null'];
5 module.exports = function defFunc(ajv) {
8 compile: function(keys, parentSchema, it) {
9 var equal = it.util.equal;
10 var scalar = getScalarKeys(keys, parentSchema);
12 return function(data) {
13 if (data.length > 1) {
14 for (var k=0; k < keys.length; k++) {
18 for (i = data.length; i--;) {
19 if (!data[i] || typeof data[i] != 'object') continue;
20 var prop = data[i][key];
21 if (prop && typeof prop == 'object') continue;
22 if (typeof prop == 'string') prop = '"' + prop;
23 if (hash[prop]) return false;
27 for (i = data.length; i--;) {
28 if (!data[i] || typeof data[i] != 'object') continue;
29 for (var j = i; j--;) {
30 if (data[j] && typeof data[j] == 'object' && equal(data[i][key], data[j][key]))
42 items: {type: 'string'}
46 ajv.addKeyword('uniqueItemProperties', defFunc.definition);
51 function getScalarKeys(keys, schema) {
52 return keys.map(function(key) {
53 var properties = schema.items && schema.items.properties;
54 var propType = properties && properties[key] && properties[key].type;
55 return Array.isArray(propType)
56 ? propType.indexOf('object') < 0 && propType.indexOf('array') < 0
57 : SCALAR_TYPES.indexOf(propType) >= 0;