lib/har/viewer/scripts/preview/jsonSchema.js in har-0.1.0 vs lib/har/viewer/scripts/preview/jsonSchema.js in har-0.1.1
- old
+ new
@@ -1,16 +1,32 @@
-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})
+/**
+ * JSONSchema Validator - Validates JavaScript objects using JSON Schemas
+ * (http://www.json.com/json-schema-proposal/)
+ *
+ * Copyright (c) 2007 Kris Zyp SitePen (www.sitepen.com)
+ * Licensed under the MIT (MIT-LICENSE.txt) license.
+To use the validator call JSONSchema.validate with an instance object and an optional schema object.
+If a schema is provided, it will be used to validate. If the instance object refers to a schema (self-validating),
+that schema will be used to validate and the schema parameter is not necessary (if both exist,
+both validations will occur).
+The validate method will return an array of validation errors. If there are no errors, then an
+empty list will be returned. A validation error will have two properties:
+"property" which indicates which property had the error
+"message" which indicates what the error was
+ */
+
+define("preview/jsonSchema",[],function(){var e={validate:function(e,t){return this._validate(e,t,!1)},checkPropertyChange:function(e,t,n){return this._validate(e,t,n||"property")},_validate:function(e,t,n){function i(e,t,o,u){function f(e){r.push({property:o,message:e})}function l(e,t){if(e){if(!(typeof e!="string"||e=="any"||(e=="null"?t===null:typeof t==e)||t instanceof Array&&e=="array"||e=="integer"&&t%1===0))return[{property:o,message:typeof t+" value found, but a "+e+" is required"}];if(e instanceof Array){var n=[];for(var s=0;s<e.length;s++)if(!(n=l(e[s],t)).length)break;if(n.length)return n}else if(typeof e=="object"){var u=r;r=[],i(t,e,o);var a=r;return r=u,a}}return[]}var a;o+=o?typeof u=="number"?"["+u+"]":typeof u=="undefined"?"":"."+u:u;if((typeof t!="object"||t instanceof Array)&&(o||typeof t!="function"))return typeof t=="function"?e instanceof t||f("is not an instance of the class/constructor "+t.name):t&&f("Invalid schema/property definition "+t),null;n&&t.readonly&&f("is a readonly field, it can not be changed"),t["extends"]&&i(e,t["extends"],o,u);if(e===undefined)t.optional||f("is missing and it is not optional");else{r=r.concat(l(t.type,e)),t.disallow&&!l(t.disallow,e).length&&f(" disallowed value was matched");if(e!==null){if(e instanceof Array){if(t.items)if(t.items instanceof Array)for(u=0,a=e.length;u<a;u++)r.concat(i(e[u],t.items[u],o,u));else for(u=0,a=e.length;u<a;u++)r.concat(i(e[u],t.items,o,u));t.minItems&&e.length<t.minItems&&f("There must be a minimum of "+t.minItems+" in the array"),t.maxItems&&e.length>t.maxItems&&f("There must be a maximum of "+t.maxItems+" in the array")}else t.properties&&r.concat(s(e,t.properties,o,t.additionalProperties));t.pattern&&typeof e=="string"&&!e.match(t.pattern)&&f("does not match the regex pattern "+t.pattern),t.maxLength&&typeof e=="string"&&e.length>t.maxLength&&f("may only be "+t.maxLength+" characters long"),t.minLength&&typeof e=="string"&&e.length<t.minLength&&f("must be at least "+t.minLength+" characters long"),typeof t.minimum!==undefined&&typeof e==typeof t.minimum&&t.minimum>e&&f("must have a minimum value of "+t.minimum),typeof t.maximum!==undefined&&typeof e==typeof t.maximum&&t.maximum<e&&f("must have a maximum value of "+t.maximum);if(t["enum"]){var c=t["enum"];a=c.length;var h;for(var p=0;p<a;p++)if(c[p]===e){h=1;break}h||f("does not have a value in the enumeration "+c.join(", "))}typeof t.maxDecimal=="number"&&e.toString().match(new RegExp("\\.[0-9]{"+(t.maxDecimal+1)+",}"))&&f("may only have "+t.maxDecimal+" digits of decimal places")}}return null}function s(e,t,s,o){if(typeof t=="object"){(typeof e!="object"||e instanceof Array)&&r.push({property:s,message:"an object is required"});for(var u in t)if(t.hasOwnProperty(u)&&(u.charAt(0)!="_"||u.charAt(1)!="_")){var a=e[u],f=t[u];i(a,f,s,u)}}for(u in e){e.hasOwnProperty(u)&&(u.charAt(0)!="_"||u.charAt(1)!="_")&&t&&!t[u]&&o===!1&&r.push({property:s,message:typeof a+"The property "+u+" is not defined in the schema and the schema does not allow additional properties"});var l=t&&t[u]&&t[u].requires;l&&!(l in e)&&r.push({property:s,message:"the presence of the property "+u+" requires that "+l+" also be present"}),a=e[u],t&&typeof t=="object"&&!(u in t)&&i(a,o,s,u),!n&&a&&a.$schema&&(r=r.concat(i(a,a.$schema,s,u)))}return r}var r=[];return t&&i(e,t,"",n||""),!n&&e&&e.$schema&&i(e,e.$schema,"",""),{valid:!r.length,errors:r}}};return e});
\ No newline at end of file