.6-浅析webpack源码之validateSchema模块
2018-06-27 09:10:17来源:未知 阅读 ()
validateSchema模块
首先来看错误检测:
const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, options); if(webpackOptionsValidationErrors.length) { throw new WebpackOptionsValidationError(webpackOptionsValidationErrors); }
可以注意到,这里传了两个参数,其实第一个参数来源于一个JSON文件:
const webpackOptionsSchema = require("../schemas/webpackOptionsSchema.json");
这个JSON文件非常大,可以观察一下部分内容:
{
"plugins": {
"description": "Add additional plugins to the compiler.",
"type": "array"
},
"resolve": {
"description": "Options for the resolver",
"anyOf": [
{
"$ref": "#/definitions/resolve"
}
]
},
"required": [
"entry"
],
"type": "object"
}
从描述可以猜测,这里的key对应options中的key,value就是检测方式。
比如说entry放到required代表是必须的,plugins的type为array代表这个键必须是一个数组,而$ref代表一个路径映射,即#/definnitions/resolve。
在JSON文件的开头有一个definitions,其中resolve对应的内容如下:
{
"definitions": {
"resolve": {
"additionalProperties": false,
"properties": {
"alias": {
// ...
}
// ...
},
"type": "object"
}
}
}
简单明了,就不多解释了。
下面进入validateSchema模块,流程如图:
内部代码简化如下:
const Ajv = require("ajv"); const ajv = new Ajv({ errorDataPath: "configuration", allErrors: true, verbose: true }); require("ajv-keywords")(ajv, ["instanceof"]); require("../schemas/ajv.absolutePath")(ajv); function validateSchema(schema, options) { // 仍然是多配置与单配置 if(Array.isArray(options)) { /*...*/ } else { return validateObject(schema, options); } } function validateObject(schema, options) { // 转换JSON文件 const validate = ajv.compile(schema); // 检测配置对象 const valid = validate(options); // 返回错误对象 return valid ? [] : filterErrors(validate.errors); } function filterErrors(errors) { /*...*/ } module.exports = validateSchema;
这里引入的ajv模块是一个工具,就像之前的JSON5一样,作用是将一个JSON配置文件转换成一个对象,用于检测对象的合法性。
在github上,该工具的Getting started如图所示:
简直跟源码中的使用过程一模一样,所以有兴趣的可以自己去看看教程学一下。
由于JSON十分巨大,所以编译后的对象也十分巨大,这里根据vue脚手架中的配置,只看常规的参数是如何进行检测的,比如说devServer、devtool、entry、module、output、plugins、resolve,测试代码如下:
var Ajv = require('ajv'); const ajv = new Ajv({ errorDataPath: "configuration", allErrors: true, verbose: true }); // 简化后的JSON文件 const json = require('./tmp.json'); const validate = ajv.compile(json);
打包后尝试获取生成的validate函数,整理后源码如下:
(function(self, RULES, formats, root, refVal, defaults, customRules, co, equal, ucs2length, ValidationError) { var refVal0 = refVal[0]; // ... var refVal13 = refVal[13]; var validate = (function(data, dataPath, parentData, parentDataProperty, rootData) { 'use strict'; // 负责收集错误信息 var vErrors = null; // 负责对错误进行计数 var errors = 0; if (rootData === undefined) rootData = data; // 这是根级对象 if ((data && typeof data === "object" && !Array.isArray(data))) { var errs__0 = errors; var valid1 = true; for (var key0 in data) { /*...*/ } // 在这里进行检测 // 每出现一个错误errors+1并记录vErrors中 var data1 = data.devServer; if (data1 !== undefined) { /*...*/ } var data1 = data.devtool; if (data1 !== undefined) { /*...*/ } var data1 = data.entry; if (data1 === undefined) { /*...*/ } else { /*...*/ } var data1 = data.module; if (data1 !== undefined) { /*...*/ } var data1 = data.output; if (data1 !== undefined) { /*...*/ } var data1 = data.plugins; if (data1 !== undefined) { /*...*/ } var data1 = data.resolve; if (data1 !== undefined) { /*...*/ } } else { /*...*/ } validate.errors = vErrors; // 判断是否产生错误 return errors === 0; }); return validate; })
调用validate(options),options在函数中就相当于那个data,validate会依次从data中取出需要校验的key,按照JSON文件中的规则进行判断。
这里有一个比较麻烦的点,就是顶部的refVal,由于这是一个内部的IIFE,所以从这里看不出refVal数组如何定义的。凭借我的聪明才智,还是从源码中获取到了对应的定义:
打开后,其实是一堆validate函数,所以就不展开看了。
其实validate并不只有这么多,其中还可以分为特殊校验器和公共校验器,其中公共校验器不会针对特殊的键来进行校验,在这里可以先列出来。(友情警告:千万不要点开!!!)
refVal1
if ((data && typeof data === "object" && !Array.isArray(data))) { if (Object.keys(data).length < 1) { var err = { keyword: 'minProperties', dataPath: (dataPath || '') + "", schemaPath: '#/oneOf/0/minProperties', params: { limit: 1 }, message: 'should NOT have less than 1 properties', schema: 1, parentSchema: validate.schema.oneOf[0], data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var errs__1 = errors; var valid2 = true; for (var key1 in data) { var data1 = data[key1]; var errs_2 = errors; var errs__2 = errors; var prevValid2 = false; var valid2 = false; var errs_3 = errors; if (typeof data1 === "string") { if (ucs2length(data1) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '[\'' + key1 + '\']', schemaPath: '#/oneOf/0/additionalProperties/oneOf/0/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: validate.schema.oneOf[0].additionalProperties.oneOf[0], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '[\'' + key1 + '\']', schemaPath: '#/oneOf/0/additionalProperties/oneOf/0/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.oneOf[0].additionalProperties.oneOf[0].type, parentSchema: validate.schema.oneOf[0].additionalProperties.oneOf[0], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; if (valid3) valid2 = prevValid2 = true; var errs_3 = errors; var errs__3 = errors; var valid3 = false; var errs_4 = errors; var errs_5 = errors; if (Array.isArray(data1)) { if (data1.length < 1) { var err = { keyword: 'minItems', dataPath: (dataPath || '') + '[\'' + key1 + '\']', schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/minItems', params: { limit: 1 }, message: 'should NOT have less than 1 items', schema: 1, parentSchema: refVal2, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid5 = true; if (data1.length > 1) { var i = data1.length, j; outer: for (; i--;) { for (j = i; j--;) { if (equal(data1[i], data1[j])) { valid5 = false; break outer; } } } } if (!valid5) { var err = { keyword: 'uniqueItems', dataPath: (dataPath || '') + '[\'' + key1 + '\']', schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/uniqueItems', params: { i: i, j: j }, message: 'should NOT have duplicate items (items ## ' + j + ' and ' + i + ' are identical)', schema: true, parentSchema: refVal2, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var errs__5 = errors; var valid5; for (var i5 = 0; i5 < data1.length; i5++) { var data2 = data1[i5]; var errs_6 = errors; if (typeof data2 === "string") { if (ucs2length(data2) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '[\'' + key1 + '\'][' + i5 + ']', schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal2.items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '[\'' + key1 + '\'][' + i5 + ']', schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal2.items.type, parentSchema: refVal2.items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid6 = errors === errs_6; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '[\'' + key1 + '\']', schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal2.type, parentSchema: refVal2, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid5 = errors === errs_5; var valid4 = errors === errs_4; valid3 = valid3 || valid4; if (!valid3) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '[\'' + key1 + '\']', schemaPath: '#/oneOf/0/additionalProperties/oneOf/1/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.oneOf[0].additionalProperties.oneOf[1].anyOf, parentSchema: validate.schema.oneOf[0].additionalProperties.oneOf[1], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__3; if (vErrors !== null) { if (errs__3) vErrors.length = errs__3; else vErrors = null; } } var valid3 = errors === errs_3; if (valid3 && prevValid2) valid2 = false; else { if (valid3) valid2 = prevValid2 = true; } if (!valid2) { var err = { keyword: 'oneOf', dataPath: (dataPath || '') + '[\'' + key1 + '\']', schemaPath: '#/oneOf/0/additionalProperties/oneOf', params: {}, message: 'should match exactly one schema in oneOf', schema: validate.schema.oneOf[0].additionalProperties.oneOf, parentSchema: validate.schema.oneOf[0].additionalProperties, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__2; if (vErrors !== null) { if (errs__2) vErrors.length = errs__2; else vErrors = null; } } var valid2 = errors === errs_2; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/oneOf/0/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.oneOf[0].type, parentSchema: validate.schema.oneOf[0], data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; if (valid1) valid0 = prevValid0 = true; var errs_1 = errors; if (typeof data === "string") { if (ucs2length(data) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + "", schemaPath: '#/oneOf/1/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: validate.schema.oneOf[1], data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/oneOf/1/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.oneOf[1].type, parentSchema: validate.schema.oneOf[1], data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; if (valid1 && prevValid0) valid0 = false; else { if (valid1) valid0 = prevValid0 = true; var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; var errs_3 = errors; if (Array.isArray(data)) { if (data.length < 1) { var err = { keyword: 'minItems', dataPath: (dataPath || '') + "", schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/minItems', params: { limit: 1 }, message: 'should NOT have less than 1 items', schema: 1, parentSchema: refVal[2], data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = true; if (data.length > 1) { var i = data.length, j; outer: for (; i--;) { for (j = i; j--;) { if (equal(data[i], data[j])) { valid3 = false; break outer; } } } } if (!valid3) { var err = { keyword: 'uniqueItems', dataPath: (dataPath || '') + "", schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/uniqueItems', params: { i: i, j: j }, message: 'should NOT have duplicate items (items ## ' + j + ' and ' + i + ' are identical)', schema: true, parentSchema: refVal[2], data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var errs__3 = errors; var valid3; for (var i3 = 0; i3 < data.length; i3++) { var data1 = data[i3]; var errs_4 = errors; if (typeof data1 === "string") { if (ucs2length(data1) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '[' + i3 + ']', schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[2].items, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '[' + i3 + ']', schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal[2].items.type, parentSchema: refVal[2].items, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid4 = errors === errs_4; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/definitions/common.nonEmptyArrayOfUniqueStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal[2].type, parentSchema: refVal[2], data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + "", schemaPath: '#/oneOf/2/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.oneOf[2].anyOf, parentSchema: validate.schema.oneOf[2], data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; if (valid1 && prevValid0) valid0 = false; else { if (valid1) valid0 = prevValid0 = true; var valid1 = true; if (valid1 && prevValid0) valid0 = false; else { if (valid1) valid0 = prevValid0 = true; } } } if (!valid0) { var err = { keyword: 'oneOf', dataPath: (dataPath || '') + "", schemaPath: '#/oneOf', params: {}, message: 'should match exactly one schema in oneOf', schema: validate.schema.oneOf, parentSchema: validate.schema, data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__0; if (vErrors !== null) { if (errs__0) vErrors.length = errs__0; else vErrors = null; } }
规则:
1.数据可以为字符串、对象、数组
2.字符串必须为非空字符串
3.数组必须是非空数组,元素必须是非空字符串且不能重复
4.如果是对象则至少要有2个键,键的规则满足2、3
refVal3
if ((data && typeof data === "object" && !Array.isArray(data))) { var errs__0 = errors; var valid1 = true; for (var key0 in data) { var isAdditional0 = !(false || validate.schema.properties[key0]); if (isAdditional0) { valid1 = false; var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + "", schemaPath: '#/additionalProperties', params: { additionalProperty: '' + key0 + '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema, data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } var data1 = data.exprContextCritical; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.exprContextCritical', schemaPath: '#/properties/exprContextCritical/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.exprContextCritical.type, parentSchema: validate.schema.properties.exprContextCritical, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.exprContextRecursive; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.exprContextRecursive', schemaPath: '#/properties/exprContextRecursive/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.exprContextRecursive.type, parentSchema: validate.schema.properties.exprContextRecursive, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } if (data.exprContextRegExp !== undefined) { var errs_1 = errors; var valid1 = errors === errs_1; } var data1 = data.exprContextRequest; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.exprContextRequest', schemaPath: '#/properties/exprContextRequest/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.exprContextRequest.type, parentSchema: validate.schema.properties.exprContextRequest, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.loaders; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; if (!refVal4(data1, (dataPath || '') + '.loaders', data, 'loaders', rootData)) { if (vErrors === null) vErrors = refVal4.errors; else vErrors = vErrors.concat(refVal4.errors); errors = vErrors.length; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.loaders', schemaPath: '#/properties/loaders/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.loaders.anyOf, parentSchema: validate.schema.properties.loaders, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } if (data.noParse !== undefined) { var errs_1 = errors; var valid1 = errors === errs_1; } if (data.rules !== undefined) { var errs_1 = errors; var errs_2 = errors; if (!refVal[4](data.rules, (dataPath || '') + '.rules', data, 'rules', rootData)) { if (vErrors === null) vErrors = refVal[4].errors; else vErrors = vErrors.concat(refVal[4].errors); errors = vErrors.length; } var valid2 = errors === errs_2; var valid1 = errors === errs_1; } var data1 = data.unknownContextCritical; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.unknownContextCritical', schemaPath: '#/properties/unknownContextCritical/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.unknownContextCritical.type, parentSchema: validate.schema.properties.unknownContextCritical, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.unknownContextRecursive; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.unknownContextRecursive', schemaPath: '#/properties/unknownContextRecursive/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.unknownContextRecursive.type, parentSchema: validate.schema.properties.unknownContextRecursive, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } if (data.unknownContextRegExp !== undefined) { var errs_1 = errors; var valid1 = errors === errs_1; } var data1 = data.unknownContextRequest; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.unknownContextRequest', schemaPath: '#/properties/unknownContextRequest/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.unknownContextRequest.type, parentSchema: validate.schema.properties.unknownContextRequest, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } if (data.unsafeCache !== undefined) { var errs_1 = errors; var valid1 = errors === errs_1; } var data1 = data.wrappedContextCritical; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.wrappedContextCritical', schemaPath: '#/properties/wrappedContextCritical/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.wrappedContextCritical.type, parentSchema: validate.schema.properties.wrappedContextCritical, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.wrappedContextRecursive; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.wrappedContextRecursive', schemaPath: '#/properties/wrappedContextRecursive/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.wrappedContextRecursive.type, parentSchema: validate.schema.properties.wrappedContextRecursive, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.strictExportPresence; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.strictExportPresence', schemaPath: '#/properties/strictExportPresence/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.strictExportPresence.type, parentSchema: validate.schema.properties.strictExportPresence, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.strictThisContextOnImports; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.strictThisContextOnImports', schemaPath: '#/properties/strictThisContextOnImports/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.strictThisContextOnImports.type, parentSchema: validate.schema.properties.strictThisContextOnImports, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.type, parentSchema: validate.schema, data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; }
规则:
1.检测了大量不知道的属性
2.loaders,rules属性调用refVal4校验
refVal4
if (Array.isArray(data)) { var errs__0 = errors; var valid0; for (var i0 = 0; i0 < data.length; i0++) { var data1 = data[i0]; var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; if (!refVal5(data1, (dataPath || '') + '[' + i0 + ']', data, i0, rootData)) { if (vErrors === null) vErrors = refVal5.errors; else vErrors = vErrors.concat(refVal5.errors); errors = vErrors.length; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '[' + i0 + ']', schemaPath: '#/items/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.items.anyOf, parentSchema: validate.schema.items, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/type', params: { type: 'array' }, message: 'should be array', schema: validate.schema.type, parentSchema: validate.schema, data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; }
规则:
1.必须为数组
2.数组元素调用refVal5校验
refVal5
if ((data && typeof data === "object" && !Array.isArray(data))) { var errs__0 = errors; var valid1 = true; for (var key0 in data) { var isAdditional0 = !(false || validate.schema.properties[key0]); if (isAdditional0) { valid1 = false; var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + "", schemaPath: '#/additionalProperties', params: { additionalProperty: '' + key0 + '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema, data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } var data1 = data.enforce; if (data1 !== undefined) { var errs_1 = errors; var schema1 = validate.schema.properties.enforce.enum; var valid1; valid1 = false; for (var i1 = 0; i1 < schema1.length; i1++) if (equal(data1, schema1[i1])) { valid1 = true; break; } if (!valid1) { var err = { keyword: 'enum', dataPath: (dataPath || '') + '.enforce', schemaPath: '#/properties/enforce/enum', params: { allowedValues: schema1 }, message: 'should be equal to one of the allowed values', schema: validate.schema.properties.enforce.enum, parentSchema: validate.schema.properties.enforce, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } if (data.exclude !== undefined) { var errs_1 = errors; var errs_2 = errors; if (!refVal6(data.exclude, (dataPath || '') + '.exclude', data, 'exclude', rootData)) { if (vErrors === null) vErrors = refVal6.errors; else vErrors = vErrors.concat(refVal6.errors); errors = vErrors.length; } var valid2 = errors === errs_2; var valid1 = errors === errs_1; } if (data.include !== undefined) { var errs_1 = errors; var errs_2 = errors; if (!refVal[6](data.include, (dataPath || '') + '.include', data, 'include', rootData)) { if (vErrors === null) vErrors = refVal[6].errors; else vErrors = vErrors.concat(refVal[6].errors); errors = vErrors.length; } var valid2 = errors === errs_2; var valid1 = errors === errs_1; } if (data.issuer !== undefined) { var errs_1 = errors; var errs_2 = errors; if (!refVal[6](data.issuer, (dataPath || '') + '.issuer', data, 'issuer', rootData)) { if (vErrors === null) vErrors = refVal[6].errors; else vErrors = vErrors.concat(refVal[6].errors); errors = vErrors.length; } var valid2 = errors === errs_2; var valid1 = errors === errs_1; } var data1 = data.loader; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; var errs_3 = errors; if (typeof data1 === "string") { if (ucs2length(data1) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.loader', schemaPath: '#/definitions/ruleSet-loader/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal7, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.loader', schemaPath: '#/definitions/ruleSet-loader/type', params: { type: 'string' }, message: 'should be string', schema: refVal7.type, parentSchema: refVal7, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var errs_2 = errors; if (!refVal8(data1, (dataPath || '') + '.loader', data, 'loader', rootData)) { if (vErrors === null) vErrors = refVal8.errors; else vErrors = vErrors.concat(refVal8.errors); errors = vErrors.length; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; } if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.loader', schemaPath: '#/properties/loader/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.loader.anyOf, parentSchema: validate.schema.properties.loader, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.loaders; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; if (!refVal[8](data1, (dataPath || '') + '.loaders', data, 'loaders', rootData)) { if (vErrors === null) vErrors = refVal[8].errors; else vErrors = vErrors.concat(refVal[8].errors); errors = vErrors.length; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.loaders', schemaPath: '#/properties/loaders/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.loaders.anyOf, parentSchema: validate.schema.properties.loaders, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.oneOf; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; if (!refVal[4](data1, (dataPath || '') + '.oneOf', data, 'oneOf', rootData)) { if (vErrors === null) vErrors = refVal[4].errors; else vErrors = vErrors.concat(refVal[4].errors); errors = vErrors.length; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.oneOf', schemaPath: '#/properties/oneOf/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.oneOf.anyOf, parentSchema: validate.schema.properties.oneOf, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.options; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; var errs_3 = errors; var errs__3 = errors; var valid3 = false; var errs_4 = errors; if ((!data1 || typeof data1 !== "object" || Array.isArray(data1))) { var err = { keyword: 'type', dataPath: (dataPath || '') + '.options', schemaPath: '#/definitions/ruleSet-query/anyOf/0/type', params: { type: 'object' }, message: 'should be object', schema: refVal9.anyOf[0].type, parentSchema: refVal9.anyOf[0], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid4 = errors === errs_4; valid3 = valid3 || valid4; if (!valid3) { var errs_4 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.options', schemaPath: '#/definitions/ruleSet-query/anyOf/1/type', params: { type: 'string' }, message: 'should be string', schema: refVal9.anyOf[1].type, parentSchema: refVal9.anyOf[1], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid4 = errors === errs_4; valid3 = valid3 || valid4; } if (!valid3) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.options', schemaPath: '#/definitions/ruleSet-query/anyOf', params: {}, message: 'should match some schema in anyOf', schema: refVal9.anyOf, parentSchema: refVal9, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__3; if (vErrors !== null) { if (errs__3) vErrors.length = errs__3; else vErrors = null; } } var valid3 = errors === errs_3; var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.options', schemaPath: '#/properties/options/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.options.anyOf, parentSchema: validate.schema.properties.options, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.parser; if (data1 !== undefined) { var errs_1 = errors; if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) { var errs__1 = errors; var valid2 = true; } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.parser', schemaPath: '#/properties/parser/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.properties.parser.type, parentSchema: validate.schema.properties.parser, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.query; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; var errs_3 = errors; var errs__3 = errors; var valid3 = false; var errs_4 = errors; if ((!data1 || typeof data1 !== "object" || Array.isArray(data1))) { var err = { keyword: 'type', dataPath: (dataPath || '') + '.query', schemaPath: '#/definitions/ruleSet-query/anyOf/0/type', params: { type: 'object' }, message: 'should be object', schema: refVal[9].anyOf[0].type, parentSchema: refVal[9].anyOf[0], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid4 = errors === errs_4; valid3 = valid3 || valid4; if (!valid3) { var errs_4 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.query', schemaPath: '#/definitions/ruleSet-query/anyOf/1/type', params: { type: 'string' }, message: 'should be string', schema: refVal[9].anyOf[1].type, parentSchema: refVal[9].anyOf[1], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid4 = errors === errs_4; valid3 = valid3 || valid4; } if (!valid3) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.query', schemaPath: '#/definitions/ruleSet-query/anyOf', params: {}, message: 'should match some schema in anyOf', schema: refVal[9].anyOf, parentSchema: refVal[9], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__3; if (vErrors !== null) { if (errs__3) vErrors.length = errs__3; else vErrors = null; } } var valid3 = errors === errs_3; var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.query', schemaPath: '#/properties/query/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.query.anyOf, parentSchema: validate.schema.properties.query, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } if (data.resource !== undefined) { var errs_1 = errors; var errs_2 = errors; if (!refVal[6](data.resource, (dataPath || '') + '.resource', data, 'resource', rootData)) { if (vErrors === null) vErrors = refVal[6].errors; else vErrors = vErrors.concat(refVal[6].errors); errors = vErrors.length; } var valid2 = errors === errs_2; var valid1 = errors === errs_1; } var data1 = data.resourceQuery; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; if (!refVal[6](data1, (dataPath || '') + '.resourceQuery', data, 'resourceQuery', rootData)) { if (vErrors === null) vErrors = refVal[6].errors; else vErrors = vErrors.concat(refVal[6].errors); errors = vErrors.length; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.resourceQuery', schemaPath: '#/properties/resourceQuery/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.resourceQuery.anyOf, parentSchema: validate.schema.properties.resourceQuery, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.compiler; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; if (!refVal[6](data1, (dataPath || '') + '.compiler', data, 'compiler', rootData)) { if (vErrors === null) vErrors = refVal[6].errors; else vErrors = vErrors.concat(refVal[6].errors); errors = vErrors.length; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.compiler', schemaPath: '#/properties/compiler/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.compiler.anyOf, parentSchema: validate.schema.properties.compiler, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.rules; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; if (!refVal[4](data1, (dataPath || '') + '.rules', data, 'rules', rootData)) { if (vErrors === null) vErrors = refVal[4].errors; else vErrors = vErrors.concat(refVal[4].errors); errors = vErrors.length; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.rules', schemaPath: '#/properties/rules/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.rules.anyOf, parentSchema: validate.schema.properties.rules, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } if (data.test !== undefined) { var errs_1 = errors; var errs_2 = errors; if (!refVal[6](data.test, (dataPath || '') + '.test', data, 'test', rootData)) { if (vErrors === null) vErrors = refVal[6].errors; else vErrors = vErrors.concat(refVal[6].errors); errors = vErrors.length; } var valid2 = errors === errs_2; var valid1 = errors === errs_1; } var data1 = data.use; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; if (!refVal[8](data1, (dataPath || '') + '.use', data, 'use', rootData)) { if (vErrors === null) vErrors = refVal[8].errors; else vErrors = vErrors.concat(refVal[8].errors); errors = vErrors.length; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.use', schemaPath: '#/properties/use/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.use.anyOf, parentSchema: validate.schema.properties.use, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.type, parentSchema: validate.schema, data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; }
规则:
1.必须为对象
2.exclude、include、test调用refVal6
3.loader为非空字符串
4.loaders调用refVal8
5.options必须为对象
6.rules调用refVal4
refVal6
var validate = (function(data, dataPath, parentData, parentDataProperty, rootData) { 'use strict'; validate.errors = null; return true; });
规则:
无
refVal8
var validate = (function(data, dataPath, parentData, parentDataProperty, rootData) { 'use strict'; validate.errors = null; return true; });
规则:
无
refVal10
if ((data && typeof data === "object" && !Array.isArray(data))) { var errs__0 = errors; var valid1 = true; for (var key0 in data) { var isAdditional0 = !(false || validate.schema.properties[key0]); if (isAdditional0) { valid1 = false; var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + "", schemaPath: '#/additionalProperties', params: { additionalProperty: '' + key0 + '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema, data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } var data1 = data.auxiliaryComment; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.auxiliaryComment', schemaPath: '#/properties/auxiliaryComment/anyOf/0/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.auxiliaryComment.anyOf[0].type, parentSchema: validate.schema.properties.auxiliaryComment.anyOf[0], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var errs_2 = errors; if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) { var errs__2 = errors; var valid3 = true; for (var key2 in data1) { var isAdditional2 = !(false || key2 == 'amd' || key2 == 'commonjs' || key2 == 'commonjs2' || key2 == 'root'); if (isAdditional2) { valid3 = false; var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + '.auxiliaryComment', schemaPath: '#/properties/auxiliaryComment/anyOf/1/additionalProperties', params: { additionalProperty: '' + key2 + '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema.properties.auxiliaryComment.anyOf[1], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } var data2 = data1.amd; if (data2 !== undefined) { var errs_3 = errors; if (typeof data2 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.auxiliaryComment.amd', schemaPath: '#/properties/auxiliaryComment/anyOf/1/properties/amd/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.amd.type, parentSchema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.amd, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; } var data2 = data1.commonjs; if (data2 !== undefined) { var errs_3 = errors; if (typeof data2 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.auxiliaryComment.commonjs', schemaPath: '#/properties/auxiliaryComment/anyOf/1/properties/commonjs/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.commonjs.type, parentSchema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.commonjs, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; } var data2 = data1.commonjs2; if (data2 !== undefined) { var errs_3 = errors; if (typeof data2 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.auxiliaryComment.commonjs2', schemaPath: '#/properties/auxiliaryComment/anyOf/1/properties/commonjs2/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.commonjs2.type, parentSchema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.commonjs2, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; } var data2 = data1.root; if (data2 !== undefined) { var errs_3 = errors; if (typeof data2 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.auxiliaryComment.root', schemaPath: '#/properties/auxiliaryComment/anyOf/1/properties/root/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.root.type, parentSchema: validate.schema.properties.auxiliaryComment.anyOf[1].properties.root, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.auxiliaryComment', schemaPath: '#/properties/auxiliaryComment/anyOf/1/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.properties.auxiliaryComment.anyOf[1].type, parentSchema: validate.schema.properties.auxiliaryComment.anyOf[1], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; } if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.auxiliaryComment', schemaPath: '#/properties/auxiliaryComment/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.auxiliaryComment.anyOf, parentSchema: validate.schema.properties.auxiliaryComment, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.chunkFilename; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.chunkFilename', schemaPath: '#/properties/chunkFilename/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.chunkFilename.type, parentSchema: validate.schema.properties.chunkFilename, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.crossOriginLoading; if (data1 !== undefined) { var errs_1 = errors; var schema1 = validate.schema.properties.crossOriginLoading.enum; var valid1; valid1 = false; for (var i1 = 0; i1 < schema1.length; i1++) if (equal(data1, schema1[i1])) { valid1 = true; break; } if (!valid1) { var err = { keyword: 'enum', dataPath: (dataPath || '') + '.crossOriginLoading', schemaPath: '#/properties/crossOriginLoading/enum', params: { allowedValues: schema1 }, message: 'should be equal to one of the allowed values', schema: validate.schema.properties.crossOriginLoading.enum, parentSchema: validate.schema.properties.crossOriginLoading, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.chunkLoadTimeout; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "number") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.chunkLoadTimeout', schemaPath: '#/properties/chunkLoadTimeout/type', params: { type: 'number' }, message: 'should be number', schema: validate.schema.properties.chunkLoadTimeout.type, parentSchema: validate.schema.properties.chunkLoadTimeout, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } if (data.devtoolFallbackModuleFilenameTemplate !== undefined) { var errs_1 = errors; var valid1 = errors === errs_1; } var data1 = data.devtoolLineToLine; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.devtoolLineToLine', schemaPath: '#/properties/devtoolLineToLine/anyOf/0/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.devtoolLineToLine.anyOf[0].type, parentSchema: validate.schema.properties.devtoolLineToLine.anyOf[0], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var errs_2 = errors; if ((!data1 || typeof data1 !== "object" || Array.isArray(data1))) { var err = { keyword: 'type', dataPath: (dataPath || '') + '.devtoolLineToLine', schemaPath: '#/properties/devtoolLineToLine/anyOf/1/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.properties.devtoolLineToLine.anyOf[1].type, parentSchema: validate.schema.properties.devtoolLineToLine.anyOf[1], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; } if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.devtoolLineToLine', schemaPath: '#/properties/devtoolLineToLine/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.devtoolLineToLine.anyOf, parentSchema: validate.schema.properties.devtoolLineToLine, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } if (data.devtoolModuleFilenameTemplate !== undefined) { var errs_1 = errors; var valid1 = errors === errs_1; } var data1 = data.filename; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.filename', schemaPath: '#/properties/filename/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.filename.type, parentSchema: validate.schema.properties.filename, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.hashDigest; if (data1 !== undefined) { var errs_1 = errors; var schema1 = validate.schema.properties.hashDigest.enum; var valid1; valid1 = false; for (var i1 = 0; i1 < schema1.length; i1++) if (equal(data1, schema1[i1])) { valid1 = true; break; } if (!valid1) { var err = { keyword: 'enum', dataPath: (dataPath || '') + '.hashDigest', schemaPath: '#/properties/hashDigest/enum', params: { allowedValues: schema1 }, message: 'should be equal to one of the allowed values', schema: validate.schema.properties.hashDigest.enum, parentSchema: validate.schema.properties.hashDigest, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.hashDigestLength; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 === "number") { if (data1 < 1 || data1 !== data1) { var err = { keyword: 'minimum', dataPath: (dataPath || '') + '.hashDigestLength', schemaPath: '#/properties/hashDigestLength/minimum', params: { comparison: '>=', limit: 1, exclusive: false }, message: 'should be >= 1', schema: 1, parentSchema: validate.schema.properties.hashDigestLength, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.hashDigestLength', schemaPath: '#/properties/hashDigestLength/type', params: { type: 'number' }, message: 'should be number', schema: validate.schema.properties.hashDigestLength.type, parentSchema: validate.schema.properties.hashDigestLength, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.hashFunction; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 === "string") { if (ucs2length(data1) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.hashFunction', schemaPath: '#/properties/hashFunction/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: validate.schema.properties.hashFunction, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.hashFunction', schemaPath: '#/properties/hashFunction/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.hashFunction.type, parentSchema: validate.schema.properties.hashFunction, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.hashSalt; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 === "string") { if (ucs2length(data1) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.hashSalt', schemaPath: '#/properties/hashSalt/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: validate.schema.properties.hashSalt, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.hashSalt', schemaPath: '#/properties/hashSalt/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.hashSalt.type, parentSchema: validate.schema.properties.hashSalt, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.hotUpdateChunkFilename; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.hotUpdateChunkFilename', schemaPath: '#/properties/hotUpdateChunkFilename/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.hotUpdateChunkFilename.type, parentSchema: validate.schema.properties.hotUpdateChunkFilename, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.hotUpdateFunction; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.hotUpdateFunction', schemaPath: '#/properties/hotUpdateFunction/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.hotUpdateFunction.type, parentSchema: validate.schema.properties.hotUpdateFunction, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.hotUpdateMainFilename; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.hotUpdateMainFilename', schemaPath: '#/properties/hotUpdateMainFilename/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.hotUpdateMainFilename.type, parentSchema: validate.schema.properties.hotUpdateMainFilename, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.jsonpFunction; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.jsonpFunction', schemaPath: '#/properties/jsonpFunction/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.jsonpFunction.type, parentSchema: validate.schema.properties.jsonpFunction, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.library; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.library', schemaPath: '#/properties/library/anyOf/0/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.library.anyOf[0].type, parentSchema: validate.schema.properties.library.anyOf[0], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var errs_2 = errors; if (Array.isArray(data1)) { var errs__2 = errors; var valid2; for (var i2 = 0; i2 < data1.length; i2++) { var data2 = data1[i2]; var errs_3 = errors; if (typeof data2 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.library[' + i2 + ']', schemaPath: '#/properties/library/anyOf/1/items/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.library.anyOf[1].items.type, parentSchema: validate.schema.properties.library.anyOf[1].items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.library', schemaPath: '#/properties/library/anyOf/1/type', params: { type: 'array' }, message: 'should be array', schema: validate.schema.properties.library.anyOf[1].type, parentSchema: validate.schema.properties.library.anyOf[1], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var errs_2 = errors; if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) { var errs__2 = errors; var valid3 = true; for (var key2 in data1) { var isAdditional2 = !(false || key2 == 'root' || key2 == 'amd' || key2 == 'commonjs'); if (isAdditional2) { valid3 = false; var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + '.library', schemaPath: '#/properties/library/anyOf/2/additionalProperties', params: { additionalProperty: '' + key2 + '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema.properties.library.anyOf[2], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } var data2 = data1.root; if (data2 !== undefined) { var errs_3 = errors; if (typeof data2 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.library.root', schemaPath: '#/properties/library/anyOf/2/properties/root/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.library.anyOf[2].properties.root.type, parentSchema: validate.schema.properties.library.anyOf[2].properties.root, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; } var data2 = data1.amd; if (data2 !== undefined) { var errs_3 = errors; if (typeof data2 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.library.amd', schemaPath: '#/properties/library/anyOf/2/properties/amd/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.library.anyOf[2].properties.amd.type, parentSchema: validate.schema.properties.library.anyOf[2].properties.amd, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; } var data2 = data1.commonjs; if (data2 !== undefined) { var errs_3 = errors; if (typeof data2 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.library.commonjs', schemaPath: '#/properties/library/anyOf/2/properties/commonjs/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.library.anyOf[2].properties.commonjs.type, parentSchema: validate.schema.properties.library.anyOf[2].properties.commonjs, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.library', schemaPath: '#/properties/library/anyOf/2/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.properties.library.anyOf[2].type, parentSchema: validate.schema.properties.library.anyOf[2], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; } } if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.library', schemaPath: '#/properties/library/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.library.anyOf, parentSchema: validate.schema.properties.library, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.libraryTarget; if (data1 !== undefined) { var errs_1 = errors; var schema1 = validate.schema.properties.libraryTarget.enum; var valid1; valid1 = false; for (var i1 = 0; i1 < schema1.length; i1++) if (equal(data1, schema1[i1])) { valid1 = true; break; } if (!valid1) { var err = { keyword: 'enum', dataPath: (dataPath || '') + '.libraryTarget', schemaPath: '#/properties/libraryTarget/enum', params: { allowedValues: schema1 }, message: 'should be equal to one of the allowed values', schema: validate.schema.properties.libraryTarget.enum, parentSchema: validate.schema.properties.libraryTarget, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.libraryExport; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.libraryExport', schemaPath: '#/properties/libraryExport/anyOf/0/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.libraryExport.anyOf[0].type, parentSchema: validate.schema.properties.libraryExport.anyOf[0], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var errs_2 = errors; var errs_3 = errors; if (Array.isArray(data1)) { var errs__3 = errors; var valid3; for (var i3 = 0; i3 < data1.length; i3++) { var data2 = data1[i3]; var errs_4 = errors; if (typeof data2 === "string") { if (ucs2length(data2) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.libraryExport[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal11.items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.libraryExport[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal11.items.type, parentSchema: refVal11.items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid4 = errors === errs_4; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.libraryExport', schemaPath: '#/definitions/common.arrayOfStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal11.type, parentSchema: refVal11, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; var valid2 = errors === errs_2; valid1 = valid1 || valid2; } if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.libraryExport', schemaPath: '#/properties/libraryExport/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.libraryExport.anyOf, parentSchema: validate.schema.properties.libraryExport, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.path; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.path', schemaPath: '#/properties/path/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.path.type, parentSchema: validate.schema.properties.path, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.pathinfo; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.pathinfo', schemaPath: '#/properties/pathinfo/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.pathinfo.type, parentSchema: validate.schema.properties.pathinfo, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.publicPath; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.publicPath', schemaPath: '#/properties/publicPath/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.publicPath.type, parentSchema: validate.schema.properties.publicPath, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.sourceMapFilename; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.sourceMapFilename', schemaPath: '#/properties/sourceMapFilename/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.sourceMapFilename.type, parentSchema: validate.schema.properties.sourceMapFilename, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.sourcePrefix; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.sourcePrefix', schemaPath: '#/properties/sourcePrefix/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.sourcePrefix.type, parentSchema: validate.schema.properties.sourcePrefix, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.strictModuleExceptionHandling; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.strictModuleExceptionHandling', schemaPath: '#/properties/strictModuleExceptionHandling/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.strictModuleExceptionHandling.type, parentSchema: validate.schema.properties.strictModuleExceptionHandling, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.umdNamedDefine; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.umdNamedDefine', schemaPath: '#/properties/umdNamedDefine/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.umdNamedDefine.type, parentSchema: validate.schema.properties.umdNamedDefine, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.type, parentSchema: validate.schema, data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; }
规则:
1.额外键检测
2.chunkFilename、filename、path、publicPath必须为字符串
3.crossOriginLoading必须是false、"anonymous"、"use-credentials"之一
4.chunkLoadTimeout必须是数字
refVal12
if ((data && typeof data === "object" && !Array.isArray(data))) { var errs__0 = errors; var valid1 = true; for (var key0 in data) { var isAdditional0 = !(false || validate.schema.properties[key0]); if (isAdditional0) { valid1 = false; var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + "", schemaPath: '#/additionalProperties', params: { additionalProperty: '' + key0 + '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema, data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } var data1 = data.alias; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) { var errs__2 = errors; var valid3 = true; for (var key2 in data1) { var data2 = data1[key2]; var errs_3 = errors; if (typeof data2 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.alias[\'' + key2 + '\']', schemaPath: '#/properties/alias/anyOf/0/additionalProperties/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.alias.anyOf[0].additionalProperties.type, parentSchema: validate.schema.properties.alias.anyOf[0].additionalProperties, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.alias', schemaPath: '#/properties/alias/anyOf/0/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.properties.alias.anyOf[0].type, parentSchema: validate.schema.properties.alias.anyOf[0], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var errs_2 = errors; if (Array.isArray(data1)) { var errs__2 = errors; var valid2; for (var i2 = 0; i2 < data1.length; i2++) { var data2 = data1[i2]; var errs_3 = errors; if ((data2 && typeof data2 === "object" && !Array.isArray(data2))) { var errs__3 = errors; var valid4 = true; for (var key3 in data2) { var isAdditional3 = !(false || key3 == 'alias' || key3 == 'name' || key3 == 'onlyModule'); if (isAdditional3) { valid4 = false; var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + '.alias[' + i2 + ']', schemaPath: '#/properties/alias/anyOf/1/items/additionalProperties', params: { additionalProperty: '' + key3 + '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema.properties.alias.anyOf[1].items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } var data3 = data2.alias; if (data3 !== undefined) { var errs_4 = errors; if (typeof data3 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.alias[' + i2 + '].alias', schemaPath: '#/properties/alias/anyOf/1/items/properties/alias/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.alias.anyOf[1].items.properties.alias.type, parentSchema: validate.schema.properties.alias.anyOf[1].items.properties.alias, data: data3 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid4 = errors === errs_4; } var data3 = data2.name; if (data3 !== undefined) { var errs_4 = errors; if (typeof data3 !== "string") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.alias[' + i2 + '].name', schemaPath: '#/properties/alias/anyOf/1/items/properties/name/type', params: { type: 'string' }, message: 'should be string', schema: validate.schema.properties.alias.anyOf[1].items.properties.name.type, parentSchema: validate.schema.properties.alias.anyOf[1].items.properties.name, data: data3 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid4 = errors === errs_4; } var data3 = data2.onlyModule; if (data3 !== undefined) { var errs_4 = errors; if (typeof data3 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.alias[' + i2 + '].onlyModule', schemaPath: '#/properties/alias/anyOf/1/items/properties/onlyModule/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.alias.anyOf[1].items.properties.onlyModule.type, parentSchema: validate.schema.properties.alias.anyOf[1].items.properties.onlyModule, data: data3 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid4 = errors === errs_4; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.alias[' + i2 + ']', schemaPath: '#/properties/alias/anyOf/1/items/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.properties.alias.anyOf[1].items.type, parentSchema: validate.schema.properties.alias.anyOf[1].items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.alias', schemaPath: '#/properties/alias/anyOf/1/type', params: { type: 'array' }, message: 'should be array', schema: validate.schema.properties.alias.anyOf[1].type, parentSchema: validate.schema.properties.alias.anyOf[1], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; } if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.alias', schemaPath: '#/properties/alias/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.alias.anyOf, parentSchema: validate.schema.properties.alias, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.aliasFields; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; var errs_3 = errors; if (Array.isArray(data1)) { var errs__3 = errors; var valid3; for (var i3 = 0; i3 < data1.length; i3++) { var data2 = data1[i3]; var errs_4 = errors; var errs__4 = errors; var valid4 = false; var errs_5 = errors; if (typeof data2 === "string") { if (ucs2length(data2) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.aliasFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/0/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal13.items.anyOf[0], data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.aliasFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/0/type', params: { type: 'string' }, message: 'should be string', schema: refVal13.items.anyOf[0].type, parentSchema: refVal13.items.anyOf[0], data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid5 = errors === errs_5; valid4 = valid4 || valid5; if (!valid4) { var errs_5 = errors; if (Array.isArray(data2)) { var errs__5 = errors; var valid5; for (var i5 = 0; i5 < data2.length; i5++) { var data3 = data2[i5]; var errs_6 = errors; if (typeof data3 === "string") { if (ucs2length(data3) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.aliasFields[' + i3 + '][' + i5 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/1/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal13.items.anyOf[1].items, data: data3 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.aliasFields[' + i3 + '][' + i5 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/1/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal13.items.anyOf[1].items.type, parentSchema: refVal13.items.anyOf[1].items, data: data3 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid6 = errors === errs_6; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.aliasFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/1/type', params: { type: 'array' }, message: 'should be array', schema: refVal13.items.anyOf[1].type, parentSchema: refVal13.items.anyOf[1], data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid5 = errors === errs_5; valid4 = valid4 || valid5; } if (!valid4) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.aliasFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf', params: {}, message: 'should match some schema in anyOf', schema: refVal13.items.anyOf, parentSchema: refVal13.items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__4; if (vErrors !== null) { if (errs__4) vErrors.length = errs__4; else vErrors = null; } } var valid4 = errors === errs_4; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.aliasFields', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal13.type, parentSchema: refVal13, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.aliasFields', schemaPath: '#/properties/aliasFields/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.aliasFields.anyOf, parentSchema: validate.schema.properties.aliasFields, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.cacheWithContext; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.cacheWithContext', schemaPath: '#/properties/cacheWithContext/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.cacheWithContext.type, parentSchema: validate.schema.properties.cacheWithContext, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.descriptionFiles; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; var errs_3 = errors; if (Array.isArray(data1)) { var errs__3 = errors; var valid3; for (var i3 = 0; i3 < data1.length; i3++) { var data2 = data1[i3]; var errs_4 = errors; if (typeof data2 === "string") { if (ucs2length(data2) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.descriptionFiles[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[11].items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.descriptionFiles[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal[11].items.type, parentSchema: refVal[11].items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid4 = errors === errs_4; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.descriptionFiles', schemaPath: '#/definitions/common.arrayOfStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal[11].type, parentSchema: refVal[11], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.descriptionFiles', schemaPath: '#/properties/descriptionFiles/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.descriptionFiles.anyOf, parentSchema: validate.schema.properties.descriptionFiles, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.enforceExtension; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.enforceExtension', schemaPath: '#/properties/enforceExtension/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.enforceExtension.type, parentSchema: validate.schema.properties.enforceExtension, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.enforceModuleExtension; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.enforceModuleExtension', schemaPath: '#/properties/enforceModuleExtension/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.enforceModuleExtension.type, parentSchema: validate.schema.properties.enforceModuleExtension, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.extensions; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; var errs_3 = errors; if (Array.isArray(data1)) { var errs__3 = errors; var valid3; for (var i3 = 0; i3 < data1.length; i3++) { var data2 = data1[i3]; var errs_4 = errors; if (typeof data2 === "string") { if (ucs2length(data2) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.extensions[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[11].items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.extensions[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal[11].items.type, parentSchema: refVal[11].items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid4 = errors === errs_4; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.extensions', schemaPath: '#/definitions/common.arrayOfStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal[11].type, parentSchema: refVal[11], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.extensions', schemaPath: '#/properties/extensions/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.extensions.anyOf, parentSchema: validate.schema.properties.extensions, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.mainFields; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; var errs_3 = errors; if (Array.isArray(data1)) { var errs__3 = errors; var valid3; for (var i3 = 0; i3 < data1.length; i3++) { var data2 = data1[i3]; var errs_4 = errors; var errs__4 = errors; var valid4 = false; var errs_5 = errors; if (typeof data2 === "string") { if (ucs2length(data2) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.mainFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/0/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[13].items.anyOf[0], data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.mainFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/0/type', params: { type: 'string' }, message: 'should be string', schema: refVal[13].items.anyOf[0].type, parentSchema: refVal[13].items.anyOf[0], data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid5 = errors === errs_5; valid4 = valid4 || valid5; if (!valid4) { var errs_5 = errors; if (Array.isArray(data2)) { var errs__5 = errors; var valid5; for (var i5 = 0; i5 < data2.length; i5++) { var data3 = data2[i5]; var errs_6 = errors; if (typeof data3 === "string") { if (ucs2length(data3) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.mainFields[' + i3 + '][' + i5 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/1/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[13].items.anyOf[1].items, data: data3 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.mainFields[' + i3 + '][' + i5 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/1/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal[13].items.anyOf[1].items.type, parentSchema: refVal[13].items.anyOf[1].items, data: data3 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid6 = errors === errs_6; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.mainFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf/1/type', params: { type: 'array' }, message: 'should be array', schema: refVal[13].items.anyOf[1].type, parentSchema: refVal[13].items.anyOf[1], data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid5 = errors === errs_5; valid4 = valid4 || valid5; } if (!valid4) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.mainFields[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/items/anyOf', params: {}, message: 'should match some schema in anyOf', schema: refVal[13].items.anyOf, parentSchema: refVal[13].items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__4; if (vErrors !== null) { if (errs__4) vErrors.length = errs__4; else vErrors = null; } } var valid4 = errors === errs_4; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.mainFields', schemaPath: '#/definitions/common.arrayOfStringOrStringArrayValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal[13].type, parentSchema: refVal[13], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.mainFields', schemaPath: '#/properties/mainFields/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.mainFields.anyOf, parentSchema: validate.schema.properties.mainFields, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.mainFiles; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; var errs_3 = errors; if (Array.isArray(data1)) { var errs__3 = errors; var valid3; for (var i3 = 0; i3 < data1.length; i3++) { var data2 = data1[i3]; var errs_4 = errors; if (typeof data2 === "string") { if (ucs2length(data2) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.mainFiles[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[11].items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.mainFiles[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal[11].items.type, parentSchema: refVal[11].items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid4 = errors === errs_4; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.mainFiles', schemaPath: '#/definitions/common.arrayOfStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal[11].type, parentSchema: refVal[11], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.mainFiles', schemaPath: '#/properties/mainFiles/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.mainFiles.anyOf, parentSchema: validate.schema.properties.mainFiles, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.moduleExtensions; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; var errs_3 = errors; if (Array.isArray(data1)) { var errs__3 = errors; var valid3; for (var i3 = 0; i3 < data1.length; i3++) { var data2 = data1[i3]; var errs_4 = errors; if (typeof data2 === "string") { if (ucs2length(data2) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.moduleExtensions[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[11].items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.moduleExtensions[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal[11].items.type, parentSchema: refVal[11].items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid4 = errors === errs_4; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.moduleExtensions', schemaPath: '#/definitions/common.arrayOfStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal[11].type, parentSchema: refVal[11], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.moduleExtensions', schemaPath: '#/properties/moduleExtensions/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.moduleExtensions.anyOf, parentSchema: validate.schema.properties.moduleExtensions, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.modules; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; var errs_3 = errors; if (Array.isArray(data1)) { var errs__3 = errors; var valid3; for (var i3 = 0; i3 < data1.length; i3++) { var data2 = data1[i3]; var errs_4 = errors; if (typeof data2 === "string") { if (ucs2length(data2) < 1) { var err = { keyword: 'minLength', dataPath: (dataPath || '') + '.modules[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/minLength', params: { limit: 1 }, message: 'should NOT be shorter than 1 characters', schema: 1, parentSchema: refVal[11].items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.modules[' + i3 + ']', schemaPath: '#/definitions/common.arrayOfStringValues/items/type', params: { type: 'string' }, message: 'should be string', schema: refVal[11].items.type, parentSchema: refVal[11].items, data: data2 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid4 = errors === errs_4; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.modules', schemaPath: '#/definitions/common.arrayOfStringValues/type', params: { type: 'array' }, message: 'should be array', schema: refVal[11].type, parentSchema: refVal[11], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid3 = errors === errs_3; var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.modules', schemaPath: '#/properties/modules/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.modules.anyOf, parentSchema: validate.schema.properties.modules, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.plugins; if (data1 !== undefined) { var errs_1 = errors; if (!Array.isArray(data1)) { var err = { keyword: 'type', dataPath: (dataPath || '') + '.plugins', schemaPath: '#/properties/plugins/type', params: { type: 'array' }, message: 'should be array', schema: validate.schema.properties.plugins.type, parentSchema: validate.schema.properties.plugins, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.symlinks; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.symlinks', schemaPath: '#/properties/symlinks/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.symlinks.type, parentSchema: validate.schema.properties.symlinks, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } var data1 = data.unsafeCache; if (data1 !== undefined) { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.unsafeCache', schemaPath: '#/properties/unsafeCache/anyOf/0/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.unsafeCache.anyOf[0].type, parentSchema: validate.schema.properties.unsafeCache.anyOf[0], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { var errs_2 = errors; if ((data1 && typeof data1 === "object" && !Array.isArray(data1))) { var errs__2 = errors; var valid3 = true; } else { var err = { keyword: 'type', dataPath: (dataPath || '') + '.unsafeCache', schemaPath: '#/properties/unsafeCache/anyOf/1/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.properties.unsafeCache.anyOf[1].type, parentSchema: validate.schema.properties.unsafeCache.anyOf[1], data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid2 = errors === errs_2; valid1 = valid1 || valid2; } if (!valid1) { var err = { keyword: 'anyOf', dataPath: (dataPath || '') + '.unsafeCache', schemaPath: '#/properties/unsafeCache/anyOf', params: {}, message: 'should match some schema in anyOf', schema: validate.schema.properties.unsafeCache.anyOf, parentSchema: validate.schema.properties.unsafeCache, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; } var data1 = data.useSyncFileSystemCalls; if (data1 !== undefined) { var errs_1 = errors; if (typeof data1 !== "boolean") { var err = { keyword: 'type', dataPath: (dataPath || '') + '.useSyncFileSystemCalls', schemaPath: '#/properties/useSyncFileSystemCalls/type', params: { type: 'boolean' }, message: 'should be boolean', schema: validate.schema.properties.useSyncFileSystemCalls.type, parentSchema: validate.schema.properties.useSyncFileSystemCalls, data: data1 }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } var valid1 = errors === errs_1; } } else { var err = { keyword: 'type', dataPath: (dataPath || '') + "", schemaPath: '#/type', params: { type: 'object' }, message: 'should be object', schema: validate.schema.type, parentSchema: validate.schema, data: data }; if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; }
规则:
1.必须是对象
2.额外键检测
3.alias可以是对象、数组
4.alias为数组时,数组元素必须是对象,且键必须为alias、name、onlyModule之一
5.键为alias、name的值必须是字符串,键为onlyModule的值必须为布尔值
6.extensions必须是数组,数组元素必须是非空字符串
由于可选参数过于庞大,所以的代码只展示常用的属性校验,剔除大量陌生属性,不然实在是太长了!!!!!!!!
1、rootObject
首先是根对象的检测:
// 对象判断 if ((data && typeof data === "object" && !Array.isArray(data))) { var errs__0 = errors; var valid1 = true; // 遍历key for (var key0 in data) { // 这里检测属性中是否有检测范围外的键 var isAdditional0 = !(false || validate.schema.properties[key0]); if (isAdditional0) { valid1 = false; // 生成报错信息 var err = { keyword: 'additionalProperties', dataPath: (dataPath || '') + "", schemaPath: '#/additionalProperties', params: { additionalProperty: '' + key0 + '' }, message: 'should NOT have additional properties', schema: false, parentSchema: validate.schema, data: data }; // 第一次产生错误时初始化vErrors为数组 if (vErrors === null) vErrors = [err]; else vErrors.push(err); errors++; } } } else{ /*添加错误*/ }
这里还有一个validate.schema.properties对象,通过翻源码找到了定义:
一句话概括就是,在根对象中会检测是否有多余的键,可以测试一下:
const validate = ajv.compile(json); const valid = validate({ "unexpectedKey":0, }); console.log(validate.errors);
输出内容如下:
2、devServer
var data1 = data.devServer; // 存在键就继续检测 // 由于是非必须项 所以没有也不报错 if (data1 !== undefined) { var errs_1 = errors; // 检测是是对象 if ((!data1 || typeof data1 !== "object" || Array.isArray(data1))) { // 生成报错信息 } // 如果检测后总错误数量不变 说明通过 var valid1 = errors === errs_1; }
一句话概括:如果存在该键则必须为对象。
3、devtool
var data1 = data.devtool; if (data1 !== undefined) { var valid1 = false; // 标记初始值 var errs_1 = errors; // 用于记录错误 var errs__1 = errors; var errs_2 = errors; // 判断字符串 if (typeof data1 !== "string") { /*添加错误*/ } var valid2 = errors === errs_2; valid1 = valid1 || valid2; // 如果上面报错进入这里 if (!valid1) { var errs_2 = errors; // 获取枚举数组 var schema2 = validate.schema.properties.devtool.anyOf[1].enum; var valid2; valid2 = false; // 遍历判断是否匹配元素 for (var i2 = 0; i2 < schema2.length; i2++) if (equal(data1, schema2[i2])) { valid2 = true; break; } if (!valid2) { /*添加错误*/ } var valid2 = errors === errs_2; valid1 = valid1 || valid2; } // 即非字符串也不是枚举数组元素 if (!valid1) { /*添加错误*/ } // 如果有一个符合就回滚错误数量 验证通过 else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; }
其中枚举数组如图:
一句话概括:devtool可以为字符串或者false。
4、entry
var data1 = data.entry; // 检测键是否存在 if (data1 === undefined) { /*添加错误*/ } else { var errs_1 = errors; var errs__1 = errors; var valid1 = false; var errs_2 = errors; // refVal1 if (!refVal1(data1, (dataPath || '') + '.entry', data, 'entry', rootData)) { /*添加错误*/ } var valid2 = errors === errs_2; valid1 = valid1 || valid2; if (!valid1) { /*添加错误*/ } // 通过 else { errors = errs__1; if (vErrors !== null) { if (errs__1) vErrors.length = errs__1; else vErrors = null; } } var valid1 = errors === errs_1; }
调用了refVal1校验器,不愿意看上面的代码可以直接看规则。
5、module => refVal3
6、output => refVal10
7、plugins
var data1 = data.plugins; if (data1 !== undefined) { var errs_1 = errors; // 必须是数组 if (!Array.isArray(data1)) { /**/ } var valid1 = errors === errs_1; }
8、resolve => refVal12
真是又臭又长,再返回validate校验函数后,会进行校验 :
const valid = validate(options); return valid ? [] : filterErrors(validate.errors);
根据是否有错误返回true或false,由于在检测的时候已经对错误进行了收集,所以可以直接从 validate.errors 获取,这里的过滤就不看了,恶心的不行。
然后会返回到webpack主函数:
const webpackOptionsValidationErrors = validateSchema(webpackOptionsSchema, options); if (webpackOptionsValidationErrors.length) { throw new WebpackOptionsValidationError(webpackOptionsValidationErrors); }
根据 webpackOptionsValidationErrors 的长度来判断是否有错误,有错则抛出并中止编译。
完事!
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
- 浅析XMLHttpRequest的缓存问题 2020-02-25
- webpack打包配置禁止html标签全部转为小写 2019-08-14
- 入门webpack,看这篇就够了 2019-08-14
- image-webpack-loader包安装报错解决 2019-08-14
- Vue学习之webpack中使用vue(十七) 2019-08-14
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash