fixes for RegExp in schema

This commit is contained in:
Tobias Koppers 2018-09-21 12:14:33 +02:00
parent 8b489f1c1b
commit 72c63ba91c
5 changed files with 41 additions and 17 deletions

View File

@ -122,7 +122,8 @@
}, },
{ {
"description": "Every matched dependency becomes external.", "description": "Every matched dependency becomes external.",
"instanceof": "RegExp" "instanceof": "RegExp",
"tsType": "RegExp"
} }
] ]
}, },
@ -157,7 +158,8 @@
"FilterItemTypes": { "FilterItemTypes": {
"anyOf": [ "anyOf": [
{ {
"instanceof": "RegExp" "instanceof": "RegExp",
"tsType": "RegExp"
}, },
{ {
"type": "string" "type": "string"
@ -238,7 +240,8 @@
"type": "boolean" "type": "boolean"
}, },
{ {
"instanceof": "RegExp" "instanceof": "RegExp",
"tsType": "RegExp"
} }
] ]
}, },
@ -253,12 +256,14 @@
"type": "array", "type": "array",
"items": { "items": {
"description": "A regular expression, when matched the module is not parsed", "description": "A regular expression, when matched the module is not parsed",
"instanceof": "RegExp" "instanceof": "RegExp",
"tsType": "RegExp"
}, },
"minItems": 1 "minItems": 1
}, },
{ {
"instanceof": "RegExp" "instanceof": "RegExp",
"tsType": "RegExp"
}, },
{ {
"instanceof": "Function", "instanceof": "Function",
@ -310,7 +315,8 @@
"type": "boolean" "type": "boolean"
}, },
{ {
"instanceof": "RegExp" "instanceof": "RegExp",
"tsType": "RegExp"
} }
] ]
}, },
@ -340,7 +346,8 @@
}, },
"wrappedContextRegExp": { "wrappedContextRegExp": {
"description": "Set the inner regular expression for partial dynamic dependencies", "description": "Set the inner regular expression for partial dynamic dependencies",
"instanceof": "RegExp" "instanceof": "RegExp",
"tsType": "RegExp"
} }
} }
}, },
@ -554,7 +561,8 @@
"type": "string" "type": "string"
}, },
{ {
"instanceof": "RegExp" "instanceof": "RegExp",
"tsType": "RegExp"
}, },
{ {
"type": "object", "type": "object",
@ -642,13 +650,15 @@
"description": "Assign modules to a cache group by module name", "description": "Assign modules to a cache group by module name",
"oneOf": [ "oneOf": [
{ {
"instanceof": "Function" "instanceof": "Function",
"tsType": "Function"
}, },
{ {
"type": "string" "type": "string"
}, },
{ {
"instanceof": "RegExp" "instanceof": "RegExp",
"tsType": "RegExp"
} }
] ]
}, },
@ -663,7 +673,8 @@
"type": "string" "type": "string"
}, },
{ {
"instanceof": "RegExp" "instanceof": "RegExp",
"tsType": "RegExp"
} }
] ]
} }
@ -1210,7 +1221,8 @@
"RuleSetCondition": { "RuleSetCondition": {
"anyOf": [ "anyOf": [
{ {
"instanceof": "RegExp" "instanceof": "RegExp",
"tsType": "RegExp"
}, },
{ {
"type": "string", "type": "string",

View File

@ -8,7 +8,8 @@
"Rule": { "Rule": {
"oneOf": [ "oneOf": [
{ {
"instanceof": "RegExp" "instanceof": "RegExp",
"tsType": "RegExp"
}, },
{ {
"type": "string", "type": "string",

View File

@ -7,11 +7,13 @@
"properties": { "properties": {
"contextRegExp": { "contextRegExp": {
"description": "A RegExp to test the context (directory) against", "description": "A RegExp to test the context (directory) against",
"instanceof": "RegExp" "instanceof": "RegExp",
"tsType": "RegExp"
}, },
"resourceRegExp": { "resourceRegExp": {
"description": "A RegExp to test the request against", "description": "A RegExp to test the request against",
"instanceof": "RegExp" "instanceof": "RegExp",
"tsType": "RegExp"
} }
} }
}, },

View File

@ -3,7 +3,8 @@
"rule": { "rule": {
"oneOf": [ "oneOf": [
{ {
"instanceof": "RegExp" "instanceof": "RegExp",
"tsType": "RegExp"
}, },
{ {
"type": "string", "type": "string",

View File

@ -76,7 +76,7 @@ describe("Schemas", () => {
} }
}); });
if (Object.keys(item).indexOf("$ref") >= 0) { if ("$ref" in item) {
it("should not have other properties next to $ref", () => { it("should not have other properties next to $ref", () => {
const otherProperties = Object.keys(item).filter( const otherProperties = Object.keys(item).filter(
p => p !== "$ref" p => p !== "$ref"
@ -91,6 +91,14 @@ describe("Schemas", () => {
}); });
} }
if ("instanceof" in item) {
it("should have tsType specified when using instanceof", () => {
if (!("tsType" in item)) {
throw new Error("When using instanceof, tsType is required");
}
});
}
arrayProperties.forEach(prop => { arrayProperties.forEach(prop => {
if (prop in item) { if (prop in item) {
describe(prop, () => { describe(prop, () => {