1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.validate = void 0;
|
4 | var utils_1 = require("./utils");
|
5 | var rules = new Map();
|
6 | rules.set('Enum members and tsEnumNames must be of the same length', function (schema) {
|
7 | if (schema.enum && schema.tsEnumNames && schema.enum.length !== schema.tsEnumNames.length) {
|
8 | return false;
|
9 | }
|
10 | });
|
11 | rules.set('tsEnumNames must be an array of strings', function (schema) {
|
12 | if (schema.tsEnumNames && schema.tsEnumNames.some(function (_) { return typeof _ !== 'string'; })) {
|
13 | return false;
|
14 | }
|
15 | });
|
16 | rules.set('When both maxItems and minItems are present, maxItems >= minItems', function (schema) {
|
17 | var maxItems = schema.maxItems, minItems = schema.minItems;
|
18 | if (typeof maxItems === 'number' && typeof minItems === 'number') {
|
19 | return maxItems >= minItems;
|
20 | }
|
21 | });
|
22 | rules.set('When maxItems exists, maxItems >= 0', function (schema) {
|
23 | var maxItems = schema.maxItems;
|
24 | if (typeof maxItems === 'number') {
|
25 | return maxItems >= 0;
|
26 | }
|
27 | });
|
28 | rules.set('When minItems exists, minItems >= 0', function (schema) {
|
29 | var minItems = schema.minItems;
|
30 | if (typeof minItems === 'number') {
|
31 | return minItems >= 0;
|
32 | }
|
33 | });
|
34 | function validate(schema, filename) {
|
35 | var errors = [];
|
36 | rules.forEach(function (rule, ruleName) {
|
37 | utils_1.mapDeep(schema, function (schema, key) {
|
38 | if (rule(schema) === false) {
|
39 | errors.push("Error at key \"" + key + "\" in file \"" + filename + "\": " + ruleName);
|
40 | }
|
41 | return schema;
|
42 | });
|
43 | });
|
44 | return errors;
|
45 | }
|
46 | exports.validate = validate;
|
47 |
|
\ | No newline at end of file |