@atolis-hq/corum 0.1.9 → 0.1.11
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.
|
@@ -86,7 +86,6 @@ export function mapDocument(document, entry, packConfig) {
|
|
|
86
86
|
endpointNode.properties = {
|
|
87
87
|
method: method.toUpperCase(),
|
|
88
88
|
path: urlPath,
|
|
89
|
-
...(operation.operationId && { operationId: operation.operationId }),
|
|
90
89
|
...(operation.summary && { description: operation.summary }),
|
|
91
90
|
};
|
|
92
91
|
nodes.push(endpointNode);
|
|
@@ -94,16 +93,23 @@ export function mapDocument(document, entry, packConfig) {
|
|
|
94
93
|
if (requestBody?.content) {
|
|
95
94
|
const jsonContent = requestBody.content['application/json'];
|
|
96
95
|
if (jsonContent?.schema) {
|
|
97
|
-
emitSchemaNode(jsonContent.schema, `${operationId}-request`, endpointId, 'schemas', packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas);
|
|
96
|
+
const ref = emitSchemaNode(jsonContent.schema, `${operationId}-request`, endpointId, 'schemas', packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas);
|
|
97
|
+
if (ref)
|
|
98
|
+
endpointNode.properties.request = ref;
|
|
98
99
|
}
|
|
99
100
|
}
|
|
101
|
+
const responses = {};
|
|
100
102
|
for (const [status, response] of Object.entries(operation.responses ?? {})) {
|
|
101
103
|
const responseObj = response;
|
|
102
104
|
const jsonContent = responseObj.content?.['application/json'];
|
|
103
105
|
if (jsonContent?.schema) {
|
|
104
|
-
emitSchemaNode(jsonContent.schema, `${operationId}-response-${status}`, endpointId, 'schemas', packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas);
|
|
106
|
+
const ref = emitSchemaNode(jsonContent.schema, `${operationId}-response-${status}`, endpointId, 'schemas', packConfig, entry.spec, nodes, edges, diagnostics, sharedSchemas);
|
|
107
|
+
if (ref)
|
|
108
|
+
responses[status] = ref;
|
|
105
109
|
}
|
|
106
110
|
}
|
|
111
|
+
if (Object.keys(responses).length > 0)
|
|
112
|
+
endpointNode.properties.responses = responses;
|
|
107
113
|
}
|
|
108
114
|
}
|
|
109
115
|
return { nodes, edges, diagnostics };
|
|
@@ -125,13 +131,7 @@ function makeNode(template, component, specPath, id) {
|
|
|
125
131
|
}
|
|
126
132
|
function emitSchemaNode(schema, name, parentId, section, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas) {
|
|
127
133
|
if (isRefSchema(schema)) {
|
|
128
|
-
|
|
129
|
-
if (refId) {
|
|
130
|
-
const parent = nodes.find(n => n.id === parentId);
|
|
131
|
-
if (parent)
|
|
132
|
-
parent.properties[`${section}.${name}`] = refId;
|
|
133
|
-
}
|
|
134
|
-
return;
|
|
134
|
+
return sharedSchemas.get(refName(schema.$ref));
|
|
135
135
|
}
|
|
136
136
|
const schemaId = deriveNodeId('schema', undefined, name, parentId, section);
|
|
137
137
|
const [component] = parentId.split('.');
|
|
@@ -139,6 +139,7 @@ function emitSchemaNode(schema, name, parentId, section, packConfig, specPath, n
|
|
|
139
139
|
nodes.push(node);
|
|
140
140
|
edges.push({ id: `${parentId}__has-field__${schemaId}`, from: parentId, to: schemaId, type: 'has-field', state: 'implemented', stability: 'unstable' });
|
|
141
141
|
emitFields(schema, schemaId, 'fields', packConfig, specPath, nodes, edges, diagnostics, sharedSchemas);
|
|
142
|
+
return `#/${section}/${name}`;
|
|
142
143
|
}
|
|
143
144
|
function emitFields(schema, parentId, section, packConfig, specPath, nodes, edges, diagnostics, sharedSchemas) {
|
|
144
145
|
for (const [fieldName, fieldSchema] of Object.entries(schema.properties ?? {})) {
|
|
@@ -185,7 +186,8 @@ function deriveComponentForSchema(name, document, entry, visited = new Set()) {
|
|
|
185
186
|
if (visited.has(name))
|
|
186
187
|
return undefined;
|
|
187
188
|
visited.add(name);
|
|
188
|
-
// Direct:
|
|
189
|
+
// Direct: collect all components whose operations reference this schema
|
|
190
|
+
const directComponents = new Set();
|
|
189
191
|
for (const [urlPath, pathItem] of Object.entries(document.paths ?? {})) {
|
|
190
192
|
if (!pathItem)
|
|
191
193
|
continue;
|
|
@@ -195,12 +197,18 @@ function deriveComponentForSchema(name, document, entry, visited = new Set()) {
|
|
|
195
197
|
if (!operation)
|
|
196
198
|
continue;
|
|
197
199
|
if (referencesSchema(operation, name)) {
|
|
198
|
-
|
|
200
|
+
const component = entry.componentMapping.strategy === 'tag'
|
|
199
201
|
? operation.tags?.[0]
|
|
200
202
|
: deriveComponent(urlPath, entry.componentMapping);
|
|
203
|
+
if (component)
|
|
204
|
+
directComponents.add(component);
|
|
201
205
|
}
|
|
202
206
|
}
|
|
203
207
|
}
|
|
208
|
+
if (directComponents.size > 1)
|
|
209
|
+
return 'shared';
|
|
210
|
+
if (directComponents.size === 1)
|
|
211
|
+
return [...directComponents][0];
|
|
204
212
|
// Indirect: find another component schema that references this one and use its component
|
|
205
213
|
for (const [schemaName, schema] of Object.entries(document.components?.schemas ?? {})) {
|
|
206
214
|
if (schemaName === name || isRefSchema(schema))
|
package/package.json
CHANGED
package/web/primitives.jsx
CHANGED
|
@@ -168,7 +168,11 @@ function fieldSchemaName(nodeId) {
|
|
|
168
168
|
const fieldMarker = '.fields.';
|
|
169
169
|
const schemaIdx = nodeId.indexOf(schemaMarker);
|
|
170
170
|
const fieldIdx = nodeId.indexOf(fieldMarker);
|
|
171
|
-
if (
|
|
171
|
+
if (fieldIdx < 0) return null;
|
|
172
|
+
if (schemaIdx < 0) {
|
|
173
|
+
// Standalone Schema node: e.g. user.Schema.User.fields.email → 'User'
|
|
174
|
+
return nodeId.slice(0, fieldIdx).split('.').pop() ?? null;
|
|
175
|
+
}
|
|
172
176
|
return nodeId.slice(schemaIdx + schemaMarker.length, fieldIdx);
|
|
173
177
|
}
|
|
174
178
|
|