@atolis-hq/corum 0.1.19 → 0.1.21
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/dist/src/adapters/asyncapi/mapper.js +69 -22
- package/dist/src/adapters/openapi/mapper.js +103 -75
- package/dist/src/web/server.js +24 -4
- package/package.json +1 -1
- package/web/app.jsx +60 -14
- package/web/primitives.jsx +115 -23
- package/web/style.css +5 -0
|
@@ -282,7 +282,7 @@ export function mapDocument(document, entry, packConfig, componentNameReplacemen
|
|
|
282
282
|
continue;
|
|
283
283
|
const [component] = registeredId.split('.');
|
|
284
284
|
nodes.push(makeNode(packConfig.constructs['payloadSchema']?.template ?? 'Schema', component, entry.spec, registeredId));
|
|
285
|
-
emitFields(s, registeredId, 'fields', undefined, packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, new Map());
|
|
285
|
+
emitFields(s, registeredId, 'fields', undefined, packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, new Map(), new Map());
|
|
286
286
|
}
|
|
287
287
|
const seenMessages = new Map();
|
|
288
288
|
const allOperations = document.allOperations().all();
|
|
@@ -338,7 +338,7 @@ export function mapDocument(document, entry, packConfig, componentNameReplacemen
|
|
|
338
338
|
const schemaId = deriveNodeId('schema', component, schemaKey, { parentId: eventId, section: 'schemas' });
|
|
339
339
|
nodes.push(makeNode(packConfig.constructs['payloadSchema']?.template ?? 'Schema', component, entry.spec, schemaId));
|
|
340
340
|
edges.push({ id: `${eventId}__has-field__${schemaId}`, from: eventId, to: schemaId, type: 'has-field', state: 'implemented', stability: 'unstable' });
|
|
341
|
-
emitFields(sourceSchema, schemaId, 'fields', eventId, packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, new Map());
|
|
341
|
+
emitFields(sourceSchema, schemaId, 'fields', eventId, packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, new Map(), new Map());
|
|
342
342
|
properties.payload = `#/schemas/${schemaKey}`;
|
|
343
343
|
}
|
|
344
344
|
}
|
|
@@ -347,7 +347,7 @@ export function mapDocument(document, entry, packConfig, componentNameReplacemen
|
|
|
347
347
|
const schemaId = deriveNodeId('schema', component, messageName, { parentId: eventId, section: 'schemas' });
|
|
348
348
|
nodes.push(makeNode(packConfig.constructs['payloadSchema']?.template ?? 'Schema', component, entry.spec, schemaId));
|
|
349
349
|
edges.push({ id: `${eventId}__has-field__${schemaId}`, from: eventId, to: schemaId, type: 'has-field', state: 'implemented', stability: 'unstable' });
|
|
350
|
-
emitFields(rawPayload, schemaId, 'fields', eventId, packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, new Map());
|
|
350
|
+
emitFields(rawPayload, schemaId, 'fields', eventId, packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, new Map(), new Map());
|
|
351
351
|
properties.payload = `#/schemas/${messageName}`;
|
|
352
352
|
}
|
|
353
353
|
else {
|
|
@@ -407,7 +407,7 @@ function resolveAllOfRef(schema) {
|
|
|
407
407
|
return s.allOf[0];
|
|
408
408
|
return schema;
|
|
409
409
|
}
|
|
410
|
-
function resolveSchemaRef(schemaName, nullable, collection, readsSource, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas) {
|
|
410
|
+
function resolveSchemaRef(schemaName, nullable, collection, readsSource, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
|
|
411
411
|
const extra = { nullable };
|
|
412
412
|
if (collection)
|
|
413
413
|
extra.collection = collection;
|
|
@@ -427,14 +427,61 @@ function resolveSchemaRef(schemaName, nullable, collection, readsSource, rootId,
|
|
|
427
427
|
edges.push({ id: `${rootId}__has-field__${inlineId}`, from: rootId, to: inlineId, type: 'has-field', state: 'implemented', stability: 'unstable' });
|
|
428
428
|
const localRef = `#/schemas/${schemaName}`;
|
|
429
429
|
localSchemas.set(schemaName, localRef);
|
|
430
|
-
emitFields(src, inlineId, 'fields', rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas);
|
|
430
|
+
emitFields(src, inlineId, 'fields', rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
431
431
|
}
|
|
432
432
|
return { $ref: localSchemas.get(schemaName) ?? `#/schemas/${schemaName}`, ...extra };
|
|
433
433
|
}
|
|
434
434
|
}
|
|
435
435
|
return { $ref: schemaName, ...extra };
|
|
436
436
|
}
|
|
437
|
-
function
|
|
437
|
+
function createMapping(mappingName, addlRaw, parentId, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
|
|
438
|
+
const existingId = localMappings.get(mappingName);
|
|
439
|
+
if (existingId)
|
|
440
|
+
return existingId;
|
|
441
|
+
const mappingId = `${parentId}.mappings.${mappingName}`;
|
|
442
|
+
const mappingNode = makeNode('Mapping', component, specPath, mappingId);
|
|
443
|
+
const props = {};
|
|
444
|
+
if (!addlRaw || typeof addlRaw === 'boolean') {
|
|
445
|
+
props['type'] = 'string';
|
|
446
|
+
}
|
|
447
|
+
else {
|
|
448
|
+
const addl = addlRaw;
|
|
449
|
+
if (addl.$ref) {
|
|
450
|
+
const schemaName = refName(addl.$ref);
|
|
451
|
+
const globalId = sharedSchemas.get(schemaName);
|
|
452
|
+
props['$ref'] = globalId ?? schemaName;
|
|
453
|
+
}
|
|
454
|
+
else if (addl.type === 'array') {
|
|
455
|
+
props['value-collection'] = 'array';
|
|
456
|
+
const items = addl.items ? resolveAllOfRef(addl.items) : undefined;
|
|
457
|
+
if (items && isRefSchema(items)) {
|
|
458
|
+
const schemaName = refName(items.$ref);
|
|
459
|
+
const globalId = sharedSchemas.get(schemaName);
|
|
460
|
+
props['$ref'] = globalId ?? schemaName;
|
|
461
|
+
}
|
|
462
|
+
else if (items) {
|
|
463
|
+
const it = items;
|
|
464
|
+
props['type'] = deriveScalarType(it.type ?? 'string', it.format, packConfig.scalarTypes) ?? 'string';
|
|
465
|
+
}
|
|
466
|
+
else {
|
|
467
|
+
props['type'] = 'string';
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
else if (addl.type === 'object' && addl.additionalProperties) {
|
|
471
|
+
const innerName = `${mappingName}-values`;
|
|
472
|
+
const innerId = createMapping(innerName, addl.additionalProperties, parentId, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
473
|
+
props['$ref'] = innerId;
|
|
474
|
+
}
|
|
475
|
+
else {
|
|
476
|
+
props['type'] = deriveScalarType(addl.type ?? 'string', addl.format, packConfig.scalarTypes) ?? 'string';
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
mappingNode.properties = props;
|
|
480
|
+
nodes.push(mappingNode);
|
|
481
|
+
localMappings.set(mappingName, mappingId);
|
|
482
|
+
return mappingId;
|
|
483
|
+
}
|
|
484
|
+
function emitFields(schema, parentId, section, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
|
|
438
485
|
const readsSource = rootId ?? parentId;
|
|
439
486
|
const [component] = parentId.split('.');
|
|
440
487
|
for (const [fieldName, rawFieldSchema] of Object.entries(schema.properties ?? {})) {
|
|
@@ -448,7 +495,7 @@ function emitFields(schema, parentId, section, rootId, packConfig, specPath, nod
|
|
|
448
495
|
? resolvedSchemaId
|
|
449
496
|
: (isRefSchema(fieldSchema) ? refName(fieldSchema.$ref) : undefined);
|
|
450
497
|
if (schemaName !== undefined) {
|
|
451
|
-
fieldNode.properties = resolveSchemaRef(schemaName, !required, undefined, readsSource, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas);
|
|
498
|
+
fieldNode.properties = resolveSchemaRef(schemaName, !required, undefined, readsSource, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
452
499
|
}
|
|
453
500
|
else {
|
|
454
501
|
const fs = fieldSchema;
|
|
@@ -467,7 +514,7 @@ function emitFields(schema, parentId, section, rootId, packConfig, specPath, nod
|
|
|
467
514
|
fieldNode.properties = { type: 'string', nullable, collection: 'array' };
|
|
468
515
|
}
|
|
469
516
|
else if (isRefSchema(items)) {
|
|
470
|
-
fieldNode.properties = resolveSchemaRef(refName(items.$ref), nullable, 'array', readsSource, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas);
|
|
517
|
+
fieldNode.properties = resolveSchemaRef(refName(items.$ref), nullable, 'array', readsSource, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
471
518
|
if (!fieldNode.properties.$ref)
|
|
472
519
|
fieldNode.properties = { type: 'string', nullable, collection: 'array' };
|
|
473
520
|
}
|
|
@@ -477,21 +524,21 @@ function emitFields(schema, parentId, section, rootId, packConfig, specPath, nod
|
|
|
477
524
|
}
|
|
478
525
|
}
|
|
479
526
|
else if (rawType === 'object' && fs.properties) {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
}
|
|
489
|
-
fieldNode.properties = { $ref: localSchemas.get(fieldName) ?? `#/schemas/${fieldName}`, nullable };
|
|
490
|
-
}
|
|
491
|
-
else {
|
|
492
|
-
diagnostics.push({ severity: 'warning', file: specPath, message: `Inline object field "${fieldId}" has no event context — treating as string` });
|
|
493
|
-
fieldNode.properties = { type: 'string', nullable };
|
|
527
|
+
const schemaParent = rootId ?? parentId;
|
|
528
|
+
const inlineId = deriveNodeId('schema', component, fieldName, { parentId: schemaParent, section: 'schemas' });
|
|
529
|
+
if (!nodes.some(n => n.id === inlineId)) {
|
|
530
|
+
nodes.push(makeNode(packConfig.constructs['payloadSchema']?.template ?? 'Schema', component, specPath, inlineId));
|
|
531
|
+
edges.push({ id: `${schemaParent}__has-field__${inlineId}`, from: schemaParent, to: inlineId, type: 'has-field', state: 'implemented', stability: 'unstable' });
|
|
532
|
+
const localRef = `#/schemas/${fieldName}`;
|
|
533
|
+
localSchemas.set(fieldName, localRef);
|
|
534
|
+
emitFields(fs, inlineId, 'fields', rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
494
535
|
}
|
|
536
|
+
fieldNode.properties = { $ref: localSchemas.get(fieldName) ?? `#/schemas/${fieldName}`, nullable };
|
|
537
|
+
}
|
|
538
|
+
else if (rawType === 'object' && fs.additionalProperties) {
|
|
539
|
+
// Map/dictionary: emit a Mapping node scoped to the parent schema, ref it from the field
|
|
540
|
+
createMapping(fieldName, fs.additionalProperties, parentId, rootId, component, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
541
|
+
fieldNode.properties = { $ref: `#/mappings/${fieldName}`, nullable };
|
|
495
542
|
}
|
|
496
543
|
else {
|
|
497
544
|
const scalarType = deriveScalarType(rawType, fs.format, packConfig.scalarTypes);
|
|
@@ -106,7 +106,7 @@ export function mapDocument(document, entry, packConfig, componentNameReplacemen
|
|
|
106
106
|
const [component] = schemaId.split('.');
|
|
107
107
|
const node = makeNode(packConfig.constructs.requestSchema?.template ?? 'Schema', component, entry.spec, schemaId);
|
|
108
108
|
nodes.push(node);
|
|
109
|
-
emitFields(s, schemaId, 'fields', undefined, packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, new Map());
|
|
109
|
+
emitFields(s, schemaId, 'fields', undefined, packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, new Map(), new Map());
|
|
110
110
|
}
|
|
111
111
|
}
|
|
112
112
|
for (const [urlPath, pathItem] of Object.entries(document.paths ?? {})) {
|
|
@@ -140,11 +140,12 @@ export function mapDocument(document, entry, packConfig, componentNameReplacemen
|
|
|
140
140
|
if (parameters)
|
|
141
141
|
endpointNode.properties.parameters = parameters;
|
|
142
142
|
const localSchemas = new Map();
|
|
143
|
+
const localMappings = new Map();
|
|
143
144
|
const requestBody = operation.requestBody;
|
|
144
145
|
if (requestBody?.content) {
|
|
145
146
|
const jsonContent = requestBody.content['application/json'];
|
|
146
147
|
if (jsonContent?.schema) {
|
|
147
|
-
const ref = emitSchemaNode(jsonContent.schema, `${operationId}-request`, endpointId, 'schemas', endpointId, packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas);
|
|
148
|
+
const ref = emitSchemaNode(jsonContent.schema, `${operationId}-request`, endpointId, 'schemas', endpointId, packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
148
149
|
if (ref)
|
|
149
150
|
endpointNode.properties.request = ref;
|
|
150
151
|
}
|
|
@@ -154,7 +155,7 @@ export function mapDocument(document, entry, packConfig, componentNameReplacemen
|
|
|
154
155
|
const responseObj = response;
|
|
155
156
|
const jsonContent = responseObj.content?.['application/json'];
|
|
156
157
|
if (jsonContent?.schema) {
|
|
157
|
-
const ref = emitSchemaNode(jsonContent.schema, `${operationId}-response-${status}`, endpointId, 'schemas', endpointId, packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas);
|
|
158
|
+
const ref = emitSchemaNode(jsonContent.schema, `${operationId}-response-${status}`, endpointId, 'schemas', endpointId, packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
158
159
|
if (ref)
|
|
159
160
|
responses[status] = ref;
|
|
160
161
|
}
|
|
@@ -276,7 +277,7 @@ function makeNode(template, component, specPath, id) {
|
|
|
276
277
|
properties: {},
|
|
277
278
|
};
|
|
278
279
|
}
|
|
279
|
-
function emitSchemaNode(schema, name, parentId, section, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas) {
|
|
280
|
+
function emitSchemaNode(schema, name, parentId, section, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
|
|
280
281
|
schema = resolveAllOfRef(schema);
|
|
281
282
|
if (isRefSchema(schema)) {
|
|
282
283
|
const schemaName = refName(schema.$ref);
|
|
@@ -291,15 +292,15 @@ function emitSchemaNode(schema, name, parentId, section, rootId, packConfig, spe
|
|
|
291
292
|
const sourceSchema = sourceSchemas.get(schemaName);
|
|
292
293
|
if (sourceSchema) {
|
|
293
294
|
const effectiveParent = rootId ?? parentId;
|
|
294
|
-
return createInlineSchema(sourceSchema, schemaName, effectiveParent, section, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas);
|
|
295
|
+
return createInlineSchema(sourceSchema, schemaName, effectiveParent, section, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
295
296
|
}
|
|
296
297
|
return undefined;
|
|
297
298
|
}
|
|
298
299
|
if (localSchemas.has(name))
|
|
299
300
|
return localSchemas.get(name);
|
|
300
|
-
return createInlineSchema(schema, name, parentId, section, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas);
|
|
301
|
+
return createInlineSchema(schema, name, parentId, section, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
301
302
|
}
|
|
302
|
-
function createInlineSchema(schema, name, parentId, section, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas) {
|
|
303
|
+
function createInlineSchema(schema, name, parentId, section, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
|
|
303
304
|
const schemaId = deriveNodeId('schema', undefined, name, parentId, section);
|
|
304
305
|
const [component] = parentId.split('.');
|
|
305
306
|
const node = makeNode(packConfig.constructs.requestSchema?.template ?? 'Schema', component, specPath, schemaId);
|
|
@@ -307,10 +308,10 @@ function createInlineSchema(schema, name, parentId, section, rootId, packConfig,
|
|
|
307
308
|
edges.push({ id: `${parentId}__has-field__${schemaId}`, from: parentId, to: schemaId, type: 'has-field', state: 'implemented', stability: 'unstable' });
|
|
308
309
|
const localRef = `#/${section}/${name}`;
|
|
309
310
|
localSchemas.set(name, localRef);
|
|
310
|
-
emitFields(schema, schemaId, 'fields', rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas);
|
|
311
|
+
emitFields(schema, schemaId, 'fields', rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
311
312
|
return localRef;
|
|
312
313
|
}
|
|
313
|
-
function resolveFieldRef(schemaName, collection, required, rootId, readsSource, refSchema, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas) {
|
|
314
|
+
function resolveFieldRef(schemaName, collection, required, rootId, readsSource, refSchema, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
|
|
314
315
|
const extra = { nullable: !required };
|
|
315
316
|
if (collection !== 'one')
|
|
316
317
|
extra.collection = collection;
|
|
@@ -322,13 +323,94 @@ function resolveFieldRef(schemaName, collection, required, rootId, readsSource,
|
|
|
322
323
|
if (localSchemas.has(schemaName))
|
|
323
324
|
return { $ref: localSchemas.get(schemaName), ...extra };
|
|
324
325
|
if (rootId) {
|
|
325
|
-
const localRef = emitSchemaNode(refSchema, schemaName, rootId, 'schemas', rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas);
|
|
326
|
+
const localRef = emitSchemaNode(refSchema, schemaName, rootId, 'schemas', rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
326
327
|
if (localRef)
|
|
327
328
|
return { $ref: localRef, ...extra };
|
|
328
329
|
}
|
|
329
330
|
return { $ref: schemaName, ...extra };
|
|
330
331
|
}
|
|
331
|
-
function
|
|
332
|
+
function createMapping(mappingName, addlRaw, parentId, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
|
|
333
|
+
const existingId = localMappings.get(mappingName);
|
|
334
|
+
if (existingId)
|
|
335
|
+
return existingId;
|
|
336
|
+
const [component] = parentId.split('.');
|
|
337
|
+
const mappingId = `${parentId}.mappings.${mappingName}`;
|
|
338
|
+
const mappingNode = makeNode('Mapping', component, specPath, mappingId);
|
|
339
|
+
const props = {};
|
|
340
|
+
if (typeof addlRaw === 'boolean' || addlRaw === undefined) {
|
|
341
|
+
props['type'] = 'string';
|
|
342
|
+
}
|
|
343
|
+
else {
|
|
344
|
+
const addlSchema = resolveAllOfRef(addlRaw);
|
|
345
|
+
if (isRefSchema(addlSchema)) {
|
|
346
|
+
const valueSchemaName = refName(addlSchema.$ref);
|
|
347
|
+
const globalId = sharedSchemas.get(valueSchemaName);
|
|
348
|
+
if (globalId) {
|
|
349
|
+
props['$ref'] = globalId;
|
|
350
|
+
}
|
|
351
|
+
else {
|
|
352
|
+
const localRef = localSchemas.get(valueSchemaName);
|
|
353
|
+
if (localRef) {
|
|
354
|
+
props['$ref'] = localRef;
|
|
355
|
+
}
|
|
356
|
+
else if (rootId) {
|
|
357
|
+
const emitted = emitSchemaNode(addlSchema, valueSchemaName, rootId, 'schemas', rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
358
|
+
props['$ref'] = emitted ?? valueSchemaName;
|
|
359
|
+
}
|
|
360
|
+
else {
|
|
361
|
+
props['$ref'] = valueSchemaName;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
}
|
|
365
|
+
else {
|
|
366
|
+
const addlObj = addlSchema;
|
|
367
|
+
if (addlObj.type === 'array') {
|
|
368
|
+
const rawItems = addlObj.items;
|
|
369
|
+
const items = rawItems ? resolveAllOfRef(rawItems) : undefined;
|
|
370
|
+
props['value-collection'] = 'array';
|
|
371
|
+
if (items && isRefSchema(items)) {
|
|
372
|
+
const valueSchemaName = refName(items.$ref);
|
|
373
|
+
const globalId = sharedSchemas.get(valueSchemaName);
|
|
374
|
+
if (globalId) {
|
|
375
|
+
props['$ref'] = globalId;
|
|
376
|
+
}
|
|
377
|
+
else {
|
|
378
|
+
const localRef = localSchemas.get(valueSchemaName);
|
|
379
|
+
if (localRef) {
|
|
380
|
+
props['$ref'] = localRef;
|
|
381
|
+
}
|
|
382
|
+
else if (rootId) {
|
|
383
|
+
const emitted = emitSchemaNode(items, valueSchemaName, rootId, 'schemas', rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
384
|
+
props['$ref'] = emitted ?? valueSchemaName;
|
|
385
|
+
}
|
|
386
|
+
else {
|
|
387
|
+
props['$ref'] = valueSchemaName;
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
else {
|
|
392
|
+
const scalarType = items ? deriveScalarType(items.type ?? 'string', items.format, packConfig.scalarTypes) : undefined;
|
|
393
|
+
props['type'] = scalarType ?? 'string';
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
else if (addlObj.type === 'object' && addlObj.additionalProperties) {
|
|
397
|
+
// map-of-map: inner additionalProperties → second Mapping node
|
|
398
|
+
const innerName = `${mappingName}-values`;
|
|
399
|
+
const innerRef = createMapping(innerName, addlObj.additionalProperties, parentId, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
400
|
+
props['$ref'] = innerRef;
|
|
401
|
+
}
|
|
402
|
+
else {
|
|
403
|
+
const scalarType = deriveScalarType(addlObj.type ?? 'string', addlObj.format, packConfig.scalarTypes);
|
|
404
|
+
props['type'] = scalarType ?? 'string';
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
}
|
|
408
|
+
mappingNode.properties = props;
|
|
409
|
+
nodes.push(mappingNode);
|
|
410
|
+
localMappings.set(mappingName, mappingId);
|
|
411
|
+
return mappingId;
|
|
412
|
+
}
|
|
413
|
+
function emitFields(schema, parentId, section, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings) {
|
|
332
414
|
// readsSource: when in endpoint context use rootId, otherwise use the schema itself
|
|
333
415
|
const readsSource = rootId ?? parentId;
|
|
334
416
|
for (const [fieldName, rawFieldSchema] of Object.entries(schema.properties ?? {})) {
|
|
@@ -338,7 +420,7 @@ function emitFields(schema, parentId, section, rootId, packConfig, specPath, nod
|
|
|
338
420
|
const fieldNode = makeNode(packConfig.constructs.schemaProperty?.template ?? 'Field', component, specPath, fieldId);
|
|
339
421
|
const required = Array.isArray(schema.required) && schema.required.includes(fieldName);
|
|
340
422
|
if (isRefSchema(fieldSchema)) {
|
|
341
|
-
fieldNode.properties = resolveFieldRef(refName(fieldSchema.$ref), 'one', required, rootId, readsSource, fieldSchema, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas);
|
|
423
|
+
fieldNode.properties = resolveFieldRef(refName(fieldSchema.$ref), 'one', required, rootId, readsSource, fieldSchema, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
342
424
|
}
|
|
343
425
|
else {
|
|
344
426
|
const fs = fieldSchema;
|
|
@@ -353,7 +435,7 @@ function emitFields(schema, parentId, section, rootId, packConfig, specPath, nod
|
|
|
353
435
|
fieldNode.properties = { type: 'string', nullable: !required, collection: 'array' };
|
|
354
436
|
}
|
|
355
437
|
else if (isRefSchema(items)) {
|
|
356
|
-
fieldNode.properties = resolveFieldRef(refName(items.$ref), 'array', required, rootId, readsSource, items, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas);
|
|
438
|
+
fieldNode.properties = resolveFieldRef(refName(items.$ref), 'array', required, rootId, readsSource, items, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
357
439
|
}
|
|
358
440
|
else {
|
|
359
441
|
const itemType = deriveScalarType(items.type ?? 'string', items.format, packConfig.scalarTypes);
|
|
@@ -362,70 +444,16 @@ function emitFields(schema, parentId, section, rootId, packConfig, specPath, nod
|
|
|
362
444
|
}
|
|
363
445
|
else if (fs.type === 'object' && fs.properties) {
|
|
364
446
|
// Anonymous object with named properties → inline as sibling schema
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
}
|
|
371
|
-
else {
|
|
372
|
-
diagnostics.push({ severity: 'warning', file: specPath, message: `Inline object for field ${fieldId} has no endpoint context; treating as string` });
|
|
373
|
-
fieldNode.properties = { type: 'string', nullable: !required };
|
|
374
|
-
}
|
|
447
|
+
const schemaParent = rootId ?? parentId;
|
|
448
|
+
const localRef = emitSchemaNode(fs, fieldName, schemaParent, 'schemas', rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
449
|
+
fieldNode.properties = localRef
|
|
450
|
+
? { $ref: localRef, nullable: !required }
|
|
451
|
+
: { type: 'string', nullable: !required };
|
|
375
452
|
}
|
|
376
453
|
else if (fs.type === 'object' && fs.additionalProperties) {
|
|
377
|
-
// Map/dictionary:
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
fieldNode.properties = { type: 'string', nullable: !required, collection: 'map' };
|
|
381
|
-
}
|
|
382
|
-
else {
|
|
383
|
-
const addlSchema = resolveAllOfRef(addlRaw);
|
|
384
|
-
if (isRefSchema(addlSchema)) {
|
|
385
|
-
fieldNode.properties = resolveFieldRef(refName(addlSchema.$ref), 'map', required, rootId, readsSource, addlSchema, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas);
|
|
386
|
-
}
|
|
387
|
-
else {
|
|
388
|
-
const addlObj = addlSchema;
|
|
389
|
-
if (addlObj.type === 'object') {
|
|
390
|
-
const innerAddl = addlObj.additionalProperties;
|
|
391
|
-
if (!innerAddl || typeof innerAddl === 'boolean') {
|
|
392
|
-
fieldNode.properties = { type: 'string', nullable: !required, collection: 'map-of-map' };
|
|
393
|
-
}
|
|
394
|
-
else {
|
|
395
|
-
const innerSchema = resolveAllOfRef(innerAddl);
|
|
396
|
-
if (isRefSchema(innerSchema)) {
|
|
397
|
-
fieldNode.properties = resolveFieldRef(refName(innerSchema.$ref), 'map-of-map', required, rootId, readsSource, innerSchema, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas);
|
|
398
|
-
}
|
|
399
|
-
else {
|
|
400
|
-
const inner = innerSchema;
|
|
401
|
-
const scalarType = deriveScalarType(inner.type ?? 'string', inner.format, packConfig.scalarTypes);
|
|
402
|
-
if (scalarType) {
|
|
403
|
-
fieldNode.properties = { type: scalarType, nullable: !required, collection: 'map-of-map' };
|
|
404
|
-
}
|
|
405
|
-
else {
|
|
406
|
-
diagnostics.push({ severity: 'warning', file: specPath, message: `[WARN] Double-nested map for field ${fieldId}; inner value type not representable, using string` });
|
|
407
|
-
fieldNode.properties = { type: 'string', nullable: !required, collection: 'map-of-map' };
|
|
408
|
-
}
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
else if (addlObj.type === 'array') {
|
|
413
|
-
const rawItems = addlObj.items;
|
|
414
|
-
const items = rawItems ? resolveAllOfRef(rawItems) : undefined;
|
|
415
|
-
if (items && isRefSchema(items)) {
|
|
416
|
-
fieldNode.properties = resolveFieldRef(refName(items.$ref), 'map-of-array', required, rootId, readsSource, items, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas);
|
|
417
|
-
}
|
|
418
|
-
else {
|
|
419
|
-
const scalarType = items ? deriveScalarType(items.type ?? 'string', items.format, packConfig.scalarTypes) : undefined;
|
|
420
|
-
fieldNode.properties = { type: scalarType ?? 'string', nullable: !required, collection: 'map-of-array' };
|
|
421
|
-
}
|
|
422
|
-
}
|
|
423
|
-
else {
|
|
424
|
-
const scalarType = deriveScalarType(addlObj.type ?? 'string', addlObj.format, packConfig.scalarTypes);
|
|
425
|
-
fieldNode.properties = { type: scalarType ?? 'string', nullable: !required, collection: 'map' };
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
}
|
|
454
|
+
// Map/dictionary: emit a Mapping node scoped to the parent schema, ref it from the field
|
|
455
|
+
createMapping(fieldName, fs.additionalProperties, parentId, rootId, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas, sourceSchemas, localSchemas, localMappings);
|
|
456
|
+
fieldNode.properties = { $ref: `#/mappings/${fieldName}`, nullable: !required };
|
|
429
457
|
}
|
|
430
458
|
else {
|
|
431
459
|
const scalarType = deriveScalarType(fs.type ?? 'string', fs.format, packConfig.scalarTypes);
|
package/dist/src/web/server.js
CHANGED
|
@@ -67,16 +67,36 @@ function summarizeNodeForNavigation(graph, node) {
|
|
|
67
67
|
...(ownership ?? {}),
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
|
+
function resolveLocalRef(graph, nodeId, section, name) {
|
|
71
|
+
// Walk up the node ID hierarchy to find the nearest ancestor owning section.name.
|
|
72
|
+
// This handles refs on both root nodes and nested Field nodes correctly.
|
|
73
|
+
let ancestor = nodeId.replace(/\.fields\.[^.]+$/, '');
|
|
74
|
+
while (ancestor.length > 0) {
|
|
75
|
+
const candidate = `${ancestor}.${section}.${name}`;
|
|
76
|
+
if (graph.nodesById.has(candidate))
|
|
77
|
+
return candidate;
|
|
78
|
+
const dot = ancestor.lastIndexOf('.');
|
|
79
|
+
if (dot === -1)
|
|
80
|
+
break;
|
|
81
|
+
ancestor = ancestor.slice(0, dot);
|
|
82
|
+
}
|
|
83
|
+
return undefined;
|
|
84
|
+
}
|
|
70
85
|
function resolveNodeRef(graph, node, rawValue) {
|
|
71
86
|
if (rawValue.startsWith('#/schemas/')) {
|
|
72
87
|
const name = rawValue.slice(10);
|
|
73
|
-
const id =
|
|
74
|
-
return
|
|
88
|
+
const id = resolveLocalRef(graph, node.id, 'schemas', name);
|
|
89
|
+
return id ? { display: name, nodeId: id } : { display: name };
|
|
75
90
|
}
|
|
76
91
|
if (rawValue.startsWith('#/enums/')) {
|
|
77
92
|
const name = rawValue.slice(8);
|
|
78
|
-
const id =
|
|
79
|
-
return
|
|
93
|
+
const id = resolveLocalRef(graph, node.id, 'enums', name);
|
|
94
|
+
return id ? { display: name, nodeId: id } : { display: name };
|
|
95
|
+
}
|
|
96
|
+
if (rawValue.startsWith('#/mappings/')) {
|
|
97
|
+
const name = rawValue.slice(11);
|
|
98
|
+
const id = resolveLocalRef(graph, node.id, 'mappings', name);
|
|
99
|
+
return id ? { display: name, nodeId: id } : { display: name };
|
|
80
100
|
}
|
|
81
101
|
if (graph.nodesById.has(rawValue))
|
|
82
102
|
return { display: rawValue, nodeId: rawValue };
|
package/package.json
CHANGED
package/web/app.jsx
CHANGED
|
@@ -83,23 +83,63 @@ function NavRail({ activeSection, onSection, debugMode, onDebugMode }) {
|
|
|
83
83
|
);
|
|
84
84
|
}
|
|
85
85
|
|
|
86
|
+
function entryKey(entry) {
|
|
87
|
+
return entry.kind === 'group' ? entry.groupTemplateName : entry.templateName;
|
|
88
|
+
}
|
|
89
|
+
|
|
86
90
|
function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds }) {
|
|
87
91
|
const sortedComponents = [...navTree.keys()].sort((a, b) => a.localeCompare(b));
|
|
88
92
|
const [openComponent, setOpenComponent] = useState();
|
|
93
|
+
const [openEntryKeys, setOpenEntryKeys] = useState(new Set());
|
|
89
94
|
const templateMap = new Map(templates.map(template => [template.name, template]));
|
|
90
95
|
|
|
96
|
+
function openComponentWithEntries(component) {
|
|
97
|
+
setOpenComponent(component);
|
|
98
|
+
if (!component) { setOpenEntryKeys(new Set()); return; }
|
|
99
|
+
const entries = navTree.get(component) ?? [];
|
|
100
|
+
setOpenEntryKeys(entries.length === 1 ? new Set([entryKey(entries[0])]) : new Set());
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Initialise / recover openComponent when the tree first loads or the open component disappears.
|
|
91
104
|
useEffect(() => {
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
}
|
|
96
|
-
if (openComponent !== null && !navTree.has(openComponent)) {
|
|
97
|
-
setOpenComponent(sortedComponents[0] ?? null);
|
|
98
|
-
}
|
|
105
|
+
const autoOpen = sortedComponents.length === 1 ? sortedComponents[0] : null;
|
|
106
|
+
if (openComponent === undefined) { openComponentWithEntries(autoOpen); return; }
|
|
107
|
+
if (openComponent !== null && !navTree.has(openComponent)) { openComponentWithEntries(autoOpen); }
|
|
99
108
|
}, [navTree, openComponent, sortedComponents]);
|
|
100
109
|
|
|
110
|
+
// When navigating directly to a node (e.g. via link), open its component and entry.
|
|
111
|
+
useEffect(() => {
|
|
112
|
+
if (!activeNodeId || !navTree.size) return;
|
|
113
|
+
for (const [component, entries] of navTree.entries()) {
|
|
114
|
+
for (const entry of entries) {
|
|
115
|
+
const eKey = entryKey(entry);
|
|
116
|
+
let found = false;
|
|
117
|
+
if (entry.kind === 'group') {
|
|
118
|
+
found = entry.children.some(child => child.nodes.some(n => n.id === activeNodeId));
|
|
119
|
+
} else {
|
|
120
|
+
found = entry.nodes.some(n => n.id === activeNodeId) ||
|
|
121
|
+
entry.nodes.some(n => (n.navChildren ?? []).some(g => g.nodes.some(c => c.id === activeNodeId)));
|
|
122
|
+
}
|
|
123
|
+
if (found) {
|
|
124
|
+
setOpenComponent(component);
|
|
125
|
+
setOpenEntryKeys(new Set([eKey]));
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}, [activeNodeId, navTree]);
|
|
131
|
+
|
|
101
132
|
function toggleComponent(component) {
|
|
102
|
-
|
|
133
|
+
if (openComponent === component) { openComponentWithEntries(null); }
|
|
134
|
+
else { openComponentWithEntries(component); }
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function toggleEntry(key) {
|
|
138
|
+
setOpenEntryKeys(prev => {
|
|
139
|
+
const next = new Set(prev);
|
|
140
|
+
if (next.has(key)) next.delete(key); else next.add(key);
|
|
141
|
+
return next;
|
|
142
|
+
});
|
|
103
143
|
}
|
|
104
144
|
|
|
105
145
|
if (navTree.size === 0) {
|
|
@@ -118,9 +158,11 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
|
|
|
118
158
|
</div>
|
|
119
159
|
{openComponent === component && entries.map(entry => {
|
|
120
160
|
if (entry.kind === 'group') {
|
|
161
|
+
const gKey = entryKey(entry);
|
|
162
|
+
const gOpen = openEntryKeys.has(gKey);
|
|
121
163
|
return (
|
|
122
164
|
<div key={entry.groupTemplateName}>
|
|
123
|
-
<div className="nav-template-head">
|
|
165
|
+
<div className="nav-template-head" onClick={() => toggleEntry(gKey)} style={{ cursor: 'pointer' }}>
|
|
124
166
|
{entry.icon && (
|
|
125
167
|
<i
|
|
126
168
|
className={`fa-solid fa-${entry.icon}`}
|
|
@@ -128,8 +170,9 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
|
|
|
128
170
|
/>
|
|
129
171
|
)}
|
|
130
172
|
<span>{entry.label}</span>
|
|
173
|
+
<Icon name={gOpen ? 'chevron-down' : 'chevron-right'} size={10} />
|
|
131
174
|
</div>
|
|
132
|
-
{entry.children.map(child => (
|
|
175
|
+
{gOpen && entry.children.map(child => (
|
|
133
176
|
<div key={child.templateName}>
|
|
134
177
|
<div className="nav-subtype-head">
|
|
135
178
|
{child.icon && (
|
|
@@ -167,16 +210,19 @@ function NavTree({ navTree, templates, activeNodeId, onNode, overlayIndicatorIds
|
|
|
167
210
|
|
|
168
211
|
const template = templateMap.get(entry.templateName);
|
|
169
212
|
const colour = template?.ui?.colour ?? 'var(--ink-4)';
|
|
213
|
+
const tKey = entryKey(entry);
|
|
214
|
+
const tOpen = openEntryKeys.has(tKey);
|
|
170
215
|
return (
|
|
171
216
|
<div key={entry.templateName}>
|
|
172
|
-
<div className="nav-template-head">
|
|
217
|
+
<div className="nav-template-head" onClick={() => toggleEntry(tKey)} style={{ cursor: 'pointer' }}>
|
|
173
218
|
<i
|
|
174
219
|
className={`fa-solid fa-${template?.ui?.icon ?? 'circle'}`}
|
|
175
220
|
style={{ fontSize: 12, width: 14, textAlign: 'center', flexShrink: 0 }}
|
|
176
221
|
/>
|
|
177
222
|
<span>{templateDisplayName(template)}</span>
|
|
223
|
+
<Icon name={tOpen ? 'chevron-down' : 'chevron-right'} size={10} />
|
|
178
224
|
</div>
|
|
179
|
-
{entry.nodes.map(node => {
|
|
225
|
+
{tOpen && entry.nodes.map(node => {
|
|
180
226
|
const isActive = node.id === activeNodeId;
|
|
181
227
|
return (
|
|
182
228
|
<div key={node.id}>
|
|
@@ -420,7 +466,7 @@ function NodePage({ nodeId, templates, onNavigate, refreshToken, viewingRef, ove
|
|
|
420
466
|
const rootSpecializedTemplates = new Set(['Schema', 'EnumDefinition']);
|
|
421
467
|
const rootSpecializedNodes = rootSpecializedTemplates.has(root.template) ? [[root.template, [root]]] : [];
|
|
422
468
|
const childDisplayEntries = [...displayChildren.entries()]
|
|
423
|
-
.filter(([templateName]) => templateName !== 'Field' && templateName !== 'EnumValue');
|
|
469
|
+
.filter(([templateName]) => templateName !== 'Field' && templateName !== 'EnumValue' && templateName !== 'Mapping');
|
|
424
470
|
const displayEntries = [...rootSpecializedNodes, ...childDisplayEntries];
|
|
425
471
|
const includedSchemaNodes = includedNodes.filter(n => n.template === 'Schema');
|
|
426
472
|
const includedEnumNodes = includedNodes.filter(n => n.template === 'EnumDefinition');
|
|
@@ -626,7 +672,7 @@ function App() {
|
|
|
626
672
|
|
|
627
673
|
const activeNodeId = route.pathname === '/node' ? route.params.get('id') : null;
|
|
628
674
|
const activeSection = activeNodeId ? 'components' : (route.pathname.slice(1) || 'dashboard');
|
|
629
|
-
const navTree = buildNavTree(nodes, templates);
|
|
675
|
+
const navTree = useMemo(() => buildNavTree(nodes, templates), [nodes, templates]);
|
|
630
676
|
const showTree = activeSection === 'components' || activeNodeId;
|
|
631
677
|
const activeOverlayRefs = useMemo(() =>
|
|
632
678
|
overlayMode === 'single' ? [] :
|
package/web/primitives.jsx
CHANGED
|
@@ -212,7 +212,7 @@ function fieldLocalName(nodeId) {
|
|
|
212
212
|
}
|
|
213
213
|
|
|
214
214
|
function clusterNodeId(nodeId) {
|
|
215
|
-
const sectionMatch = nodeId.match(/\.(schemas|enums|operations)\./);
|
|
215
|
+
const sectionMatch = nodeId.match(/\.(schemas|enums|mappings|operations)\./);
|
|
216
216
|
if (sectionMatch && sectionMatch.index !== undefined) {
|
|
217
217
|
return nodeId.slice(0, sectionMatch.index);
|
|
218
218
|
}
|
|
@@ -221,7 +221,7 @@ function clusterNodeId(nodeId) {
|
|
|
221
221
|
|
|
222
222
|
function refName(ref, compact = false) {
|
|
223
223
|
if (typeof ref === 'string') {
|
|
224
|
-
const full = ref.replace(/^#\/(schemas|enums)\//, '');
|
|
224
|
+
const full = ref.replace(/^#\/(schemas|enums|mappings)\//, '');
|
|
225
225
|
if (compact) {
|
|
226
226
|
const dot = full.lastIndexOf('.');
|
|
227
227
|
return dot >= 0 ? full.slice(dot + 1) : full;
|
|
@@ -249,6 +249,7 @@ function refLocalSchemaName(ref) {
|
|
|
249
249
|
return null;
|
|
250
250
|
}
|
|
251
251
|
if (ref.startsWith('#/schemas/')) return ref.slice(10);
|
|
252
|
+
if (ref.startsWith('#/mappings/')) return ref.slice(11);
|
|
252
253
|
// Global node ID (e.g. "component.Schema.TypeName") — local name is the final segment
|
|
253
254
|
const lastDot = ref.lastIndexOf('.');
|
|
254
255
|
return lastDot >= 0 ? ref.slice(lastDot + 1) : null;
|
|
@@ -256,7 +257,7 @@ function refLocalSchemaName(ref) {
|
|
|
256
257
|
|
|
257
258
|
function fieldType(properties, compact = false) {
|
|
258
259
|
const c = properties?.collection;
|
|
259
|
-
const suffix = c === 'array' ? '[]' :
|
|
260
|
+
const suffix = c === 'array' ? '[]' : '';
|
|
260
261
|
if (properties?.type) return `${properties.type}${suffix}`;
|
|
261
262
|
const ref = properties?.['$ref'];
|
|
262
263
|
if (ref) return `${refName(ref, compact)}${suffix}`;
|
|
@@ -325,7 +326,9 @@ function enumValueDescription(node) {
|
|
|
325
326
|
function buildSchemaModel(schemaNodes, allNodes) {
|
|
326
327
|
// Include all Schema nodes from allNodes so canExpand works for included/referenced schemas
|
|
327
328
|
const allSchemaNodes = (allNodes ?? []).filter(n => n.template === 'Schema');
|
|
329
|
+
const allMappingNodes = (allNodes ?? []).filter(n => n.template === 'Mapping');
|
|
328
330
|
const schemasByName = new Map(allSchemaNodes.map(node => [localSchemaName(node.id), node]));
|
|
331
|
+
const mappingsByNodeId = new Map(allMappingNodes.map(node => [node.id, node]));
|
|
329
332
|
// Ensure the primary schemaNodes are always present (they may not be in allNodes)
|
|
330
333
|
for (const node of schemaNodes) schemasByName.set(localSchemaName(node.id), node);
|
|
331
334
|
const fieldsBySchema = new Map();
|
|
@@ -348,11 +351,86 @@ function buildSchemaModel(schemaNodes, allNodes) {
|
|
|
348
351
|
const topSchemas = schemaNodes.filter(node => !referencedSchemas.has(localSchemaName(node.id)));
|
|
349
352
|
return {
|
|
350
353
|
schemasByName,
|
|
354
|
+
mappingsByNodeId,
|
|
351
355
|
fieldsBySchema,
|
|
352
356
|
topSchemas: topSchemas.length > 0 ? topSchemas : schemaNodes,
|
|
353
357
|
};
|
|
354
358
|
}
|
|
355
359
|
|
|
360
|
+
function MappingInlineRows({ mappingNode, depth, model, edges, compact, visited = new Set() }) {
|
|
361
|
+
const [valueCollapsed, setValueCollapsed] = React.useState(false);
|
|
362
|
+
const keyType = mappingNode.properties?.['key-type'];
|
|
363
|
+
const keyRef = mappingNode.properties?.['key-ref'];
|
|
364
|
+
const valueType = mappingNode.properties?.['type'];
|
|
365
|
+
const valueRef = mappingNode.properties?.['$ref'];
|
|
366
|
+
const valueRefNodeId = valueRef && typeof valueRef === 'object' && 'nodeId' in valueRef
|
|
367
|
+
? valueRef.nodeId : null;
|
|
368
|
+
const valueLocalRef = valueRef ? refLocalSchemaName(valueRef) : null;
|
|
369
|
+
const valueSchema = (valueLocalRef && model.schemasByName.has(valueLocalRef))
|
|
370
|
+
? model.schemasByName.get(valueLocalRef) : null;
|
|
371
|
+
const valueMappingNode = (valueRefNodeId && model.mappingsByNodeId?.has(valueRefNodeId))
|
|
372
|
+
? model.mappingsByNodeId.get(valueRefNodeId) : null;
|
|
373
|
+
const valueCanExpandSchema = !!valueSchema && !visited.has(valueLocalRef);
|
|
374
|
+
const valueCanExpandMapping = !!valueMappingNode && !visited.has(valueRefNodeId);
|
|
375
|
+
const valueCanExpand = valueCanExpandSchema || valueCanExpandMapping;
|
|
376
|
+
const keyDisplay = keyType ?? (keyRef ? refName(keyRef, compact) : 'string');
|
|
377
|
+
const valueDisplay = valueType ?? (valueRef ? refName(valueRef, compact) : '-');
|
|
378
|
+
const valueCollection = mappingNode.properties?.['value-collection'];
|
|
379
|
+
const nextVisited = new Set(visited);
|
|
380
|
+
if (valueLocalRef) nextVisited.add(valueLocalRef);
|
|
381
|
+
if (valueRefNodeId) nextVisited.add(valueRefNodeId);
|
|
382
|
+
|
|
383
|
+
return (
|
|
384
|
+
<>
|
|
385
|
+
<div className="field-row nested mapping-meta" style={{ '--field-depth': depth }}>
|
|
386
|
+
<div className="gutter" />
|
|
387
|
+
<div className="name">_key</div>
|
|
388
|
+
<div className="type">{keyDisplay}</div>
|
|
389
|
+
<div className="cardinality">-</div>
|
|
390
|
+
<div className="req">-</div>
|
|
391
|
+
<div className="state" />
|
|
392
|
+
<div className="lineage" />
|
|
393
|
+
</div>
|
|
394
|
+
<div className="field-row nested mapping-meta" style={{ '--field-depth': depth }}>
|
|
395
|
+
<div
|
|
396
|
+
className="gutter"
|
|
397
|
+
style={valueCanExpand ? { cursor: 'pointer' } : undefined}
|
|
398
|
+
onClick={valueCanExpand ? () => setValueCollapsed(prev => !prev) : undefined}
|
|
399
|
+
>
|
|
400
|
+
{valueCanExpand && <Icon name={valueCollapsed ? 'caret-right' : 'caret-down'} size={11} />}
|
|
401
|
+
</div>
|
|
402
|
+
<div className="name">_value</div>
|
|
403
|
+
<div className="type">{valueDisplay}</div>
|
|
404
|
+
<div className="cardinality">{valueCollection ?? 'one'}</div>
|
|
405
|
+
<div className="req">-</div>
|
|
406
|
+
<div className="state" />
|
|
407
|
+
<div className="lineage" />
|
|
408
|
+
</div>
|
|
409
|
+
{valueCanExpand && !valueCollapsed && (
|
|
410
|
+
valueCanExpandSchema ? (
|
|
411
|
+
<SchemaFieldRows
|
|
412
|
+
schemaName={valueLocalRef}
|
|
413
|
+
model={model}
|
|
414
|
+
depth={depth + 1}
|
|
415
|
+
visited={nextVisited}
|
|
416
|
+
edges={edges}
|
|
417
|
+
compact={compact}
|
|
418
|
+
/>
|
|
419
|
+
) : (
|
|
420
|
+
<MappingInlineRows
|
|
421
|
+
mappingNode={valueMappingNode}
|
|
422
|
+
depth={depth + 1}
|
|
423
|
+
model={model}
|
|
424
|
+
edges={edges}
|
|
425
|
+
compact={compact}
|
|
426
|
+
visited={nextVisited}
|
|
427
|
+
/>
|
|
428
|
+
)
|
|
429
|
+
)}
|
|
430
|
+
</>
|
|
431
|
+
);
|
|
432
|
+
}
|
|
433
|
+
|
|
356
434
|
function SchemaFieldRows({ schemaName, model, prefix = '', depth = 0, visited = new Set(), edges = [], overlayFields, overlayRefs, compact = false }) {
|
|
357
435
|
const [collapsed, setCollapsed] = React.useState(new Set());
|
|
358
436
|
const fields = model.fieldsBySchema.get(schemaName) ?? [];
|
|
@@ -376,11 +454,15 @@ function SchemaFieldRows({ schemaName, model, prefix = '', depth = 0, visited =
|
|
|
376
454
|
const name = fieldLocalName(field.id);
|
|
377
455
|
const ref = field.properties?.['$ref'];
|
|
378
456
|
const localRef = refLocalSchemaName(ref);
|
|
379
|
-
const
|
|
380
|
-
const
|
|
457
|
+
const refNodeId = ref && typeof ref === 'object' && 'nodeId' in ref ? ref.nodeId : null;
|
|
458
|
+
const mappingNode = refNodeId ? (model.mappingsByNodeId?.get(refNodeId) ?? null) : null;
|
|
459
|
+
const canExpandMapping = !!mappingNode;
|
|
460
|
+
const childSchemaNode = (!canExpandMapping && localRef) ? (model.schemasByName.get(localRef) ?? null) : null;
|
|
461
|
+
const canExpand = !!childSchemaNode && !visited.has(localRef);
|
|
462
|
+
const isExpandable = canExpand || canExpandMapping;
|
|
381
463
|
const childGhostFields = childSchemaNode ? overlayFieldsForSchema(overlayFields, childSchemaNode.id) : [];
|
|
382
464
|
const c = field.properties?.collection;
|
|
383
|
-
const childPrefix = `${prefix}${name}${c === '
|
|
465
|
+
const childPrefix = `${prefix}${name}${c === 'array' ? '[].' : '.'}`;
|
|
384
466
|
const nextVisited = new Set(visited);
|
|
385
467
|
nextVisited.add(schemaName);
|
|
386
468
|
const links = edges.filter(e =>
|
|
@@ -397,18 +479,18 @@ function SchemaFieldRows({ schemaName, model, prefix = '', depth = 0, visited =
|
|
|
397
479
|
<div className={`field-row${depth > 0 ? ' nested' : ''}`} style={{ '--field-depth': depth }}>
|
|
398
480
|
<div
|
|
399
481
|
className="gutter"
|
|
400
|
-
style={
|
|
401
|
-
onClick={
|
|
482
|
+
style={isExpandable ? { cursor: 'pointer' } : undefined}
|
|
483
|
+
onClick={isExpandable ? () => setCollapsed(prev => {
|
|
402
484
|
const next = new Set(prev);
|
|
403
485
|
next.has(field.id) ? next.delete(field.id) : next.add(field.id);
|
|
404
486
|
return next;
|
|
405
487
|
}) : undefined}
|
|
406
488
|
>
|
|
407
|
-
{
|
|
489
|
+
{isExpandable && <Icon name={isCollapsed ? 'caret-right' : 'caret-down'} size={11} />}
|
|
408
490
|
</div>
|
|
409
491
|
<div className="name">{compact ? name : `${prefix}${name}`}</div>
|
|
410
492
|
<div className="type" title={typeFull !== typeDisplay ? typeFull : undefined}>{typeDisplay}</div>
|
|
411
|
-
<div className="cardinality">{fieldCardinality(field.properties)}</div>
|
|
493
|
+
<div className="cardinality">{canExpandMapping ? 'map' : fieldCardinality(field.properties)}</div>
|
|
412
494
|
<div className="req">{fieldRequirement(field.properties)}</div>
|
|
413
495
|
<div className="state"><StateTag state={field.state} /></div>
|
|
414
496
|
<div className="lineage">
|
|
@@ -431,23 +513,33 @@ function SchemaFieldRows({ schemaName, model, prefix = '', depth = 0, visited =
|
|
|
431
513
|
: fieldDetails(field.properties, compact)}
|
|
432
514
|
</div>
|
|
433
515
|
</div>
|
|
434
|
-
{
|
|
435
|
-
|
|
436
|
-
<
|
|
437
|
-
|
|
438
|
-
model={model}
|
|
439
|
-
prefix={childPrefix}
|
|
516
|
+
{isExpandable && !isCollapsed && (
|
|
517
|
+
canExpandMapping ? (
|
|
518
|
+
<MappingInlineRows
|
|
519
|
+
mappingNode={mappingNode}
|
|
440
520
|
depth={depth + 1}
|
|
441
|
-
|
|
521
|
+
model={model}
|
|
442
522
|
edges={edges}
|
|
443
|
-
overlayFields={overlayFields}
|
|
444
|
-
overlayRefs={overlayRefs}
|
|
445
523
|
compact={compact}
|
|
446
524
|
/>
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
525
|
+
) : (
|
|
526
|
+
<>
|
|
527
|
+
<SchemaFieldRows
|
|
528
|
+
schemaName={localRef}
|
|
529
|
+
model={model}
|
|
530
|
+
prefix={childPrefix}
|
|
531
|
+
depth={depth + 1}
|
|
532
|
+
visited={nextVisited}
|
|
533
|
+
edges={edges}
|
|
534
|
+
overlayFields={overlayFields}
|
|
535
|
+
overlayRefs={overlayRefs}
|
|
536
|
+
compact={compact}
|
|
537
|
+
/>
|
|
538
|
+
{childGhostFields.length > 0 && (
|
|
539
|
+
<GhostFieldRows fields={childGhostFields} overlayRefs={overlayRefs} prefix={childPrefix} depth={depth + 1} compact={compact} />
|
|
540
|
+
)}
|
|
541
|
+
</>
|
|
542
|
+
)
|
|
451
543
|
)}
|
|
452
544
|
</React.Fragment>
|
|
453
545
|
);
|
package/web/style.css
CHANGED
|
@@ -785,6 +785,11 @@ button {
|
|
|
785
785
|
.signal-dot-0 { background: var(--accent); }
|
|
786
786
|
.signal-dot-1 { background: #5c7aa8; }
|
|
787
787
|
|
|
788
|
+
.field-row.mapping-meta .name {
|
|
789
|
+
color: var(--ink-3);
|
|
790
|
+
font-weight: 500;
|
|
791
|
+
}
|
|
792
|
+
|
|
788
793
|
.field-row.overlay-ghost {
|
|
789
794
|
opacity: 0.7;
|
|
790
795
|
background: color-mix(in oklch, var(--ink) 6%, var(--paper));
|