@eventvisor/core 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +9 -0
- package/jest.config.js +4 -0
- package/lib/builder/buildProject.d.ts +21 -0
- package/lib/builder/buildProject.js +153 -0
- package/lib/builder/buildProject.js.map +1 -0
- package/lib/builder/hashes.d.ts +2 -0
- package/lib/builder/hashes.js +59 -0
- package/lib/builder/hashes.js.map +1 -0
- package/lib/builder/index.d.ts +1 -0
- package/lib/builder/index.js +18 -0
- package/lib/builder/index.js.map +1 -0
- package/lib/cli/cli.d.ts +26 -0
- package/lib/cli/cli.js +69 -0
- package/lib/cli/cli.js.map +1 -0
- package/lib/cli/index.d.ts +1 -0
- package/lib/cli/index.js +18 -0
- package/lib/cli/index.js.map +1 -0
- package/lib/cli/plugins.d.ts +4 -0
- package/lib/cli/plugins.js +12 -0
- package/lib/cli/plugins.js.map +1 -0
- package/lib/config/index.d.ts +2 -0
- package/lib/config/index.js +19 -0
- package/lib/config/index.js.map +1 -0
- package/lib/config/parsers.d.ts +15 -0
- package/lib/config/parsers.js +65 -0
- package/lib/config/parsers.js.map +1 -0
- package/lib/config/projectConfig.d.ts +42 -0
- package/lib/config/projectConfig.js +137 -0
- package/lib/config/projectConfig.js.map +1 -0
- package/lib/datasource/adapter.d.ts +16 -0
- package/lib/datasource/adapter.js +7 -0
- package/lib/datasource/adapter.js.map +1 -0
- package/lib/datasource/datasource.d.ts +48 -0
- package/lib/datasource/datasource.js +117 -0
- package/lib/datasource/datasource.js.map +1 -0
- package/lib/datasource/filesystemAdapter.d.ts +29 -0
- package/lib/datasource/filesystemAdapter.js +192 -0
- package/lib/datasource/filesystemAdapter.js.map +1 -0
- package/lib/datasource/index.d.ts +3 -0
- package/lib/datasource/index.js +20 -0
- package/lib/datasource/index.js.map +1 -0
- package/lib/dependencies.d.ts +11 -0
- package/lib/dependencies.js +3 -0
- package/lib/dependencies.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +21 -0
- package/lib/index.js.map +1 -0
- package/lib/index.spec.d.ts +0 -0
- package/lib/index.spec.js +6 -0
- package/lib/index.spec.js.map +1 -0
- package/lib/init/index.d.ts +8 -0
- package/lib/init/index.js +90 -0
- package/lib/init/index.js.map +1 -0
- package/lib/linter/attributeSchema.d.ts +5 -0
- package/lib/linter/attributeSchema.js +55 -0
- package/lib/linter/attributeSchema.js.map +1 -0
- package/lib/linter/conditionsSchema.d.ts +303 -0
- package/lib/linter/conditionsSchema.js +106 -0
- package/lib/linter/conditionsSchema.js.map +1 -0
- package/lib/linter/destinationSchema.d.ts +5 -0
- package/lib/linter/destinationSchema.js +57 -0
- package/lib/linter/destinationSchema.js.map +1 -0
- package/lib/linter/effectSchema.d.ts +1257 -0
- package/lib/linter/effectSchema.js +77 -0
- package/lib/linter/effectSchema.js.map +1 -0
- package/lib/linter/eventSchema.d.ts +5 -0
- package/lib/linter/eventSchema.js +70 -0
- package/lib/linter/eventSchema.js.map +1 -0
- package/lib/linter/index.d.ts +1 -0
- package/lib/linter/index.js +18 -0
- package/lib/linter/index.js.map +1 -0
- package/lib/linter/jsonSchema.d.ts +25 -0
- package/lib/linter/jsonSchema.js +487 -0
- package/lib/linter/jsonSchema.js.map +1 -0
- package/lib/linter/jsonSchema.spec.d.ts +1 -0
- package/lib/linter/jsonSchema.spec.js +875 -0
- package/lib/linter/jsonSchema.spec.js.map +1 -0
- package/lib/linter/lintProject.d.ts +2 -0
- package/lib/linter/lintProject.js +141 -0
- package/lib/linter/lintProject.js.map +1 -0
- package/lib/linter/persistSchema.d.ts +609 -0
- package/lib/linter/persistSchema.js +52 -0
- package/lib/linter/persistSchema.js.map +1 -0
- package/lib/linter/printError.d.ts +9 -0
- package/lib/linter/printError.js +75 -0
- package/lib/linter/printError.js.map +1 -0
- package/lib/linter/sampleSchema.d.ts +331 -0
- package/lib/linter/sampleSchema.js +70 -0
- package/lib/linter/sampleSchema.js.map +1 -0
- package/lib/linter/sourceSchema.d.ts +11 -0
- package/lib/linter/sourceSchema.js +73 -0
- package/lib/linter/sourceSchema.js.map +1 -0
- package/lib/linter/tagsSchema.d.ts +3 -0
- package/lib/linter/tagsSchema.js +44 -0
- package/lib/linter/tagsSchema.js.map +1 -0
- package/lib/linter/testSchema.d.ts +5 -0
- package/lib/linter/testSchema.js +44 -0
- package/lib/linter/testSchema.js.map +1 -0
- package/lib/linter/transformsSchema.d.ts +29 -0
- package/lib/linter/transformsSchema.js +66 -0
- package/lib/linter/transformsSchema.js.map +1 -0
- package/lib/tester/createTestInstance.d.ts +16 -0
- package/lib/tester/createTestInstance.js +158 -0
- package/lib/tester/createTestInstance.js.map +1 -0
- package/lib/tester/executeTest.d.ts +24 -0
- package/lib/tester/executeTest.js +305 -0
- package/lib/tester/executeTest.js.map +1 -0
- package/lib/tester/index.d.ts +1 -0
- package/lib/tester/index.js +18 -0
- package/lib/tester/index.js.map +1 -0
- package/lib/tester/printTestResult.d.ts +10 -0
- package/lib/tester/printTestResult.js +80 -0
- package/lib/tester/printTestResult.js.map +1 -0
- package/lib/tester/testProject.d.ts +12 -0
- package/lib/tester/testProject.js +93 -0
- package/lib/tester/testProject.js.map +1 -0
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +18 -0
- package/lib/utils/index.js.map +1 -0
- package/lib/utils/prettyDuration.d.ts +1 -0
- package/lib/utils/prettyDuration.js +27 -0
- package/lib/utils/prettyDuration.js.map +1 -0
- package/package.json +42 -0
- package/src/builder/buildProject.ts +222 -0
- package/src/builder/hashes.ts +30 -0
- package/src/builder/index.ts +1 -0
- package/src/cli/cli.ts +110 -0
- package/src/cli/index.ts +1 -0
- package/src/cli/plugins.ts +13 -0
- package/src/config/index.ts +2 -0
- package/src/config/parsers.ts +40 -0
- package/src/config/projectConfig.ts +158 -0
- package/src/datasource/adapter.ts +23 -0
- package/src/datasource/datasource.ts +164 -0
- package/src/datasource/filesystemAdapter.ts +206 -0
- package/src/datasource/index.ts +3 -0
- package/src/dependencies.ts +13 -0
- package/src/index.spec.ts +5 -0
- package/src/index.ts +4 -0
- package/src/init/index.ts +65 -0
- package/src/linter/attributeSchema.ts +23 -0
- package/src/linter/conditionsSchema.ts +89 -0
- package/src/linter/destinationSchema.ts +25 -0
- package/src/linter/effectSchema.ts +49 -0
- package/src/linter/eventSchema.ts +40 -0
- package/src/linter/index.ts +1 -0
- package/src/linter/jsonSchema.spec.ts +934 -0
- package/src/linter/jsonSchema.ts +533 -0
- package/src/linter/lintProject.ts +182 -0
- package/src/linter/persistSchema.ts +21 -0
- package/src/linter/printError.ts +50 -0
- package/src/linter/sampleSchema.ts +45 -0
- package/src/linter/sourceSchema.ts +42 -0
- package/src/linter/tagsSchema.ts +12 -0
- package/src/linter/testSchema.ts +9 -0
- package/src/linter/transformsSchema.ts +35 -0
- package/src/tester/createTestInstance.ts +209 -0
- package/src/tester/executeTest.ts +436 -0
- package/src/tester/index.ts +1 -0
- package/src/tester/printTestResult.ts +60 -0
- package/src/tester/testProject.ts +129 -0
- package/src/utils/index.ts +1 -0
- package/src/utils/prettyDuration.ts +27 -0
- package/tsconfig.cjs.json +11 -0
|
@@ -0,0 +1,875 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsonSchema_1 = require("./jsonSchema");
|
|
4
|
+
describe("JSON Schema Validator", () => {
|
|
5
|
+
describe("Basic Schema Structure", () => {
|
|
6
|
+
it("should validate a valid empty schema", () => {
|
|
7
|
+
const schema = {};
|
|
8
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
9
|
+
expect(result.valid).toBe(true);
|
|
10
|
+
expect(result.errors).toHaveLength(0);
|
|
11
|
+
});
|
|
12
|
+
it("should reject non-object schemas", () => {
|
|
13
|
+
const schema = "not an object";
|
|
14
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
15
|
+
expect(result.valid).toBe(false);
|
|
16
|
+
expect(result.errors).toHaveLength(1);
|
|
17
|
+
expect(result.errors[0].code).toBe("INVALID_SCHEMA_TYPE");
|
|
18
|
+
});
|
|
19
|
+
it("should reject null schemas", () => {
|
|
20
|
+
const schema = null;
|
|
21
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
22
|
+
expect(result.valid).toBe(false);
|
|
23
|
+
expect(result.errors).toHaveLength(1);
|
|
24
|
+
expect(result.errors[0].code).toBe("INVALID_SCHEMA_TYPE");
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
describe("Type Constraints", () => {
|
|
28
|
+
it("should validate valid types", () => {
|
|
29
|
+
const validTypes = ["object", "array", "string", "number", "integer", "boolean", "null"];
|
|
30
|
+
for (const type of validTypes) {
|
|
31
|
+
const schema = { type };
|
|
32
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
33
|
+
expect(result.valid).toBe(true);
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
it("should reject invalid types", () => {
|
|
37
|
+
const schema = { type: "invalid_type" };
|
|
38
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
39
|
+
expect(result.valid).toBe(false);
|
|
40
|
+
expect(result.errors).toHaveLength(1);
|
|
41
|
+
expect(result.errors[0].code).toBe("INVALID_TYPE");
|
|
42
|
+
});
|
|
43
|
+
it("should validate enum values match declared type", () => {
|
|
44
|
+
const schema = {
|
|
45
|
+
type: "string",
|
|
46
|
+
enum: ["valid", "also_valid", 123], // 123 doesn't match string type
|
|
47
|
+
};
|
|
48
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
49
|
+
expect(result.valid).toBe(false);
|
|
50
|
+
expect(result.errors).toHaveLength(1);
|
|
51
|
+
expect(result.errors[0].code).toBe("TYPE_MISMATCH_IN_ENUM");
|
|
52
|
+
expect(result.errors[0].path).toEqual(["enum", "2"]);
|
|
53
|
+
});
|
|
54
|
+
it("should validate const value matches declared type", () => {
|
|
55
|
+
const schema = {
|
|
56
|
+
type: "number",
|
|
57
|
+
const: "not a number",
|
|
58
|
+
};
|
|
59
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
60
|
+
expect(result.valid).toBe(false);
|
|
61
|
+
expect(result.errors).toHaveLength(1);
|
|
62
|
+
expect(result.errors[0].code).toBe("TYPE_MISMATCH_IN_CONST");
|
|
63
|
+
});
|
|
64
|
+
it("should validate null type enum includes null", () => {
|
|
65
|
+
const schema = {
|
|
66
|
+
type: "null",
|
|
67
|
+
enum: ["not null"],
|
|
68
|
+
};
|
|
69
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
70
|
+
expect(result.valid).toBe(false);
|
|
71
|
+
expect(result.errors).toHaveLength(1);
|
|
72
|
+
expect(result.errors[0].code).toBe("INVALID_ENUM_FOR_NULL_TYPE");
|
|
73
|
+
});
|
|
74
|
+
it("should validate boolean type enum only contains boolean values", () => {
|
|
75
|
+
const schema = {
|
|
76
|
+
type: "boolean",
|
|
77
|
+
enum: [true, false, "not boolean"],
|
|
78
|
+
};
|
|
79
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
80
|
+
expect(result.valid).toBe(false);
|
|
81
|
+
expect(result.errors).toHaveLength(1);
|
|
82
|
+
expect(result.errors[0].code).toBe("INVALID_ENUM_FOR_BOOLEAN_TYPE");
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
describe("Numeric Constraints", () => {
|
|
86
|
+
it("should validate numeric constraints only on numeric types", () => {
|
|
87
|
+
const schema = {
|
|
88
|
+
type: "string",
|
|
89
|
+
maximum: 10,
|
|
90
|
+
};
|
|
91
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
92
|
+
expect(result.valid).toBe(false);
|
|
93
|
+
expect(result.errors).toHaveLength(1);
|
|
94
|
+
expect(result.errors[0].code).toBe("NUMERIC_CONSTRAINTS_ON_NON_NUMERIC_TYPE");
|
|
95
|
+
});
|
|
96
|
+
it("should validate maximum is a valid number", () => {
|
|
97
|
+
const schema = {
|
|
98
|
+
type: "number",
|
|
99
|
+
maximum: "not a number",
|
|
100
|
+
};
|
|
101
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
102
|
+
expect(result.valid).toBe(false);
|
|
103
|
+
expect(result.errors).toHaveLength(1);
|
|
104
|
+
expect(result.errors[0].code).toBe("INVALID_MAXIMUM");
|
|
105
|
+
});
|
|
106
|
+
it("should validate minimum is a valid number", () => {
|
|
107
|
+
const schema = {
|
|
108
|
+
type: "number",
|
|
109
|
+
minimum: "not a number",
|
|
110
|
+
};
|
|
111
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
112
|
+
expect(result.valid).toBe(false);
|
|
113
|
+
expect(result.errors).toHaveLength(1);
|
|
114
|
+
expect(result.errors[0].code).toBe("INVALID_MINIMUM");
|
|
115
|
+
});
|
|
116
|
+
it("should validate maximum >= minimum", () => {
|
|
117
|
+
const schema = {
|
|
118
|
+
type: "number",
|
|
119
|
+
maximum: 5,
|
|
120
|
+
minimum: 10,
|
|
121
|
+
};
|
|
122
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
123
|
+
expect(result.valid).toBe(false);
|
|
124
|
+
expect(result.errors).toHaveLength(1);
|
|
125
|
+
expect(result.errors[0].code).toBe("MAXIMUM_LESS_THAN_MINIMUM");
|
|
126
|
+
});
|
|
127
|
+
it("should accept valid numeric constraints", () => {
|
|
128
|
+
const schema = {
|
|
129
|
+
type: "number",
|
|
130
|
+
maximum: 100,
|
|
131
|
+
minimum: 0,
|
|
132
|
+
};
|
|
133
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
134
|
+
expect(result.valid).toBe(true);
|
|
135
|
+
});
|
|
136
|
+
it("should handle edge cases with null and undefined values", () => {
|
|
137
|
+
// Schema with explicit null values
|
|
138
|
+
const schemaWithNull = {
|
|
139
|
+
type: "object",
|
|
140
|
+
properties: {
|
|
141
|
+
nullable: { type: "null" },
|
|
142
|
+
optional: { type: "string" },
|
|
143
|
+
},
|
|
144
|
+
};
|
|
145
|
+
expect((0, jsonSchema_1.validateJSONSchema)(schemaWithNull).valid).toBe(true);
|
|
146
|
+
// Schema with undefined properties (should be rejected)
|
|
147
|
+
const schemaWithUndefined = {
|
|
148
|
+
type: "object",
|
|
149
|
+
properties: {
|
|
150
|
+
defined: { type: "string" },
|
|
151
|
+
},
|
|
152
|
+
};
|
|
153
|
+
schemaWithUndefined.properties.undefined = undefined;
|
|
154
|
+
// The validator should reject schemas with undefined property values
|
|
155
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schemaWithUndefined);
|
|
156
|
+
expect(result.valid).toBe(false);
|
|
157
|
+
expect(result.errors[0].code).toBe("INVALID_PROPERTY_SCHEMA");
|
|
158
|
+
expect(result.errors[0].path).toEqual(["properties", "undefined"]);
|
|
159
|
+
});
|
|
160
|
+
});
|
|
161
|
+
describe("String Constraints", () => {
|
|
162
|
+
it("should validate string constraints only on string types", () => {
|
|
163
|
+
const schema = {
|
|
164
|
+
type: "number",
|
|
165
|
+
maxLength: 10,
|
|
166
|
+
};
|
|
167
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
168
|
+
expect(result.valid).toBe(false);
|
|
169
|
+
expect(result.errors).toHaveLength(1);
|
|
170
|
+
expect(result.errors[0].code).toBe("STRING_CONSTRAINTS_ON_NON_STRING_TYPE");
|
|
171
|
+
});
|
|
172
|
+
it("should validate maxLength is non-negative integer", () => {
|
|
173
|
+
const schema = {
|
|
174
|
+
type: "string",
|
|
175
|
+
maxLength: -1,
|
|
176
|
+
};
|
|
177
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
178
|
+
expect(result.valid).toBe(false);
|
|
179
|
+
expect(result.errors).toHaveLength(1);
|
|
180
|
+
expect(result.errors[0].code).toBe("INVALID_MAX_LENGTH");
|
|
181
|
+
});
|
|
182
|
+
it("should validate minLength is non-negative integer", () => {
|
|
183
|
+
const schema = {
|
|
184
|
+
type: "string",
|
|
185
|
+
minLength: 3.5,
|
|
186
|
+
};
|
|
187
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
188
|
+
expect(result.valid).toBe(false);
|
|
189
|
+
expect(result.errors).toHaveLength(1);
|
|
190
|
+
expect(result.errors[0].code).toBe("INVALID_MIN_LENGTH");
|
|
191
|
+
});
|
|
192
|
+
it("should validate maxLength >= minLength", () => {
|
|
193
|
+
const schema = {
|
|
194
|
+
type: "string",
|
|
195
|
+
maxLength: 5,
|
|
196
|
+
minLength: 10,
|
|
197
|
+
};
|
|
198
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
199
|
+
expect(result.valid).toBe(false);
|
|
200
|
+
expect(result.errors).toHaveLength(1);
|
|
201
|
+
expect(result.errors[0].code).toBe("MAX_LENGTH_LESS_THAN_MIN_LENGTH");
|
|
202
|
+
});
|
|
203
|
+
it("should validate pattern is a string", () => {
|
|
204
|
+
const schema = {
|
|
205
|
+
type: "string",
|
|
206
|
+
pattern: 123,
|
|
207
|
+
};
|
|
208
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
209
|
+
expect(result.valid).toBe(false);
|
|
210
|
+
expect(result.errors).toHaveLength(1);
|
|
211
|
+
expect(result.errors[0].code).toBe("INVALID_PATTERN_TYPE");
|
|
212
|
+
});
|
|
213
|
+
it("should validate pattern is a valid regex", () => {
|
|
214
|
+
const schema = {
|
|
215
|
+
type: "string",
|
|
216
|
+
pattern: "[invalid regex",
|
|
217
|
+
};
|
|
218
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
219
|
+
expect(result.valid).toBe(false);
|
|
220
|
+
expect(result.errors).toHaveLength(1);
|
|
221
|
+
expect(result.errors[0].code).toBe("INVALID_REGEX_PATTERN");
|
|
222
|
+
});
|
|
223
|
+
it("should accept valid string constraints", () => {
|
|
224
|
+
const schema = {
|
|
225
|
+
type: "string",
|
|
226
|
+
maxLength: 100,
|
|
227
|
+
minLength: 1,
|
|
228
|
+
pattern: "^[a-z]+$",
|
|
229
|
+
};
|
|
230
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
231
|
+
expect(result.valid).toBe(true);
|
|
232
|
+
});
|
|
233
|
+
});
|
|
234
|
+
describe("Array Constraints", () => {
|
|
235
|
+
it("should validate array constraints only on array types", () => {
|
|
236
|
+
const schema = {
|
|
237
|
+
type: "string",
|
|
238
|
+
maxItems: 10,
|
|
239
|
+
};
|
|
240
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
241
|
+
expect(result.valid).toBe(false);
|
|
242
|
+
expect(result.errors).toHaveLength(1);
|
|
243
|
+
expect(result.errors[0].code).toBe("ARRAY_CONSTRAINTS_ON_NON_ARRAY_TYPE");
|
|
244
|
+
});
|
|
245
|
+
it("should validate maxItems is non-negative integer", () => {
|
|
246
|
+
const schema = {
|
|
247
|
+
type: "array",
|
|
248
|
+
maxItems: -1,
|
|
249
|
+
};
|
|
250
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
251
|
+
expect(result.valid).toBe(false);
|
|
252
|
+
expect(result.errors).toHaveLength(1);
|
|
253
|
+
expect(result.errors[0].code).toBe("INVALID_MAX_ITEMS");
|
|
254
|
+
});
|
|
255
|
+
it("should validate minItems is non-negative integer", () => {
|
|
256
|
+
const schema = {
|
|
257
|
+
type: "array",
|
|
258
|
+
minItems: 3.5,
|
|
259
|
+
};
|
|
260
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
261
|
+
expect(result.valid).toBe(false);
|
|
262
|
+
expect(result.errors).toHaveLength(1);
|
|
263
|
+
expect(result.errors[0].code).toBe("INVALID_MIN_ITEMS");
|
|
264
|
+
});
|
|
265
|
+
it("should validate maxItems >= minItems", () => {
|
|
266
|
+
const schema = {
|
|
267
|
+
type: "array",
|
|
268
|
+
maxItems: 5,
|
|
269
|
+
minItems: 10,
|
|
270
|
+
};
|
|
271
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
272
|
+
expect(result.valid).toBe(false);
|
|
273
|
+
expect(result.errors).toHaveLength(1);
|
|
274
|
+
expect(result.errors[0].code).toBe("MAX_ITEMS_LESS_THAN_MIN_ITEMS");
|
|
275
|
+
});
|
|
276
|
+
it("should validate uniqueItems is boolean", () => {
|
|
277
|
+
const schema = {
|
|
278
|
+
type: "array",
|
|
279
|
+
uniqueItems: "not boolean",
|
|
280
|
+
};
|
|
281
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
282
|
+
expect(result.valid).toBe(false);
|
|
283
|
+
expect(result.errors).toHaveLength(1);
|
|
284
|
+
expect(result.errors[0].code).toBe("INVALID_UNIQUE_ITEMS");
|
|
285
|
+
});
|
|
286
|
+
it("should validate items array contains valid schemas", () => {
|
|
287
|
+
const schema = {
|
|
288
|
+
type: "array",
|
|
289
|
+
items: [{ type: "string" }, "not a schema"],
|
|
290
|
+
};
|
|
291
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
292
|
+
expect(result.valid).toBe(false);
|
|
293
|
+
expect(result.errors).toHaveLength(1);
|
|
294
|
+
expect(result.errors[0].code).toBe("INVALID_ITEMS_SCHEMA");
|
|
295
|
+
});
|
|
296
|
+
it("should validate items is a valid schema", () => {
|
|
297
|
+
const schema = {
|
|
298
|
+
type: "array",
|
|
299
|
+
items: "not a schema",
|
|
300
|
+
};
|
|
301
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
302
|
+
expect(result.valid).toBe(false);
|
|
303
|
+
expect(result.errors).toHaveLength(1);
|
|
304
|
+
expect(result.errors[0].code).toBe("INVALID_ITEMS_TYPE");
|
|
305
|
+
});
|
|
306
|
+
it("should accept valid array constraints", () => {
|
|
307
|
+
const schema = {
|
|
308
|
+
type: "array",
|
|
309
|
+
maxItems: 100,
|
|
310
|
+
minItems: 1,
|
|
311
|
+
uniqueItems: true,
|
|
312
|
+
items: { type: "string" },
|
|
313
|
+
};
|
|
314
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
315
|
+
expect(result.valid).toBe(true);
|
|
316
|
+
});
|
|
317
|
+
});
|
|
318
|
+
describe("Object Constraints", () => {
|
|
319
|
+
it("should validate object constraints only on object types", () => {
|
|
320
|
+
const schema = {
|
|
321
|
+
type: "string",
|
|
322
|
+
properties: { name: { type: "string" } },
|
|
323
|
+
};
|
|
324
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
325
|
+
expect(result.valid).toBe(false);
|
|
326
|
+
expect(result.errors).toHaveLength(1);
|
|
327
|
+
expect(result.errors[0].code).toBe("OBJECT_CONSTRAINTS_ON_NON_OBJECT_TYPE");
|
|
328
|
+
});
|
|
329
|
+
it("should validate required is an array", () => {
|
|
330
|
+
const schema = {
|
|
331
|
+
type: "object",
|
|
332
|
+
required: "not an array",
|
|
333
|
+
};
|
|
334
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
335
|
+
expect(result.valid).toBe(false);
|
|
336
|
+
expect(result.errors).toHaveLength(1);
|
|
337
|
+
expect(result.errors[0].code).toBe("INVALID_REQUIRED_TYPE");
|
|
338
|
+
});
|
|
339
|
+
it("should validate required array contains strings", () => {
|
|
340
|
+
const schema = {
|
|
341
|
+
type: "object",
|
|
342
|
+
required: ["prop1", 123, "prop3"],
|
|
343
|
+
};
|
|
344
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
345
|
+
expect(result.valid).toBe(false);
|
|
346
|
+
expect(result.errors).toHaveLength(1);
|
|
347
|
+
expect(result.errors[0].code).toBe("INVALID_REQUIRED_ITEM");
|
|
348
|
+
});
|
|
349
|
+
it("should validate properties is an object", () => {
|
|
350
|
+
const schema = {
|
|
351
|
+
type: "object",
|
|
352
|
+
properties: "not an object",
|
|
353
|
+
};
|
|
354
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
355
|
+
expect(result.valid).toBe(false);
|
|
356
|
+
expect(result.errors).toHaveLength(1);
|
|
357
|
+
expect(result.errors[0].code).toBe("INVALID_PROPERTIES_TYPE");
|
|
358
|
+
});
|
|
359
|
+
it("should validate properties values are schemas", () => {
|
|
360
|
+
const schema = {
|
|
361
|
+
type: "object",
|
|
362
|
+
properties: {
|
|
363
|
+
prop1: { type: "string" },
|
|
364
|
+
prop2: "not a schema",
|
|
365
|
+
},
|
|
366
|
+
};
|
|
367
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
368
|
+
expect(result.valid).toBe(false);
|
|
369
|
+
expect(result.errors).toHaveLength(1);
|
|
370
|
+
expect(result.errors[0].code).toBe("INVALID_PROPERTY_SCHEMA");
|
|
371
|
+
});
|
|
372
|
+
it("should accept valid object constraints", () => {
|
|
373
|
+
const schema = {
|
|
374
|
+
type: "object",
|
|
375
|
+
required: ["prop1"],
|
|
376
|
+
properties: {
|
|
377
|
+
prop1: { type: "string" },
|
|
378
|
+
},
|
|
379
|
+
};
|
|
380
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
381
|
+
expect(result.valid).toBe(true);
|
|
382
|
+
});
|
|
383
|
+
});
|
|
384
|
+
describe("Complex Schema Validation", () => {
|
|
385
|
+
it("should validate a complex valid schema", () => {
|
|
386
|
+
const schema = {
|
|
387
|
+
description: "A schema for user data",
|
|
388
|
+
type: "object",
|
|
389
|
+
properties: {
|
|
390
|
+
id: {
|
|
391
|
+
type: "integer",
|
|
392
|
+
minimum: 1,
|
|
393
|
+
},
|
|
394
|
+
name: {
|
|
395
|
+
type: "string",
|
|
396
|
+
minLength: 1,
|
|
397
|
+
maxLength: 100,
|
|
398
|
+
},
|
|
399
|
+
email: {
|
|
400
|
+
type: "string",
|
|
401
|
+
},
|
|
402
|
+
age: {
|
|
403
|
+
type: "integer",
|
|
404
|
+
minimum: 0,
|
|
405
|
+
maximum: 150,
|
|
406
|
+
},
|
|
407
|
+
tags: {
|
|
408
|
+
type: "array",
|
|
409
|
+
items: { type: "string" },
|
|
410
|
+
uniqueItems: true,
|
|
411
|
+
},
|
|
412
|
+
},
|
|
413
|
+
required: ["id", "name", "email"],
|
|
414
|
+
};
|
|
415
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
416
|
+
expect(result.valid).toBe(true);
|
|
417
|
+
});
|
|
418
|
+
it("should validate nested schemas", () => {
|
|
419
|
+
const schema = {
|
|
420
|
+
type: "object",
|
|
421
|
+
properties: {
|
|
422
|
+
address: {
|
|
423
|
+
type: "object",
|
|
424
|
+
properties: {
|
|
425
|
+
street: { type: "string" },
|
|
426
|
+
city: { type: "string" },
|
|
427
|
+
},
|
|
428
|
+
required: ["street", "city"],
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
};
|
|
432
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
433
|
+
expect(result.valid).toBe(true);
|
|
434
|
+
});
|
|
435
|
+
});
|
|
436
|
+
describe("Error Paths", () => {
|
|
437
|
+
it("should provide correct error paths for nested properties", () => {
|
|
438
|
+
const schema = {
|
|
439
|
+
type: "object",
|
|
440
|
+
properties: {
|
|
441
|
+
user: {
|
|
442
|
+
type: "object",
|
|
443
|
+
properties: {
|
|
444
|
+
name: {
|
|
445
|
+
type: "string",
|
|
446
|
+
maxLength: "not a number", // Invalid
|
|
447
|
+
},
|
|
448
|
+
},
|
|
449
|
+
},
|
|
450
|
+
},
|
|
451
|
+
};
|
|
452
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
453
|
+
expect(result.valid).toBe(false);
|
|
454
|
+
expect(result.errors).toHaveLength(1);
|
|
455
|
+
expect(result.errors[0].path).toEqual([
|
|
456
|
+
"properties",
|
|
457
|
+
"user",
|
|
458
|
+
"properties",
|
|
459
|
+
"name",
|
|
460
|
+
"maxLength",
|
|
461
|
+
]);
|
|
462
|
+
});
|
|
463
|
+
it("should provide correct error paths for array items", () => {
|
|
464
|
+
const schema = {
|
|
465
|
+
type: "array",
|
|
466
|
+
items: [
|
|
467
|
+
{ type: "string" },
|
|
468
|
+
{ type: "number", maximum: "not a number" }, // Invalid
|
|
469
|
+
],
|
|
470
|
+
};
|
|
471
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
472
|
+
expect(result.valid).toBe(false);
|
|
473
|
+
expect(result.errors).toHaveLength(1);
|
|
474
|
+
expect(result.errors[0].path).toEqual(["items", "1", "maximum"]);
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
describe("Deep Recursion and Complex Nested Schemas", () => {
|
|
478
|
+
it("should handle deeply nested object schemas", () => {
|
|
479
|
+
const schema = {
|
|
480
|
+
type: "object",
|
|
481
|
+
properties: {
|
|
482
|
+
level1: {
|
|
483
|
+
type: "object",
|
|
484
|
+
properties: {
|
|
485
|
+
level2: {
|
|
486
|
+
type: "object",
|
|
487
|
+
properties: {
|
|
488
|
+
level3: {
|
|
489
|
+
type: "object",
|
|
490
|
+
properties: {
|
|
491
|
+
level4: {
|
|
492
|
+
type: "object",
|
|
493
|
+
properties: {
|
|
494
|
+
level5: {
|
|
495
|
+
type: "string",
|
|
496
|
+
maxLength: 100,
|
|
497
|
+
},
|
|
498
|
+
},
|
|
499
|
+
},
|
|
500
|
+
},
|
|
501
|
+
},
|
|
502
|
+
},
|
|
503
|
+
},
|
|
504
|
+
},
|
|
505
|
+
},
|
|
506
|
+
},
|
|
507
|
+
};
|
|
508
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
509
|
+
expect(result.valid).toBe(true);
|
|
510
|
+
});
|
|
511
|
+
it("should handle deeply nested array schemas", () => {
|
|
512
|
+
const schema = {
|
|
513
|
+
type: "array",
|
|
514
|
+
items: {
|
|
515
|
+
type: "array",
|
|
516
|
+
items: {
|
|
517
|
+
type: "array",
|
|
518
|
+
items: {
|
|
519
|
+
type: "array",
|
|
520
|
+
items: {
|
|
521
|
+
type: "array",
|
|
522
|
+
items: { type: "string" },
|
|
523
|
+
},
|
|
524
|
+
},
|
|
525
|
+
},
|
|
526
|
+
},
|
|
527
|
+
};
|
|
528
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
529
|
+
expect(result.valid).toBe(true);
|
|
530
|
+
});
|
|
531
|
+
it("should handle complex mixed nesting", () => {
|
|
532
|
+
const schema = {
|
|
533
|
+
type: "object",
|
|
534
|
+
properties: {
|
|
535
|
+
users: {
|
|
536
|
+
type: "array",
|
|
537
|
+
items: {
|
|
538
|
+
type: "object",
|
|
539
|
+
properties: {
|
|
540
|
+
profile: {
|
|
541
|
+
type: "object",
|
|
542
|
+
properties: {
|
|
543
|
+
addresses: {
|
|
544
|
+
type: "array",
|
|
545
|
+
items: {
|
|
546
|
+
type: "object",
|
|
547
|
+
properties: {
|
|
548
|
+
coordinates: {
|
|
549
|
+
type: "object",
|
|
550
|
+
properties: {
|
|
551
|
+
lat: { type: "number" },
|
|
552
|
+
lng: { type: "number" },
|
|
553
|
+
},
|
|
554
|
+
},
|
|
555
|
+
},
|
|
556
|
+
},
|
|
557
|
+
},
|
|
558
|
+
},
|
|
559
|
+
},
|
|
560
|
+
},
|
|
561
|
+
},
|
|
562
|
+
},
|
|
563
|
+
},
|
|
564
|
+
};
|
|
565
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
566
|
+
expect(result.valid).toBe(true);
|
|
567
|
+
});
|
|
568
|
+
it("should detect errors in deeply nested schemas", () => {
|
|
569
|
+
const schema = {
|
|
570
|
+
type: "object",
|
|
571
|
+
properties: {
|
|
572
|
+
level1: {
|
|
573
|
+
type: "object",
|
|
574
|
+
properties: {
|
|
575
|
+
level2: {
|
|
576
|
+
type: "object",
|
|
577
|
+
properties: {
|
|
578
|
+
level3: {
|
|
579
|
+
type: "string",
|
|
580
|
+
maxLength: "invalid", // Invalid
|
|
581
|
+
},
|
|
582
|
+
},
|
|
583
|
+
},
|
|
584
|
+
},
|
|
585
|
+
},
|
|
586
|
+
},
|
|
587
|
+
};
|
|
588
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
589
|
+
expect(result.valid).toBe(false);
|
|
590
|
+
expect(result.errors).toHaveLength(1);
|
|
591
|
+
expect(result.errors[0].path).toEqual([
|
|
592
|
+
"properties",
|
|
593
|
+
"level1",
|
|
594
|
+
"properties",
|
|
595
|
+
"level2",
|
|
596
|
+
"properties",
|
|
597
|
+
"level3",
|
|
598
|
+
"maxLength",
|
|
599
|
+
]);
|
|
600
|
+
});
|
|
601
|
+
});
|
|
602
|
+
describe("Advanced Array Validation", () => {
|
|
603
|
+
it("should validate complex array items with mixed schemas", () => {
|
|
604
|
+
const schema = {
|
|
605
|
+
type: "array",
|
|
606
|
+
items: [
|
|
607
|
+
{ type: "string" },
|
|
608
|
+
{ type: "number" },
|
|
609
|
+
{ type: "boolean" },
|
|
610
|
+
{ type: "object", properties: { name: { type: "string" } } },
|
|
611
|
+
],
|
|
612
|
+
};
|
|
613
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
614
|
+
expect(result.valid).toBe(true);
|
|
615
|
+
});
|
|
616
|
+
it("should validate uniqueItems with complex objects", () => {
|
|
617
|
+
const schema = {
|
|
618
|
+
type: "array",
|
|
619
|
+
uniqueItems: true,
|
|
620
|
+
items: {
|
|
621
|
+
type: "object",
|
|
622
|
+
properties: {
|
|
623
|
+
id: { type: "integer" },
|
|
624
|
+
name: { type: "string" },
|
|
625
|
+
},
|
|
626
|
+
},
|
|
627
|
+
};
|
|
628
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
629
|
+
expect(result.valid).toBe(true);
|
|
630
|
+
});
|
|
631
|
+
it("should detect invalid array items in mixed schema", () => {
|
|
632
|
+
const schema = {
|
|
633
|
+
type: "array",
|
|
634
|
+
items: [
|
|
635
|
+
{ type: "string" },
|
|
636
|
+
{ type: "number", maximum: "invalid" }, // Invalid
|
|
637
|
+
],
|
|
638
|
+
};
|
|
639
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
640
|
+
expect(result.valid).toBe(false);
|
|
641
|
+
expect(result.errors).toHaveLength(1);
|
|
642
|
+
expect(result.errors[0].path).toEqual(["items", "1", "maximum"]);
|
|
643
|
+
});
|
|
644
|
+
});
|
|
645
|
+
describe("Advanced Object Validation", () => { });
|
|
646
|
+
describe("Edge Cases and Error Scenarios", () => {
|
|
647
|
+
it("should handle schemas with only metadata", () => {
|
|
648
|
+
const schema = {
|
|
649
|
+
description: "A schema with only metadata",
|
|
650
|
+
};
|
|
651
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
652
|
+
expect(result.valid).toBe(true);
|
|
653
|
+
});
|
|
654
|
+
it("should handle schemas with only examples and default", () => {
|
|
655
|
+
const schema = {
|
|
656
|
+
type: "string",
|
|
657
|
+
default: "default value",
|
|
658
|
+
examples: ["example 1", "example 2"],
|
|
659
|
+
};
|
|
660
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
661
|
+
expect(result.valid).toBe(true);
|
|
662
|
+
});
|
|
663
|
+
});
|
|
664
|
+
describe("Performance and Large Schema Handling", () => {
|
|
665
|
+
it("should handle large schemas with many properties", () => {
|
|
666
|
+
const properties = {};
|
|
667
|
+
for (let i = 0; i < 100; i++) {
|
|
668
|
+
properties[`prop${i}`] = { type: "string" };
|
|
669
|
+
}
|
|
670
|
+
const schema = {
|
|
671
|
+
type: "object",
|
|
672
|
+
properties,
|
|
673
|
+
};
|
|
674
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
675
|
+
expect(result.valid).toBe(true);
|
|
676
|
+
});
|
|
677
|
+
it("should handle deeply nested schemas without stack overflow", () => {
|
|
678
|
+
let schema = { type: "string" };
|
|
679
|
+
for (let i = 0; i < 50; i++) {
|
|
680
|
+
schema = {
|
|
681
|
+
type: "object",
|
|
682
|
+
properties: {
|
|
683
|
+
nested: schema,
|
|
684
|
+
},
|
|
685
|
+
};
|
|
686
|
+
}
|
|
687
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
688
|
+
expect(result.valid).toBe(true);
|
|
689
|
+
});
|
|
690
|
+
it("should handle schemas with many array items", () => {
|
|
691
|
+
const items = Array(50)
|
|
692
|
+
.fill(null)
|
|
693
|
+
.map(() => ({ type: "string" }));
|
|
694
|
+
const schema = {
|
|
695
|
+
type: "array",
|
|
696
|
+
items,
|
|
697
|
+
};
|
|
698
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
699
|
+
expect(result.valid).toBe(true);
|
|
700
|
+
});
|
|
701
|
+
});
|
|
702
|
+
describe("Additional Edge Cases and Constraint Combinations", () => {
|
|
703
|
+
it("should handle schemas with all constraint types combined", () => {
|
|
704
|
+
const schema = {
|
|
705
|
+
type: "object",
|
|
706
|
+
properties: {
|
|
707
|
+
user: {
|
|
708
|
+
type: "object",
|
|
709
|
+
properties: {
|
|
710
|
+
id: {
|
|
711
|
+
type: "integer",
|
|
712
|
+
minimum: 1,
|
|
713
|
+
maximum: 999999,
|
|
714
|
+
},
|
|
715
|
+
name: {
|
|
716
|
+
type: "string",
|
|
717
|
+
minLength: 1,
|
|
718
|
+
maxLength: 100,
|
|
719
|
+
pattern: "^[a-zA-Z ]+$",
|
|
720
|
+
},
|
|
721
|
+
email: {
|
|
722
|
+
type: "string",
|
|
723
|
+
},
|
|
724
|
+
age: {
|
|
725
|
+
type: "integer",
|
|
726
|
+
minimum: 0,
|
|
727
|
+
maximum: 150,
|
|
728
|
+
multipleOf: 1,
|
|
729
|
+
},
|
|
730
|
+
tags: {
|
|
731
|
+
type: "array",
|
|
732
|
+
minItems: 0,
|
|
733
|
+
maxItems: 10,
|
|
734
|
+
uniqueItems: true,
|
|
735
|
+
items: { type: "string" },
|
|
736
|
+
},
|
|
737
|
+
},
|
|
738
|
+
required: ["id", "name", "email"],
|
|
739
|
+
},
|
|
740
|
+
},
|
|
741
|
+
required: ["user"],
|
|
742
|
+
};
|
|
743
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
744
|
+
expect(result.valid).toBe(true);
|
|
745
|
+
});
|
|
746
|
+
it("should handle schemas with complex array validation combinations", () => {
|
|
747
|
+
const schema = {
|
|
748
|
+
type: "array",
|
|
749
|
+
minItems: 1,
|
|
750
|
+
maxItems: 100,
|
|
751
|
+
uniqueItems: true,
|
|
752
|
+
items: {
|
|
753
|
+
type: "object",
|
|
754
|
+
properties: {
|
|
755
|
+
id: { type: "string" },
|
|
756
|
+
value: { type: "number" },
|
|
757
|
+
},
|
|
758
|
+
required: ["id"],
|
|
759
|
+
},
|
|
760
|
+
};
|
|
761
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
762
|
+
expect(result.valid).toBe(true);
|
|
763
|
+
});
|
|
764
|
+
it("should handle schemas with complex nested structures", () => {
|
|
765
|
+
const schema = {
|
|
766
|
+
type: "object",
|
|
767
|
+
properties: {
|
|
768
|
+
user: {
|
|
769
|
+
type: "object",
|
|
770
|
+
properties: {
|
|
771
|
+
id: { type: "string" },
|
|
772
|
+
name: { type: "string" },
|
|
773
|
+
role: { type: "string", const: "admin" },
|
|
774
|
+
permissions: { type: "array", items: { type: "string" } },
|
|
775
|
+
},
|
|
776
|
+
},
|
|
777
|
+
contact: {
|
|
778
|
+
type: "object",
|
|
779
|
+
properties: {
|
|
780
|
+
email: { type: "string" },
|
|
781
|
+
phone: { type: "string" },
|
|
782
|
+
address: {
|
|
783
|
+
type: "object",
|
|
784
|
+
properties: {
|
|
785
|
+
street: { type: "string" },
|
|
786
|
+
city: { type: "string" },
|
|
787
|
+
country: { type: "string" },
|
|
788
|
+
},
|
|
789
|
+
},
|
|
790
|
+
},
|
|
791
|
+
},
|
|
792
|
+
},
|
|
793
|
+
};
|
|
794
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
795
|
+
expect(result.valid).toBe(true);
|
|
796
|
+
});
|
|
797
|
+
it("should validate complex nested schemas with all constraint types", () => {
|
|
798
|
+
const schema = {
|
|
799
|
+
type: "object",
|
|
800
|
+
properties: {
|
|
801
|
+
users: {
|
|
802
|
+
type: "array",
|
|
803
|
+
minItems: 1,
|
|
804
|
+
maxItems: 1000,
|
|
805
|
+
items: {
|
|
806
|
+
type: "object",
|
|
807
|
+
properties: {
|
|
808
|
+
id: {
|
|
809
|
+
type: "string",
|
|
810
|
+
minLength: 1,
|
|
811
|
+
maxLength: 50,
|
|
812
|
+
pattern: "^[a-zA-Z0-9_-]+$",
|
|
813
|
+
},
|
|
814
|
+
profile: {
|
|
815
|
+
type: "object",
|
|
816
|
+
properties: {
|
|
817
|
+
firstName: {
|
|
818
|
+
type: "string",
|
|
819
|
+
minLength: 1,
|
|
820
|
+
maxLength: 100,
|
|
821
|
+
},
|
|
822
|
+
lastName: {
|
|
823
|
+
type: "string",
|
|
824
|
+
minLength: 1,
|
|
825
|
+
maxLength: 100,
|
|
826
|
+
},
|
|
827
|
+
birthDate: {
|
|
828
|
+
type: "string",
|
|
829
|
+
},
|
|
830
|
+
age: {
|
|
831
|
+
type: "integer",
|
|
832
|
+
minimum: 0,
|
|
833
|
+
maximum: 150,
|
|
834
|
+
},
|
|
835
|
+
height: {
|
|
836
|
+
type: "number",
|
|
837
|
+
minimum: 0.1,
|
|
838
|
+
maximum: 3.0,
|
|
839
|
+
},
|
|
840
|
+
tags: {
|
|
841
|
+
type: "array",
|
|
842
|
+
minItems: 0,
|
|
843
|
+
maxItems: 20,
|
|
844
|
+
uniqueItems: true,
|
|
845
|
+
items: {
|
|
846
|
+
type: "string",
|
|
847
|
+
minLength: 1,
|
|
848
|
+
maxLength: 50,
|
|
849
|
+
},
|
|
850
|
+
},
|
|
851
|
+
},
|
|
852
|
+
required: ["firstName", "lastName"],
|
|
853
|
+
minProperties: 2,
|
|
854
|
+
maxProperties: 6,
|
|
855
|
+
},
|
|
856
|
+
settings: {
|
|
857
|
+
type: "object",
|
|
858
|
+
properties: {
|
|
859
|
+
theme: { type: "string" },
|
|
860
|
+
language: { type: "string" },
|
|
861
|
+
},
|
|
862
|
+
},
|
|
863
|
+
},
|
|
864
|
+
required: ["id"],
|
|
865
|
+
},
|
|
866
|
+
},
|
|
867
|
+
},
|
|
868
|
+
required: ["users"],
|
|
869
|
+
};
|
|
870
|
+
const result = (0, jsonSchema_1.validateJSONSchema)(schema);
|
|
871
|
+
expect(result.valid).toBe(true);
|
|
872
|
+
});
|
|
873
|
+
});
|
|
874
|
+
});
|
|
875
|
+
//# sourceMappingURL=jsonSchema.spec.js.map
|