@amritk/generate-parsers 0.16.3 → 0.17.1
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/AI.md +36 -0
- package/dist/generators/assert-supported-keywords.js +45 -72
- package/dist/generators/build-schema.js +56 -168
- package/dist/generators/generate-default-from-pattern.js +24 -31
- package/dist/generators/generate-discriminated-union-validation.js +27 -47
- package/dist/generators/generate-enum-check.js +27 -61
- package/dist/generators/generate-files.js +54 -83
- package/dist/generators/generate-non-discriminated-union-validation.js +24 -26
- package/dist/generators/generate-parser-function.d.ts +12 -0
- package/dist/generators/generate-parser-function.js +1132 -1711
- package/dist/generators/generate-schema-checks.js +216 -250
- package/dist/generators/generate-strict-assertion.js +311 -447
- package/dist/generators/generate-type-checks.js +287 -460
- package/dist/generators/generate-validation-expression.js +300 -439
- package/dist/generators/subschema-match.js +201 -266
- package/dist/helpers/apply-schema-extensions.js +18 -49
- package/dist/helpers/collect-helpers.js +58 -71
- package/dist/helpers/collect-imports.js +161 -237
- package/dist/helpers/find-discriminator.js +23 -29
- package/dist/helpers/get-default-value.js +76 -96
- package/dist/helpers/get-discriminator-value.js +16 -17
- package/dist/index.js +4 -1
- package/package.json +6 -5
|
@@ -1,265 +1,231 @@
|
|
|
1
|
-
import { escapeRegexPattern } from
|
|
2
|
-
import { getMjstInstanceOf, getMjstPrimitive } from
|
|
3
|
-
import { multipleOfPassExpr } from
|
|
4
|
-
import { hasAdditionalProperties, hasConst, hasEnum, hasExclusiveMaximum, hasExclusiveMinimum, hasMaxItems, hasMaximum, hasMaxLength, hasMaxProperties, hasMinItems, hasMinimum, hasMinLength, hasMinProperties, hasMultipleOf, hasPattern, hasProperties, hasRequired, hasType, hasUniqueItems, isSchemaObject
|
|
5
|
-
import { generateEnumCheck } from
|
|
6
|
-
// Keywords that only make sense on a given type. A branch that carries any of
|
|
7
|
-
// them but no explicit `type` is treated as that type for discrimination.
|
|
1
|
+
import { escapeRegexPattern } from "@amritk/helpers/escape-regex-pattern";
|
|
2
|
+
import { getMjstInstanceOf, getMjstPrimitive } from "@amritk/helpers/mjst-extension";
|
|
3
|
+
import { multipleOfPassExpr } from "@amritk/helpers/multiple-of-check";
|
|
4
|
+
import { hasAdditionalProperties, hasConst, hasEnum, hasExclusiveMaximum, hasExclusiveMinimum, hasMaxItems, hasMaximum, hasMaxLength, hasMaxProperties, hasMinItems, hasMinimum, hasMinLength, hasMinProperties, hasMultipleOf, hasPattern, hasProperties, hasRequired, hasType, hasUniqueItems, isSchemaObject } from "@amritk/helpers/schema-guards";
|
|
5
|
+
import { generateEnumCheck } from "./generate-enum-check.js";
|
|
8
6
|
const OBJECT_KEYWORDS = [
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
7
|
+
"properties",
|
|
8
|
+
"required",
|
|
9
|
+
"minProperties",
|
|
10
|
+
"maxProperties",
|
|
11
|
+
"additionalProperties",
|
|
12
|
+
"patternProperties",
|
|
13
|
+
"dependentRequired",
|
|
14
|
+
"propertyNames"
|
|
17
15
|
];
|
|
18
|
-
const ARRAY_KEYWORDS = [
|
|
19
|
-
const STRING_KEYWORDS = [
|
|
20
|
-
const NUMBER_KEYWORDS = [
|
|
21
|
-
const countKeywords = (schema, keywords) => keywords.reduce((total, keyword) =>
|
|
22
|
-
/** Resolves the JSON Schema type of a single literal (a `const` value). */
|
|
16
|
+
const ARRAY_KEYWORDS = ["items", "prefixItems", "minItems", "maxItems", "uniqueItems", "contains"];
|
|
17
|
+
const STRING_KEYWORDS = ["minLength", "maxLength", "pattern", "format"];
|
|
18
|
+
const NUMBER_KEYWORDS = ["minimum", "maximum", "exclusiveMinimum", "exclusiveMaximum", "multipleOf"];
|
|
19
|
+
const countKeywords = (schema, keywords) => keywords.reduce((total, keyword) => keyword in schema ? total + 1 : total, 0);
|
|
23
20
|
const typeOfLiteral = (value) => {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
21
|
+
if (value === null)
|
|
22
|
+
return "null";
|
|
23
|
+
if (Array.isArray(value))
|
|
24
|
+
return "array";
|
|
25
|
+
const type = typeof value;
|
|
26
|
+
if (type === "boolean")
|
|
27
|
+
return "boolean";
|
|
28
|
+
if (type === "number" || type === "bigint")
|
|
29
|
+
return "number";
|
|
30
|
+
if (type === "string")
|
|
31
|
+
return "string";
|
|
32
|
+
return "object";
|
|
36
33
|
};
|
|
37
|
-
/**
|
|
38
|
-
* Infers the type of a schema branch that omits an explicit `type`.
|
|
39
|
-
*
|
|
40
|
-
* A `const` pins the value to one literal, so its type is definitive. An enum
|
|
41
|
-
* of only `null`s can only be the null type. Otherwise each candidate type is
|
|
42
|
-
* scored by how many of its characteristic keywords the schema carries and the
|
|
43
|
-
* highest wins, with ties resolved in `object > array > string > number` order
|
|
44
|
-
* (so `{ minProperties, minItems }` is an object and `{ minItems, maxItems,
|
|
45
|
-
* minLength }` is an array). Returns undefined when nothing points at a type —
|
|
46
|
-
* e.g. a bare `{ description }` — so the caller emits no checks.
|
|
47
|
-
*/
|
|
48
34
|
const inferSchemaType = (schema) => {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
35
|
+
if (!isSchemaObject(schema))
|
|
36
|
+
return void 0;
|
|
37
|
+
if (hasConst(schema)) {
|
|
38
|
+
return typeOfLiteral(schema.const);
|
|
39
|
+
}
|
|
40
|
+
if (hasEnum(schema) && schema.enum.length > 0 && schema.enum.every((value) => value === null)) {
|
|
41
|
+
return "null";
|
|
42
|
+
}
|
|
43
|
+
const scores = {
|
|
44
|
+
object: countKeywords(schema, OBJECT_KEYWORDS),
|
|
45
|
+
array: countKeywords(schema, ARRAY_KEYWORDS),
|
|
46
|
+
string: countKeywords(schema, STRING_KEYWORDS),
|
|
47
|
+
number: countKeywords(schema, NUMBER_KEYWORDS)
|
|
48
|
+
};
|
|
49
|
+
let best;
|
|
50
|
+
for (const type of ["object", "array", "string", "number"]) {
|
|
51
|
+
if (scores[type] > 0 && (best === void 0 || scores[type] > scores[best])) {
|
|
52
|
+
best = type;
|
|
53
53
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
57
|
-
const scores = {
|
|
58
|
-
object: countKeywords(schema, OBJECT_KEYWORDS),
|
|
59
|
-
array: countKeywords(schema, ARRAY_KEYWORDS),
|
|
60
|
-
string: countKeywords(schema, STRING_KEYWORDS),
|
|
61
|
-
number: countKeywords(schema, NUMBER_KEYWORDS),
|
|
62
|
-
};
|
|
63
|
-
// Iterating in priority order and only replacing on a strictly-greater score
|
|
64
|
-
// means the earliest (highest-priority) type wins any tie.
|
|
65
|
-
let best;
|
|
66
|
-
for (const type of ['object', 'array', 'string', 'number']) {
|
|
67
|
-
if (scores[type] > 0 && (best === undefined || scores[type] > scores[best])) {
|
|
68
|
-
best = type;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return best;
|
|
54
|
+
}
|
|
55
|
+
return best;
|
|
72
56
|
};
|
|
73
|
-
/**
|
|
74
|
-
* Emits the checks for a branch whose type was inferred (not explicit). It
|
|
75
|
-
* mirrors the explicit-type switch below, with two deliberate differences: the
|
|
76
|
-
* enum membership check uses the `.includes` form (appended by the caller) and
|
|
77
|
-
* `multipleOf` uses the plain `% === 0` form, matching the inference spec.
|
|
78
|
-
*/
|
|
79
57
|
const generateInferredChecks = (accessor, schema, type) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
return checks;
|
|
58
|
+
const checks = [];
|
|
59
|
+
switch (type) {
|
|
60
|
+
case "object":
|
|
61
|
+
checks.push(`typeof ${accessor} === "object" && ${accessor} !== null && !Array.isArray(${accessor})`);
|
|
62
|
+
if (hasRequired(schema) && schema.required.length > 0) {
|
|
63
|
+
for (const requiredKey of schema.required) {
|
|
64
|
+
checks.push(`${JSON.stringify(requiredKey)} in ${accessor}`);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if (hasMinProperties(schema)) {
|
|
68
|
+
checks.push(`Object.keys(${accessor}).length >= ${schema.minProperties}`);
|
|
69
|
+
}
|
|
70
|
+
if (hasMaxProperties(schema)) {
|
|
71
|
+
checks.push(`Object.keys(${accessor}).length <= ${schema.maxProperties}`);
|
|
72
|
+
}
|
|
73
|
+
if (hasAdditionalProperties(schema) && schema.additionalProperties === false && hasProperties(schema)) {
|
|
74
|
+
const allowedKeysStr = JSON.stringify(Object.keys(schema.properties));
|
|
75
|
+
checks.push(`Object.keys(${accessor}).every(k => ${allowedKeysStr}.includes(k))`);
|
|
76
|
+
}
|
|
77
|
+
break;
|
|
78
|
+
case "array":
|
|
79
|
+
checks.push(`Array.isArray(${accessor})`);
|
|
80
|
+
if (hasMinItems(schema)) {
|
|
81
|
+
checks.push(`${accessor}.length >= ${schema.minItems}`);
|
|
82
|
+
}
|
|
83
|
+
if (hasMaxItems(schema)) {
|
|
84
|
+
checks.push(`${accessor}.length <= ${schema.maxItems}`);
|
|
85
|
+
}
|
|
86
|
+
if (hasUniqueItems(schema) && schema.uniqueItems === true) {
|
|
87
|
+
checks.push(`new Set(${accessor}).size === ${accessor}.length`);
|
|
88
|
+
}
|
|
89
|
+
break;
|
|
90
|
+
case "string":
|
|
91
|
+
checks.push(`typeof ${accessor} === "string"`);
|
|
92
|
+
if (hasPattern(schema)) {
|
|
93
|
+
checks.push(`/${escapeRegexPattern(schema.pattern)}/.test(${accessor})`);
|
|
94
|
+
}
|
|
95
|
+
if (hasMinLength(schema)) {
|
|
96
|
+
checks.push(`${accessor}.length >= ${schema.minLength}`);
|
|
97
|
+
}
|
|
98
|
+
if (hasMaxLength(schema)) {
|
|
99
|
+
checks.push(`${accessor}.length <= ${schema.maxLength}`);
|
|
100
|
+
}
|
|
101
|
+
break;
|
|
102
|
+
case "number":
|
|
103
|
+
checks.push(`typeof ${accessor} === "number"`);
|
|
104
|
+
if (hasMinimum(schema)) {
|
|
105
|
+
checks.push(`${accessor} >= ${schema.minimum}`);
|
|
106
|
+
}
|
|
107
|
+
if (hasMaximum(schema)) {
|
|
108
|
+
checks.push(`${accessor} <= ${schema.maximum}`);
|
|
109
|
+
}
|
|
110
|
+
if (hasExclusiveMinimum(schema)) {
|
|
111
|
+
checks.push(`${accessor} > ${schema.exclusiveMinimum}`);
|
|
112
|
+
}
|
|
113
|
+
if (hasExclusiveMaximum(schema)) {
|
|
114
|
+
checks.push(`${accessor} < ${schema.exclusiveMaximum}`);
|
|
115
|
+
}
|
|
116
|
+
if (hasMultipleOf(schema)) {
|
|
117
|
+
checks.push(`${accessor} % ${schema.multipleOf} === 0`);
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
case "boolean":
|
|
121
|
+
checks.push(`typeof ${accessor} === "boolean"`);
|
|
122
|
+
break;
|
|
123
|
+
case "null":
|
|
124
|
+
if (hasConst(schema)) {
|
|
125
|
+
checks.push(`${accessor} === null`);
|
|
126
|
+
}
|
|
127
|
+
break;
|
|
128
|
+
}
|
|
129
|
+
return checks;
|
|
155
130
|
};
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
131
|
+
const generateSchemaChecks = (accessor, schema) => {
|
|
132
|
+
const checks = [];
|
|
133
|
+
const instanceOf = getMjstInstanceOf(schema);
|
|
134
|
+
if (instanceOf) {
|
|
135
|
+
return [`${accessor} instanceof ${instanceOf}`];
|
|
136
|
+
}
|
|
137
|
+
const primitive = getMjstPrimitive(schema);
|
|
138
|
+
if (primitive) {
|
|
139
|
+
return [`typeof ${accessor} === "${primitive}"`];
|
|
140
|
+
}
|
|
141
|
+
if (!hasType(schema)) {
|
|
142
|
+
const inferred = inferSchemaType(schema);
|
|
143
|
+
if (!inferred) {
|
|
144
|
+
return checks;
|
|
165
145
|
}
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
return [`typeof ${accessor} === "${primitive}"`];
|
|
146
|
+
checks.push(...generateInferredChecks(accessor, schema, inferred));
|
|
147
|
+
if (hasEnum(schema) && schema.enum.length > 0) {
|
|
148
|
+
checks.push(`${JSON.stringify(schema.enum)}.includes(${accessor} as never)`);
|
|
170
149
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
150
|
+
return checks;
|
|
151
|
+
}
|
|
152
|
+
switch (schema.type) {
|
|
153
|
+
case "string": {
|
|
154
|
+
checks.push(`typeof ${accessor} === "string"`);
|
|
155
|
+
if (hasPattern(schema)) {
|
|
156
|
+
checks.push(`/${escapeRegexPattern(schema.pattern)}/.test(${accessor})`);
|
|
157
|
+
}
|
|
158
|
+
if (hasMinLength(schema)) {
|
|
159
|
+
checks.push(`${accessor}.length >= ${schema.minLength}`);
|
|
160
|
+
}
|
|
161
|
+
if (hasMaxLength(schema)) {
|
|
162
|
+
checks.push(`${accessor}.length <= ${schema.maxLength}`);
|
|
163
|
+
}
|
|
164
|
+
break;
|
|
183
165
|
}
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
if (hasMinItems(schema)) {
|
|
227
|
-
checks.push(`${accessor}.length >= ${schema.minItems}`);
|
|
228
|
-
}
|
|
229
|
-
if (hasMaxItems(schema)) {
|
|
230
|
-
checks.push(`${accessor}.length <= ${schema.maxItems}`);
|
|
231
|
-
}
|
|
232
|
-
if (hasUniqueItems(schema) && schema.uniqueItems === true) {
|
|
233
|
-
checks.push(`new Set(${accessor}).size === ${accessor}.length`);
|
|
234
|
-
}
|
|
235
|
-
break;
|
|
236
|
-
case 'object': {
|
|
237
|
-
checks.push(`typeof ${accessor} === "object" && ${accessor} !== null && !Array.isArray(${accessor})`);
|
|
238
|
-
// Check required properties exist
|
|
239
|
-
if (hasRequired(schema) && schema.required.length > 0) {
|
|
240
|
-
for (const requiredKey of schema.required) {
|
|
241
|
-
checks.push(`${JSON.stringify(requiredKey)} in ${accessor}`);
|
|
242
|
-
}
|
|
243
|
-
}
|
|
244
|
-
// Check minProperties
|
|
245
|
-
if (hasMinProperties(schema)) {
|
|
246
|
-
checks.push(`Object.keys(${accessor}).length >= ${schema.minProperties}`);
|
|
247
|
-
}
|
|
248
|
-
// Check maxProperties
|
|
249
|
-
if (hasMaxProperties(schema)) {
|
|
250
|
-
checks.push(`Object.keys(${accessor}).length <= ${schema.maxProperties}`);
|
|
251
|
-
}
|
|
252
|
-
// Check additionalProperties
|
|
253
|
-
if (hasAdditionalProperties(schema) && schema.additionalProperties === false && hasProperties(schema)) {
|
|
254
|
-
const allowedKeys = Object.keys(schema.properties);
|
|
255
|
-
const allowedKeysStr = JSON.stringify(allowedKeys);
|
|
256
|
-
checks.push(`Object.keys(${accessor}).every(k => ${allowedKeysStr}.includes(k))`);
|
|
257
|
-
}
|
|
258
|
-
break;
|
|
166
|
+
case "number":
|
|
167
|
+
case "integer":
|
|
168
|
+
checks.push(`typeof ${accessor} === "number"`);
|
|
169
|
+
if (schema.type === "integer") {
|
|
170
|
+
checks.push(`Number.isInteger(${accessor})`);
|
|
171
|
+
}
|
|
172
|
+
if (hasMinimum(schema)) {
|
|
173
|
+
checks.push(`${accessor} >= ${schema.minimum}`);
|
|
174
|
+
}
|
|
175
|
+
if (hasMaximum(schema)) {
|
|
176
|
+
checks.push(`${accessor} <= ${schema.maximum}`);
|
|
177
|
+
}
|
|
178
|
+
if (hasExclusiveMinimum(schema)) {
|
|
179
|
+
checks.push(`${accessor} > ${schema.exclusiveMinimum}`);
|
|
180
|
+
}
|
|
181
|
+
if (hasExclusiveMaximum(schema)) {
|
|
182
|
+
checks.push(`${accessor} < ${schema.exclusiveMaximum}`);
|
|
183
|
+
}
|
|
184
|
+
if (hasMultipleOf(schema)) {
|
|
185
|
+
checks.push(multipleOfPassExpr(accessor, schema.multipleOf));
|
|
186
|
+
}
|
|
187
|
+
break;
|
|
188
|
+
case "boolean":
|
|
189
|
+
checks.push(`typeof ${accessor} === "boolean"`);
|
|
190
|
+
break;
|
|
191
|
+
case "array":
|
|
192
|
+
checks.push(`Array.isArray(${accessor})`);
|
|
193
|
+
if (hasMinItems(schema)) {
|
|
194
|
+
checks.push(`${accessor}.length >= ${schema.minItems}`);
|
|
195
|
+
}
|
|
196
|
+
if (hasMaxItems(schema)) {
|
|
197
|
+
checks.push(`${accessor}.length <= ${schema.maxItems}`);
|
|
198
|
+
}
|
|
199
|
+
if (hasUniqueItems(schema) && schema.uniqueItems === true) {
|
|
200
|
+
checks.push(`new Set(${accessor}).size === ${accessor}.length`);
|
|
201
|
+
}
|
|
202
|
+
break;
|
|
203
|
+
case "object": {
|
|
204
|
+
checks.push(`typeof ${accessor} === "object" && ${accessor} !== null && !Array.isArray(${accessor})`);
|
|
205
|
+
if (hasRequired(schema) && schema.required.length > 0) {
|
|
206
|
+
for (const requiredKey of schema.required) {
|
|
207
|
+
checks.push(`${JSON.stringify(requiredKey)} in ${accessor}`);
|
|
259
208
|
}
|
|
209
|
+
}
|
|
210
|
+
if (hasMinProperties(schema)) {
|
|
211
|
+
checks.push(`Object.keys(${accessor}).length >= ${schema.minProperties}`);
|
|
212
|
+
}
|
|
213
|
+
if (hasMaxProperties(schema)) {
|
|
214
|
+
checks.push(`Object.keys(${accessor}).length <= ${schema.maxProperties}`);
|
|
215
|
+
}
|
|
216
|
+
if (hasAdditionalProperties(schema) && schema.additionalProperties === false && hasProperties(schema)) {
|
|
217
|
+
const allowedKeys = Object.keys(schema.properties);
|
|
218
|
+
const allowedKeysStr = JSON.stringify(allowedKeys);
|
|
219
|
+
checks.push(`Object.keys(${accessor}).every(k => ${allowedKeysStr}.includes(k))`);
|
|
220
|
+
}
|
|
221
|
+
break;
|
|
260
222
|
}
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
223
|
+
}
|
|
224
|
+
if (hasEnum(schema) && schema.enum.length > 0) {
|
|
225
|
+
checks.push(generateEnumCheck(accessor, schema.enum));
|
|
226
|
+
}
|
|
227
|
+
return checks;
|
|
228
|
+
};
|
|
229
|
+
export {
|
|
230
|
+
generateSchemaChecks
|
|
265
231
|
};
|