@orpc/json-schema 2.0.0-beta.5 → 2.0.0-beta.50
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/README.md +137 -102
- package/dist/coercer.d.ts +29 -0
- package/dist/coercer.js +354 -0
- package/dist/composition-utils.d.ts +37 -0
- package/dist/composition-utils.js +310 -0
- package/dist/constants.js +67 -0
- package/dist/convert.d.ts +29 -0
- package/dist/convert.js +12 -0
- package/dist/index.d.ts +11 -187
- package/dist/index.js +9 -0
- package/dist/ref-utils.d.ts +55 -0
- package/dist/ref-utils.js +203 -0
- package/dist/smart-coercion-handler-plugin.d.ts +22 -0
- package/dist/smart-coercion-handler-plugin.js +47 -0
- package/dist/smart-coercion-link-plugin.d.ts +28 -0
- package/dist/smart-coercion-link-plugin.js +63 -0
- package/dist/standard-json-schema-converter.d.ts +16 -0
- package/dist/standard-json-schema-converter.js +36 -0
- package/dist/types.d.ts +51 -0
- package/dist/types.js +42 -0
- package/dist/utils.d.ts +41 -0
- package/dist/utils.js +74 -0
- package/package.json +29 -22
- package/dist/index.d.mts +0 -187
- package/dist/index.mjs +0 -997
package/dist/coercer.js
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
import { resolveJsonSchemaLocalPointer } from "./ref-utils.js";
|
|
2
|
+
import "./types.js";
|
|
3
|
+
import { DEFAULT_MAX_BIGINT_DIGITS, INTEGER_REGEX, getOwn, isNonPrimitive, isPlainObject, isPlainObjectOrArray, parseBigIntString, toArray, tryOrUndefined } from "@orpc/shared";
|
|
4
|
+
// src/coercer.ts
|
|
5
|
+
/**
|
|
6
|
+
* How well a value matches a schema, used to pick the best union branch.
|
|
7
|
+
*/
|
|
8
|
+
const UNSATISFIED = 0;
|
|
9
|
+
/**
|
|
10
|
+
* Every keyword matches except some object keys or array items no schema describes.
|
|
11
|
+
* JSON Schema allows those, and validators usually strip or ignore them, but a branch
|
|
12
|
+
* that describes every key is still a better match.
|
|
13
|
+
*/
|
|
14
|
+
const LOOSELY_SATISFIED = 1;
|
|
15
|
+
/** Every keyword matches. */
|
|
16
|
+
const SATISFIED = 2;
|
|
17
|
+
const NATIVE_TYPES = /* @__PURE__ */ (() => /* @__PURE__ */ new Map([
|
|
18
|
+
["date", {
|
|
19
|
+
types: ["string"],
|
|
20
|
+
is: (value) => value instanceof Date,
|
|
21
|
+
coerce: (value) => typeof value === "string" ? stringToDate(value) : value
|
|
22
|
+
}],
|
|
23
|
+
["bigint", {
|
|
24
|
+
types: [
|
|
25
|
+
"string",
|
|
26
|
+
"integer",
|
|
27
|
+
"number"
|
|
28
|
+
],
|
|
29
|
+
is: (value) => typeof value === "bigint",
|
|
30
|
+
coerce: (value, { maxBigIntDigits }) => typeof value === "string" ? stringToBigInt(value, maxBigIntDigits) : typeof value === "number" ? numberToBigInt(value) : value
|
|
31
|
+
}],
|
|
32
|
+
["url", {
|
|
33
|
+
types: ["string"],
|
|
34
|
+
is: (value) => value instanceof URL,
|
|
35
|
+
coerce: (value) => typeof value === "string" ? stringToURL(value) : value
|
|
36
|
+
}],
|
|
37
|
+
["set", {
|
|
38
|
+
types: ["array"],
|
|
39
|
+
is: (value) => value instanceof Set,
|
|
40
|
+
coerce: (value) => Array.isArray(value) ? arrayToSet(value) : value,
|
|
41
|
+
afterTypeCheck: true
|
|
42
|
+
}],
|
|
43
|
+
["map", {
|
|
44
|
+
types: ["array"],
|
|
45
|
+
is: (value) => value instanceof Map,
|
|
46
|
+
coerce: (value) => Array.isArray(value) ? arrayToMap(value) : value,
|
|
47
|
+
afterTypeCheck: true
|
|
48
|
+
}]
|
|
49
|
+
]))();
|
|
50
|
+
function minSatisfaction(a, b) {
|
|
51
|
+
return a < b ? a : b;
|
|
52
|
+
}
|
|
53
|
+
const MIN_BUDGETED_VALUES = 100;
|
|
54
|
+
function createContext() {
|
|
55
|
+
return {
|
|
56
|
+
rootSchema: true,
|
|
57
|
+
memo: void 0,
|
|
58
|
+
memoize: false,
|
|
59
|
+
steps: 0,
|
|
60
|
+
maxSteps: 0,
|
|
61
|
+
input: void 0
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
var CoercionBudgetExceededError = class extends Error {};
|
|
65
|
+
var JsonSchemaCoercer = class {
|
|
66
|
+
nativeCoerceOptions;
|
|
67
|
+
maxStepsPerValue;
|
|
68
|
+
/** Reused between calls, since building a context is slow until V8 warms up. */
|
|
69
|
+
idleContext = createContext();
|
|
70
|
+
constructor(options = {}) {
|
|
71
|
+
this.nativeCoerceOptions = { maxBigIntDigits: options.maxBigIntDigits ?? DEFAULT_MAX_BIGINT_DIGITS };
|
|
72
|
+
this.maxStepsPerValue = options.maxStepsPerValue ?? 1e3;
|
|
73
|
+
}
|
|
74
|
+
coerce([schema, optional], value) {
|
|
75
|
+
if (optional && value === void 0) return value;
|
|
76
|
+
const context = this.idleContext ?? createContext();
|
|
77
|
+
this.idleContext = void 0;
|
|
78
|
+
context.rootSchema = schema;
|
|
79
|
+
context.memoize = false;
|
|
80
|
+
context.steps = 0;
|
|
81
|
+
context.maxSteps = this.maxStepsPerValue * MIN_BUDGETED_VALUES;
|
|
82
|
+
context.input = value;
|
|
83
|
+
try {
|
|
84
|
+
const [, coerced] = this.coerceInternal(context, schema, value);
|
|
85
|
+
return coerced;
|
|
86
|
+
} catch (error) {
|
|
87
|
+
if (error instanceof CoercionBudgetExceededError) return value;
|
|
88
|
+
throw error;
|
|
89
|
+
} finally {
|
|
90
|
+
context.memo = void 0;
|
|
91
|
+
context.input = void 0;
|
|
92
|
+
this.idleContext = context;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
coerceInternal(context, schema, value, appliedRefs) {
|
|
96
|
+
if (++context.steps > context.maxSteps) this.extendBudget(context);
|
|
97
|
+
if (typeof schema === "boolean") return [schema ? SATISFIED : UNSATISFIED, value];
|
|
98
|
+
if (Array.isArray(schema.type)) return this.coerceInternal(context, { anyOf: schema.type.map((type) => ({
|
|
99
|
+
...schema,
|
|
100
|
+
type
|
|
101
|
+
})) }, value, appliedRefs);
|
|
102
|
+
let coerced = value;
|
|
103
|
+
let satisfied = SATISFIED;
|
|
104
|
+
if (typeof schema.$ref === "string") {
|
|
105
|
+
const resolved = resolveJsonSchemaLocalPointer(context.rootSchema, schema.$ref);
|
|
106
|
+
if (resolved !== void 0 && !appliedRefs?.has(resolved)) {
|
|
107
|
+
if (schema.type === "object" || schema.type === "array") context.memoize = true;
|
|
108
|
+
const [subSatisfied, subCoerced] = this.coerceRef(context, resolved, coerced, appliedRefs);
|
|
109
|
+
coerced = subCoerced;
|
|
110
|
+
satisfied = minSatisfaction(satisfied, subSatisfied);
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
const enumValues = schema.const !== void 0 ? [schema.const] : schema.enum;
|
|
114
|
+
if (enumValues !== void 0 && !enumValues.includes(coerced)) {
|
|
115
|
+
if (typeof coerced === "string") {
|
|
116
|
+
const numberValue = stringToNumber(coerced);
|
|
117
|
+
if (enumValues.includes(numberValue)) coerced = numberValue;
|
|
118
|
+
else {
|
|
119
|
+
const booleanValue = stringToBoolean(coerced);
|
|
120
|
+
if (enumValues.includes(booleanValue)) coerced = booleanValue;
|
|
121
|
+
else satisfied = UNSATISFIED;
|
|
122
|
+
}
|
|
123
|
+
} else satisfied = UNSATISFIED;
|
|
124
|
+
}
|
|
125
|
+
const declaredNativeType = NATIVE_TYPES.get(schema["x-native-type"]);
|
|
126
|
+
const nativeType = schema.type === void 0 || declaredNativeType?.types.includes(schema.type) ? declaredNativeType : void 0;
|
|
127
|
+
if (nativeType && !nativeType.afterTypeCheck) coerced = nativeType.coerce(coerced, this.nativeCoerceOptions);
|
|
128
|
+
if (schema.type && !nativeType?.is(coerced)) switch (schema.type) {
|
|
129
|
+
case "null":
|
|
130
|
+
if (coerced !== null) satisfied = UNSATISFIED;
|
|
131
|
+
break;
|
|
132
|
+
case "string":
|
|
133
|
+
if (typeof coerced !== "string") satisfied = UNSATISFIED;
|
|
134
|
+
break;
|
|
135
|
+
case "number":
|
|
136
|
+
if (typeof coerced === "string") coerced = stringToNumber(coerced);
|
|
137
|
+
if (typeof coerced !== "number") satisfied = UNSATISFIED;
|
|
138
|
+
break;
|
|
139
|
+
case "integer":
|
|
140
|
+
if (typeof coerced === "string") coerced = stringToInteger(coerced);
|
|
141
|
+
if (typeof coerced !== "number" || !Number.isInteger(coerced)) satisfied = UNSATISFIED;
|
|
142
|
+
break;
|
|
143
|
+
case "boolean":
|
|
144
|
+
if (typeof coerced === "string") coerced = stringToBoolean(coerced);
|
|
145
|
+
if (typeof coerced !== "boolean") satisfied = UNSATISFIED;
|
|
146
|
+
break;
|
|
147
|
+
case "array":
|
|
148
|
+
if (Array.isArray(coerced)) {
|
|
149
|
+
const prefixItemSchemas = "prefixItems" in schema ? toArray(schema.prefixItems) : Array.isArray(schema.items) ? schema.items : [];
|
|
150
|
+
const itemSchema = Array.isArray(schema.items) ? schema.additionalItems : schema.items;
|
|
151
|
+
let shouldUseCoercedItems = false;
|
|
152
|
+
const coercedItems = coerced.map((item, i) => {
|
|
153
|
+
const subSchema = prefixItemSchemas[i] ?? itemSchema;
|
|
154
|
+
if (subSchema === void 0) {
|
|
155
|
+
satisfied = minSatisfaction(satisfied, LOOSELY_SATISFIED);
|
|
156
|
+
return item;
|
|
157
|
+
}
|
|
158
|
+
const [subSatisfied, subCoerced] = this.coerceInternal(context, subSchema, item);
|
|
159
|
+
satisfied = minSatisfaction(satisfied, subSatisfied);
|
|
160
|
+
if (subCoerced !== item) shouldUseCoercedItems = true;
|
|
161
|
+
return subCoerced;
|
|
162
|
+
});
|
|
163
|
+
if (typeof schema.minItems === "number" && coercedItems.length < schema.minItems) satisfied = UNSATISFIED;
|
|
164
|
+
if (shouldUseCoercedItems) coerced = coercedItems;
|
|
165
|
+
} else satisfied = UNSATISFIED;
|
|
166
|
+
break;
|
|
167
|
+
case "object":
|
|
168
|
+
if (Array.isArray(coerced)) coerced = { ...coerced };
|
|
169
|
+
if (isPlainObject(coerced)) {
|
|
170
|
+
let shouldUseCoercedItems = false;
|
|
171
|
+
const coercedItems = { ...coerced };
|
|
172
|
+
const patternProperties = Object.entries(schema.patternProperties ?? {}).flatMap(([key, value]) => {
|
|
173
|
+
const pattern = tryOrUndefined(() => new RegExp(key));
|
|
174
|
+
return pattern ? [[pattern, value]] : [];
|
|
175
|
+
});
|
|
176
|
+
const propertySchemas = schema.properties ?? {};
|
|
177
|
+
for (const key of Object.keys(coerced)) {
|
|
178
|
+
const value = coerced[key];
|
|
179
|
+
const subSchema = getOwn(propertySchemas, key) ?? patternProperties.find(([pattern]) => pattern.test(key))?.[1] ?? schema.additionalProperties;
|
|
180
|
+
if (value !== void 0 || schema.required?.includes(key)) {
|
|
181
|
+
if (subSchema === void 0) satisfied = minSatisfaction(satisfied, LOOSELY_SATISFIED);
|
|
182
|
+
else {
|
|
183
|
+
const [subSatisfied, subCoerced] = this.coerceInternal(context, subSchema, value);
|
|
184
|
+
coercedItems[key] = subCoerced;
|
|
185
|
+
satisfied = minSatisfaction(satisfied, subSatisfied);
|
|
186
|
+
if (subCoerced !== value) shouldUseCoercedItems = true;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
if (schema.required?.some((key) => !Object.hasOwn(coercedItems, key))) satisfied = UNSATISFIED;
|
|
191
|
+
if (shouldUseCoercedItems) coerced = coercedItems;
|
|
192
|
+
} else satisfied = UNSATISFIED;
|
|
193
|
+
}
|
|
194
|
+
if (nativeType) {
|
|
195
|
+
if (nativeType.afterTypeCheck) coerced = nativeType.coerce(coerced, this.nativeCoerceOptions);
|
|
196
|
+
if (!nativeType.is(coerced)) satisfied = UNSATISFIED;
|
|
197
|
+
}
|
|
198
|
+
if (schema.allOf) {
|
|
199
|
+
context.memoize = true;
|
|
200
|
+
for (const subSchema of schema.allOf) {
|
|
201
|
+
const [subSatisfied, subCoerced] = this.coerceInternal(context, subSchema, coerced, appliedRefs);
|
|
202
|
+
coerced = subCoerced;
|
|
203
|
+
satisfied = minSatisfaction(satisfied, subSatisfied);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
for (const key of ["anyOf", "oneOf"]) if (schema[key]) {
|
|
207
|
+
context.memoize = true;
|
|
208
|
+
/**
|
|
209
|
+
* The best branch is the first one that accepts the value untouched,
|
|
210
|
+
* then the most satisfied branch that accepts it after a conversion.
|
|
211
|
+
*/
|
|
212
|
+
let best;
|
|
213
|
+
for (const subSchema of schema[key]) {
|
|
214
|
+
const [subSatisfied, subCoerced] = this.coerceInternal(context, subSchema, coerced, appliedRefs);
|
|
215
|
+
if (subSatisfied === UNSATISFIED) continue;
|
|
216
|
+
if (subCoerced === coerced) {
|
|
217
|
+
best = {
|
|
218
|
+
satisfied: subSatisfied,
|
|
219
|
+
value: subCoerced
|
|
220
|
+
};
|
|
221
|
+
break;
|
|
222
|
+
}
|
|
223
|
+
if (!best || subSatisfied > best.satisfied) best = {
|
|
224
|
+
satisfied: subSatisfied,
|
|
225
|
+
value: subCoerced
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
if (best) {
|
|
229
|
+
coerced = best.value;
|
|
230
|
+
satisfied = minSatisfaction(satisfied, best.satisfied);
|
|
231
|
+
} else satisfied = UNSATISFIED;
|
|
232
|
+
}
|
|
233
|
+
if (typeof schema.not !== "undefined") {
|
|
234
|
+
context.memoize = true;
|
|
235
|
+
const [notSatisfied] = this.coerceInternal(context, schema.not, coerced, appliedRefs);
|
|
236
|
+
if (notSatisfied !== UNSATISFIED) satisfied = UNSATISFIED;
|
|
237
|
+
}
|
|
238
|
+
return [satisfied, coerced];
|
|
239
|
+
}
|
|
240
|
+
coerceRef(context, resolved, value, appliedRefs) {
|
|
241
|
+
let memo;
|
|
242
|
+
if (context.memoize && !appliedRefs?.size && isNonPrimitive(value)) {
|
|
243
|
+
context.memo ??= /* @__PURE__ */ new Map();
|
|
244
|
+
memo = context.memo.get(resolved);
|
|
245
|
+
if (!memo) {
|
|
246
|
+
memo = /* @__PURE__ */ new Map();
|
|
247
|
+
context.memo.set(resolved, memo);
|
|
248
|
+
}
|
|
249
|
+
const cached = memo.get(value);
|
|
250
|
+
if (cached) return cached;
|
|
251
|
+
}
|
|
252
|
+
appliedRefs ??= /* @__PURE__ */ new Set();
|
|
253
|
+
appliedRefs.add(resolved);
|
|
254
|
+
const result = this.coerceInternal(context, resolved, value, appliedRefs);
|
|
255
|
+
appliedRefs.delete(resolved);
|
|
256
|
+
memo?.set(value, result);
|
|
257
|
+
return result;
|
|
258
|
+
}
|
|
259
|
+
extendBudget(context) {
|
|
260
|
+
const limit = 2 * context.steps / this.maxStepsPerValue;
|
|
261
|
+
context.maxSteps = this.maxStepsPerValue * Math.max(countValues(context.input, limit), MIN_BUDGETED_VALUES);
|
|
262
|
+
if (context.steps > context.maxSteps) throw new CoercionBudgetExceededError();
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
function countValues(input, limit) {
|
|
266
|
+
const walked = /* @__PURE__ */ new Set();
|
|
267
|
+
const stack = [input];
|
|
268
|
+
let count = 1;
|
|
269
|
+
while (stack.length) {
|
|
270
|
+
const value = stack.pop();
|
|
271
|
+
if (isPlainObjectOrArray(value) && !walked.has(value)) {
|
|
272
|
+
walked.add(value);
|
|
273
|
+
const items = Array.isArray(value) ? value : Object.values(value);
|
|
274
|
+
for (let i = 0; i < items.length; i++) {
|
|
275
|
+
if (++count >= limit) return count;
|
|
276
|
+
const item = items[i];
|
|
277
|
+
if (isNonPrimitive(item)) stack.push(item);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
return count;
|
|
282
|
+
}
|
|
283
|
+
const NUMBER_PATTERN = /^-?(?:0|[1-9]\d*)(?:\.\d+)?$/;
|
|
284
|
+
function stringToNumber(value) {
|
|
285
|
+
if (!NUMBER_PATTERN.test(value)) return value;
|
|
286
|
+
const num = Number(value);
|
|
287
|
+
if (num < Number.MIN_SAFE_INTEGER || num > Number.MAX_SAFE_INTEGER) return value;
|
|
288
|
+
return num;
|
|
289
|
+
}
|
|
290
|
+
function stringToInteger(value) {
|
|
291
|
+
if (!INTEGER_REGEX.test(value)) return value;
|
|
292
|
+
const num = Number(value);
|
|
293
|
+
if (!Number.isSafeInteger(num)) return value;
|
|
294
|
+
return num;
|
|
295
|
+
}
|
|
296
|
+
function stringToBigInt(value, maxDigits) {
|
|
297
|
+
return parseBigIntString(value, maxDigits) ?? value;
|
|
298
|
+
}
|
|
299
|
+
function numberToBigInt(value) {
|
|
300
|
+
if (!Number.isInteger(value)) return value;
|
|
301
|
+
return BigInt(value);
|
|
302
|
+
}
|
|
303
|
+
function stringToBoolean(value) {
|
|
304
|
+
const lower = value.toLowerCase();
|
|
305
|
+
if (lower === "false" || lower === "off") return false;
|
|
306
|
+
if (lower === "true" || lower === "on") return true;
|
|
307
|
+
return value;
|
|
308
|
+
}
|
|
309
|
+
const DATE_TIME_PATTERN = /^(?!-0{6})(?:[+-]\d{2})?\d{4}-\d{2}-\d{2}(?:[T ]\d{2}:\d{2}(?::\d{2}(?:\.\d+)?)?(?:Z|[+-]\d{2}:?\d{2})?)?$/;
|
|
310
|
+
const DAYS_IN_MONTH = [
|
|
311
|
+
31,
|
|
312
|
+
29,
|
|
313
|
+
31,
|
|
314
|
+
30,
|
|
315
|
+
31,
|
|
316
|
+
30,
|
|
317
|
+
31,
|
|
318
|
+
31,
|
|
319
|
+
30,
|
|
320
|
+
31,
|
|
321
|
+
30,
|
|
322
|
+
31
|
|
323
|
+
];
|
|
324
|
+
function stringToDate(value) {
|
|
325
|
+
if (!DATE_TIME_PATTERN.test(value)) return value;
|
|
326
|
+
const yearEnd = value.indexOf("-", 1);
|
|
327
|
+
const month = readTwoDigits(value, yearEnd + 1);
|
|
328
|
+
const day = readTwoDigits(value, yearEnd + 4);
|
|
329
|
+
if (day < 1 || day > (DAYS_IN_MONTH[month - 1] ?? 0) || month === 2 && day === 29 && !isLeapYear(Number(value.slice(0, yearEnd)))) return value;
|
|
330
|
+
const date = new Date(value);
|
|
331
|
+
if (Number.isNaN(date.getTime())) return value;
|
|
332
|
+
return date;
|
|
333
|
+
}
|
|
334
|
+
function readTwoDigits(value, index) {
|
|
335
|
+
return (value.charCodeAt(index) - 48) * 10 + value.charCodeAt(index + 1) - 48;
|
|
336
|
+
}
|
|
337
|
+
function isLeapYear(year) {
|
|
338
|
+
return year % 4 === 0 && (year % 100 !== 0 || year % 400 === 0);
|
|
339
|
+
}
|
|
340
|
+
function stringToURL(value) {
|
|
341
|
+
return tryOrUndefined(() => new URL(value)) ?? value;
|
|
342
|
+
}
|
|
343
|
+
function arrayToSet(value) {
|
|
344
|
+
const set = new Set(value);
|
|
345
|
+
if (set.size !== value.length) return value;
|
|
346
|
+
return set;
|
|
347
|
+
}
|
|
348
|
+
function arrayToMap(value) {
|
|
349
|
+
if (value.some((item) => !Array.isArray(item) || item.length !== 2)) return value;
|
|
350
|
+
const result = new Map(value);
|
|
351
|
+
if (result.size !== value.length) return value;
|
|
352
|
+
return result;
|
|
353
|
+
}
|
|
354
|
+
export { JsonSchemaCoercer };
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { JsonSchema } from "./types.js";
|
|
2
|
+
import { JsonArraySchema, JsonObjectSchema } from "./utils.js";
|
|
3
|
+
/**
|
|
4
|
+
* Combines multiple schemas under the requested composition keyword, promoting branch `$defs` to the root.
|
|
5
|
+
*/
|
|
6
|
+
export declare function combineJsonSchemasWithComposition(keyword: "allOf" | "anyOf" | "oneOf", schemas: JsonSchema[]): JsonSchema;
|
|
7
|
+
export type JsonObjectSchemaEntry = [name: string, schema: JsonSchema, optional: boolean];
|
|
8
|
+
/**
|
|
9
|
+
* Combines object property entries back into a single object schema.
|
|
10
|
+
* When given, `additionalProperties` constrains every property the entries do not name.
|
|
11
|
+
*/
|
|
12
|
+
export declare function combineJsonObjectSchemaEntries(entries: JsonObjectSchemaEntry[], additionalProperties?: JsonSchema): JsonObjectSchema;
|
|
13
|
+
/**
|
|
14
|
+
* Parses an object schema, or a composition of object schemas, into property entries.
|
|
15
|
+
*/
|
|
16
|
+
export declare function extractJsonObjectSchemaEntries(schema: JsonSchema): JsonObjectSchemaEntry[] | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Returns the `additionalProperties` an object schema declares at its root, following root-local refs,
|
|
19
|
+
* with the root `$defs` attached so it can be passed to {@link combineJsonObjectSchemaEntries}.
|
|
20
|
+
* Composition branches are not inspected, since their keyword only constrains that branch.
|
|
21
|
+
*/
|
|
22
|
+
export declare function extractJsonObjectSchemaAdditionalProperties(schema: JsonSchema): JsonSchema | undefined;
|
|
23
|
+
/**
|
|
24
|
+
* Returns true when an object can stand for every value the schema describes: the schema constrains objects,
|
|
25
|
+
* by `type` or object keywords, composes only such schemas, or is unconstrained, since an object satisfies it.
|
|
26
|
+
* Unlike {@link extractJsonObjectSchemaEntries}, an unconstrained schema counts as object-like.
|
|
27
|
+
*/
|
|
28
|
+
export declare function isJsonObjectLikeSchema(schema: JsonSchema): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Flattens `anyOf` and `oneOf` unions when they are the only active constraints.
|
|
31
|
+
*/
|
|
32
|
+
export declare function flattenJsonUnionSchema(schema: JsonSchema): JsonSchema[];
|
|
33
|
+
/**
|
|
34
|
+
* Matches a union made of a single item schema and its array form.
|
|
35
|
+
*/
|
|
36
|
+
export declare function matchArrayableJsonSchema(schema: JsonSchema): undefined | [itemSchema: JsonSchema, arraySchema: JsonArraySchema];
|
|
37
|
+
export declare function deduplicateJsonSchemas(schemas: JsonSchema[]): JsonSchema[];
|