lib/har/viewer/scripts/preview/jsonSchema.js in har-0.0.9 vs lib/har/viewer/scripts/preview/jsonSchema.js in har-0.1.0

- old
+ new

@@ -1,7 +2 @@ -require.def("preview/jsonSchema",[],function(){return{validate:function(i,l){return this._validate(i,l,false)},checkPropertyChange:function(i,l,m){return this._validate(i,l,m||"property")},_validate:function(i,l,m){function j(b,a,f,d){function c(g){e.push({property:f,message:g})}function h(g,k){if(g){if(typeof g=="string"&&g!="any"&&(g=="null"?k!==null:typeof k!=g)&&!(k instanceof Array&&g=="array")&&!(g=="integer"&&k%1===0))return[{property:f,message:typeof k+" value found, but a "+g+" is required"}]; -if(g instanceof Array){for(var o=[],p=0;p<g.length;p++)if(!(o=h(g[p],k)).length)break;if(o.length)return o}else if(typeof g=="object"){o=e;e=[];j(k,g,f);g=e;e=o;return g}}return[]}var n;f+=f?typeof d=="number"?"["+d+"]":typeof d=="undefined"?"":"."+d:d;if((typeof a!="object"||a instanceof Array)&&(f||typeof a!="function")){if(typeof a=="function")b instanceof a||c("is not an instance of the class/constructor "+a.name);else a&&c("Invalid schema/property definition "+a);return null}m&&a.readonly&&c("is a readonly field, it can not be changed"); -a["extends"]&&j(b,a["extends"],f,d);if(b===undefined)a.optional||c("is missing and it is not optional");else{e=e.concat(h(a.type,b));a.disallow&&!h(a.disallow,b).length&&c(" disallowed value was matched");if(b!==null){if(b instanceof Array){if(a.items)if(a.items instanceof Array){d=0;for(n=b.length;d<n;d++)e.concat(j(b[d],a.items[d],f,d))}else{d=0;for(n=b.length;d<n;d++)e.concat(j(b[d],a.items,f,d))}a.minItems&&b.length<a.minItems&&c("There must be a minimum of "+a.minItems+" in the array");a.maxItems&& -b.length>a.maxItems&&c("There must be a maximum of "+a.maxItems+" in the array")}else a.properties&&e.concat(s(b,a.properties,f,a.additionalProperties));a.pattern&&typeof b=="string"&&!b.match(a.pattern)&&c("does not match the regex pattern "+a.pattern);a.maxLength&&typeof b=="string"&&b.length>a.maxLength&&c("may only be "+a.maxLength+" characters long");a.minLength&&typeof b=="string"&&b.length<a.minLength&&c("must be at least "+a.minLength+" characters long");typeof a.minimum!==undefined&&typeof b== -typeof a.minimum&&a.minimum>b&&c("must have a minimum value of "+a.minimum);typeof a.maximum!==undefined&&typeof b==typeof a.maximum&&a.maximum<b&&c("must have a maximum value of "+a.maximum);if(a["enum"]){d=a["enum"];n=d.length;for(var r,q=0;q<n;q++)if(d[q]===b){r=1;break}r||c("does not have a value in the enumeration "+d.join(", "))}typeof a.maxDecimal=="number"&&b.toString().match(new RegExp("\\.[0-9]{"+(a.maxDecimal+1)+",}"))&&c("may only have "+a.maxDecimal+" digits of decimal places")}}return null} -function s(b,a,f,d){if(typeof a=="object"){if(typeof b!="object"||b instanceof Array)e.push({property:f,message:"an object is required"});for(var c in a)if(a.hasOwnProperty(c)&&!(c.charAt(0)=="_"&&c.charAt(1)=="_")){var h=b[c];j(h,a[c],f,c)}}for(c in b){b.hasOwnProperty(c)&&!(c.charAt(0)=="_"&&c.charAt(1)=="_")&&a&&!a[c]&&d===false&&e.push({property:f,message:typeof h+"The property "+c+" is not defined in the schema and the schema does not allow additional properties"});(h=a&&a[c]&&a[c].requires)&& -!(h in b)&&e.push({property:f,message:"the presence of the property "+c+" requires that "+h+" also be present"});h=b[c];a&&typeof a=="object"&&!(c in a)&&j(h,d,f,c);if(!m&&h&&h.$schema)e=e.concat(j(h,h.$schema,f,c))}return e}var e=[];if(l)j(i,l,"",m||"");!m&&i&&i.$schema&&j(i,i.$schema,"","");return{valid:!e.length,errors:e}}}}); +require.def("preview/jsonSchema",[],function(){var a={validate:function(a,b){return this._validate(a,b,!1)},checkPropertyChange:function(a,b,c){return this._validate(a,b,c||"property")},_validate:function(a,b,c){function f(a,b,f,g){if(typeof b=="object"){(typeof a!="object"||a instanceof Array)&&d.push({property:f,message:"an object is required"});for(var h in b)if(b.hasOwnProperty(h)&&(h.charAt(0)!="_"||h.charAt(1)!="_")){var i=a[h],j=b[h];e(i,j,f,h)}}for(h in a){a.hasOwnProperty(h)&&(h.charAt(0)!="_"||h.charAt(1)!="_")&&b&&!b[h]&&g===!1&&d.push({property:f,message:typeof i+"The property "+h+" is not defined in the schema and the schema does not allow additional properties"});var k=b&&b[h]&&b[h].requires;k&&!(k in a)&&d.push({property:f,message:"the presence of the property "+h+" requires that "+k+" also be present"}),i=a[h],b&&typeof b=="object"&&!(h in b)&&e(i,g,f,h),!c&&i&&i.$schema&&(d=d.concat(e(i,i.$schema,f,h)))}return d}function e(a,b,g,h){function k(a,b){if(a){if(typeof a=="string"&&a!="any"&&(a=="null"?b!==null:typeof b!=a)&&!(b instanceof Array&&a=="array")&&(a!="integer"||b%1!==0))return[{property:g,message:typeof b+" value found, but a "+a+" is required"}];if(a instanceof Array){var c=[];for(var f=0;f<a.length;f++)if(!(c=k(a[f],b)).length)break;if(c.length)return c}else if(typeof a=="object"){var h=d;d=[],e(b,a,g);var i=d;d=h;return i}}return[]}function j(a){d.push({property:g,message:a})}var i;g+=g?typeof h=="number"?"["+h+"]":typeof h=="undefined"?"":"."+h:h;if((typeof b!="object"||b instanceof Array)&&(g||typeof b!="function")){typeof b=="function"?a instanceof b||j("is not an instance of the class/constructor "+b.name):b&&j("Invalid schema/property definition "+b);return null}c&&b.readonly&&j("is a readonly field, it can not be changed"),b["extends"]&&e(a,b["extends"],g,h);if(a===undefined)b.optional||j("is missing and it is not optional");else{d=d.concat(k(b.type,a)),b.disallow&&!k(b.disallow,a).length&&j(" disallowed value was matched");if(a!==null){if(a instanceof Array){if(b.items)if(b.items instanceof Array)for(h=0,i=a.length;h<i;h++)d.concat(e(a[h],b.items[h],g,h));else for(h=0,i=a.length;h<i;h++)d.concat(e(a[h],b.items,g,h));b.minItems&&a.length<b.minItems&&j("There must be a minimum of "+b.minItems+" in the array"),b.maxItems&&a.length>b.maxItems&&j("There must be a maximum of "+b.maxItems+" in the array")}else b.properties&&d.concat(f(a,b.properties,g,b.additionalProperties));b.pattern&&typeof a=="string"&&!a.match(b.pattern)&&j("does not match the regex pattern "+b.pattern),b.maxLength&&typeof a=="string"&&a.length>b.maxLength&&j("may only be "+b.maxLength+" characters long"),b.minLength&&typeof a=="string"&&a.length<b.minLength&&j("must be at least "+b.minLength+" characters long"),typeof b.minimum!==undefined&&typeof a==typeof b.minimum&&b.minimum>a&&j("must have a minimum value of "+b.minimum),typeof b.maximum!==undefined&&typeof a==typeof b.maximum&&b.maximum<a&&j("must have a maximum value of "+b.maximum);if(b["enum"]){var l=b["enum"];i=l.length;var m;for(var n=0;n<i;n++)if(l[n]===a){m=1;break}m||j("does not have a value in the enumeration "+l.join(", "))}typeof b.maxDecimal=="number"&&a.toString().match(new RegExp("\\.[0-9]{"+(b.maxDecimal+1)+",}"))&&j("may only have "+b.maxDecimal+" digits of decimal places")}}return null}var d=[];b&&e(a,b,"",c||""),!c&&a&&a.$schema&&e(a,a.$schema,"","");return{valid:!d.length,errors:d}}};return a}) \ No newline at end of file