@jsonforms/core 3.6.0 → 3.7.0-alpha.0
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/lib/jsonforms-core.cjs.js +133 -76
- package/lib/jsonforms-core.cjs.js.map +1 -1
- package/lib/jsonforms-core.esm.js +78 -21
- package/lib/jsonforms-core.esm.js.map +1 -1
- package/lib/util/resolvers.d.ts +2 -2
- package/package.json +2 -3
- package/src/util/resolvers.ts +161 -44
|
@@ -279,41 +279,98 @@ const findAllRefs = (schema, result = {}, resolveTuples = false) => {
|
|
|
279
279
|
};
|
|
280
280
|
const invalidSegment = (pathSegment) => pathSegment === '#' || pathSegment === undefined || pathSegment === '';
|
|
281
281
|
const resolveSchema = (schema, schemaPath, rootSchema) => {
|
|
282
|
-
const
|
|
283
|
-
|
|
282
|
+
const result = doResolveSchema(schema, schemaPath, {
|
|
283
|
+
rootSchema,
|
|
284
|
+
resolutionMap: new Map(),
|
|
285
|
+
});
|
|
286
|
+
return result;
|
|
284
287
|
};
|
|
285
|
-
const
|
|
286
|
-
|
|
287
|
-
|
|
288
|
+
const doResolveSchema = (schema, schemaPath, ctx) => {
|
|
289
|
+
let resolvedSchema = undefined;
|
|
290
|
+
if (schema && typeof schema.$ref === 'string') {
|
|
291
|
+
const baseSchema = resolvePath(ctx.rootSchema, schema.$ref, ctx);
|
|
292
|
+
if (baseSchema !== undefined) {
|
|
293
|
+
resolvedSchema = resolvePath(baseSchema, schemaPath, ctx);
|
|
294
|
+
}
|
|
295
|
+
}
|
|
296
|
+
if (resolvedSchema === undefined) {
|
|
297
|
+
resolvedSchema = resolvePath(schema, schemaPath, ctx);
|
|
298
|
+
}
|
|
299
|
+
return resolvedSchema;
|
|
300
|
+
};
|
|
301
|
+
const resolvePath = (schema, schemaPath, ctx) => {
|
|
302
|
+
let visitedPaths = ctx.resolutionMap.get(schema);
|
|
303
|
+
if (!visitedPaths) {
|
|
304
|
+
visitedPaths = new Set();
|
|
305
|
+
ctx.resolutionMap.set(schema, visitedPaths);
|
|
306
|
+
}
|
|
307
|
+
if (visitedPaths.has(schemaPath)) {
|
|
308
|
+
return undefined;
|
|
288
309
|
}
|
|
310
|
+
visitedPaths.add(schemaPath);
|
|
311
|
+
const resolvedSchema = resolvePathSegmentsWithCombinatorFallback(schema, schemaPath?.split('/').map(decode), ctx);
|
|
312
|
+
visitedPaths.delete(schemaPath);
|
|
313
|
+
return resolvedSchema;
|
|
314
|
+
};
|
|
315
|
+
const resolvePathSegmentsWithCombinatorFallback = (schema, pathSegments, ctx) => {
|
|
289
316
|
if (!pathSegments || pathSegments.length === 0) {
|
|
290
317
|
return schema;
|
|
291
318
|
}
|
|
292
319
|
if (isEmpty(schema)) {
|
|
293
320
|
return undefined;
|
|
294
321
|
}
|
|
295
|
-
const
|
|
296
|
-
if (
|
|
297
|
-
return resolveSchemaWithSegments(schema, remainingSegments, rootSchema);
|
|
298
|
-
}
|
|
299
|
-
const singleSegmentResolveSchema = get(schema, segment);
|
|
300
|
-
const resolvedSchema = resolveSchemaWithSegments(singleSegmentResolveSchema, remainingSegments, rootSchema);
|
|
301
|
-
if (resolvedSchema) {
|
|
322
|
+
const resolvedSchema = resolvePathSegments(schema, pathSegments, ctx);
|
|
323
|
+
if (resolvedSchema !== undefined) {
|
|
302
324
|
return resolvedSchema;
|
|
303
325
|
}
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
326
|
+
const subSchemas = [].concat(schema.oneOf ?? [], schema.allOf ?? [], schema.anyOf ?? [], schema.then ?? [], schema.else ?? []);
|
|
327
|
+
for (const subSchema of subSchemas) {
|
|
328
|
+
let resolvedSubSchema = subSchema;
|
|
329
|
+
if (subSchema && typeof subSchema.$ref === 'string') {
|
|
330
|
+
resolvedSubSchema = doResolveSchema(ctx.rootSchema, subSchema.$ref, ctx);
|
|
331
|
+
}
|
|
332
|
+
const alternativeResolveResult = resolvePathSegmentsWithCombinatorFallback(resolvedSubSchema, pathSegments, ctx);
|
|
333
|
+
if (alternativeResolveResult) {
|
|
334
|
+
return alternativeResolveResult;
|
|
312
335
|
}
|
|
313
|
-
return alternativeResolveResult;
|
|
314
336
|
}
|
|
315
337
|
return undefined;
|
|
316
338
|
};
|
|
339
|
+
const resolvePathSegments = (schema, pathSegments, ctx) => {
|
|
340
|
+
if (!pathSegments || pathSegments.length === 0) {
|
|
341
|
+
return schema;
|
|
342
|
+
}
|
|
343
|
+
if (isEmpty(schema)) {
|
|
344
|
+
return undefined;
|
|
345
|
+
}
|
|
346
|
+
const singleStepResult = resolveSingleStep(schema, pathSegments);
|
|
347
|
+
if (singleStepResult.schema &&
|
|
348
|
+
typeof singleStepResult.schema.$ref === 'string') {
|
|
349
|
+
singleStepResult.schema = doResolveSchema(ctx.rootSchema, singleStepResult.schema.$ref, ctx);
|
|
350
|
+
}
|
|
351
|
+
return resolvePathSegmentsWithCombinatorFallback(singleStepResult.schema, singleStepResult.remainingPathSegments, ctx);
|
|
352
|
+
};
|
|
353
|
+
const resolveSingleStep = (schema, pathSegments) => {
|
|
354
|
+
if (!pathSegments || pathSegments.length === 0) {
|
|
355
|
+
return { schema, remainingPathSegments: [] };
|
|
356
|
+
}
|
|
357
|
+
if (isEmpty(schema)) {
|
|
358
|
+
return {
|
|
359
|
+
schema: undefined,
|
|
360
|
+
remainingPathSegments: pathSegments,
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
const [segment, ...remainingPathSegments] = pathSegments;
|
|
364
|
+
if (invalidSegment(segment)) {
|
|
365
|
+
return resolveSingleStep(schema, remainingPathSegments);
|
|
366
|
+
}
|
|
367
|
+
const singleSegmentResolveSchema = get(schema, segment);
|
|
368
|
+
return {
|
|
369
|
+
schema: singleSegmentResolveSchema,
|
|
370
|
+
remainingPathSegments,
|
|
371
|
+
resolvedSegment: segment,
|
|
372
|
+
};
|
|
373
|
+
};
|
|
317
374
|
|
|
318
375
|
const Draft4 = {
|
|
319
376
|
id: 'http://json-schema.org/draft-04/schema#',
|