@atolis-hq/corum 0.1.10 → 0.1.12

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.
@@ -89,6 +89,9 @@ export function mapDocument(document, entry, packConfig) {
89
89
  ...(operation.summary && { description: operation.summary }),
90
90
  };
91
91
  nodes.push(endpointNode);
92
+ const parameters = extractParameters(pathItem, operation, packConfig, entry.spec, diagnostics);
93
+ if (parameters)
94
+ endpointNode.properties.parameters = parameters;
92
95
  const requestBody = operation.requestBody;
93
96
  if (requestBody?.content) {
94
97
  const jsonContent = requestBody.content['application/json'];
@@ -114,6 +117,56 @@ export function mapDocument(document, entry, packConfig) {
114
117
  }
115
118
  return { nodes, edges, diagnostics };
116
119
  }
120
+ function extractParameters(pathItem, operation, packConfig, specPath, diagnostics) {
121
+ const pathItemParams = (pathItem.parameters ?? []);
122
+ const operationParams = (operation.parameters ?? []);
123
+ const merged = new Map();
124
+ for (const param of [...pathItemParams, ...operationParams]) {
125
+ if (isRefSchema(param))
126
+ continue;
127
+ const p = param;
128
+ if (p.in === 'cookie')
129
+ continue;
130
+ merged.set(p.name, p);
131
+ }
132
+ if (merged.size === 0)
133
+ return undefined;
134
+ const parameters = {};
135
+ for (const [name, param] of merged) {
136
+ const schema = param.schema;
137
+ if (!schema)
138
+ continue;
139
+ let type;
140
+ let cardinality;
141
+ if (schema.type === 'array') {
142
+ cardinality = 'many';
143
+ const items = schema.items;
144
+ type = deriveScalarType(items?.type ?? 'string', items?.format, packConfig.scalarTypes) ?? 'string';
145
+ }
146
+ else if (schema.enum) {
147
+ cardinality = 'one';
148
+ type = 'string';
149
+ }
150
+ else {
151
+ cardinality = 'one';
152
+ const derived = deriveScalarType(schema.type ?? 'string', schema.format, packConfig.scalarTypes);
153
+ if (!derived) {
154
+ diagnostics.push({ severity: 'warning', file: specPath, message: `Unknown type for parameter ${name}: ${schema.type}/${schema.format}, defaulting to string` });
155
+ type = 'string';
156
+ }
157
+ else {
158
+ type = derived;
159
+ }
160
+ }
161
+ parameters[name] = {
162
+ location: param.in,
163
+ type,
164
+ required: param.required ?? false,
165
+ cardinality,
166
+ };
167
+ }
168
+ return Object.keys(parameters).length > 0 ? parameters : undefined;
169
+ }
117
170
  function makeNode(template, component, specPath, id) {
118
171
  return {
119
172
  id,
@@ -186,7 +239,8 @@ function deriveComponentForSchema(name, document, entry, visited = new Set()) {
186
239
  if (visited.has(name))
187
240
  return undefined;
188
241
  visited.add(name);
189
- // Direct: find an operation that references this schema
242
+ // Direct: collect all components whose operations reference this schema
243
+ const directComponents = new Set();
190
244
  for (const [urlPath, pathItem] of Object.entries(document.paths ?? {})) {
191
245
  if (!pathItem)
192
246
  continue;
@@ -196,12 +250,18 @@ function deriveComponentForSchema(name, document, entry, visited = new Set()) {
196
250
  if (!operation)
197
251
  continue;
198
252
  if (referencesSchema(operation, name)) {
199
- return entry.componentMapping.strategy === 'tag'
253
+ const component = entry.componentMapping.strategy === 'tag'
200
254
  ? operation.tags?.[0]
201
255
  : deriveComponent(urlPath, entry.componentMapping);
256
+ if (component)
257
+ directComponents.add(component);
202
258
  }
203
259
  }
204
260
  }
261
+ if (directComponents.size > 1)
262
+ return 'shared';
263
+ if (directComponents.size === 1)
264
+ return [...directComponents][0];
205
265
  // Indirect: find another component schema that references this one and use its component
206
266
  for (const [schemaName, schema] of Object.entries(document.components?.schemas ?? {})) {
207
267
  if (schemaName === name || isRefSchema(schema))
@@ -1,4 +1,3 @@
1
- const ADAPTER_OWNED = new Set(['method', 'path', 'operationId', 'type', 'nullable', 'cardinality', '$ref']);
2
1
  const HUMAN_OWNED = new Set(['state', 'stability', 'notes']);
3
2
  export function diffNodes(incoming, existing, specPath) {
4
3
  const toAdd = [];
@@ -12,7 +11,7 @@ export function diffNodes(incoming, existing, specPath) {
12
11
  }
13
12
  const merged = {
14
13
  ...current,
15
- properties: mergeProperties(current.properties, node.properties),
14
+ properties: mergeProperties(current.properties, node.properties, node.derivation),
16
15
  extractedFrom: node.extractedFrom,
17
16
  derivation: node.derivation,
18
17
  derivedBy: node.derivedBy,
@@ -32,14 +31,12 @@ export function diffNodes(incoming, existing, specPath) {
32
31
  }
33
32
  return { toAdd, toUpdate, toRemove };
34
33
  }
35
- function mergeProperties(current, incoming) {
36
- const merged = { ...current };
37
- for (const [key, value] of Object.entries(incoming)) {
38
- if (ADAPTER_OWNED.has(key)) {
39
- merged[key] = value;
40
- }
34
+ function mergeProperties(current, incoming, derivation) {
35
+ if (derivation === 'determined') {
36
+ const humanValues = Object.fromEntries(Object.entries(current).filter(([k]) => HUMAN_OWNED.has(k)));
37
+ return { ...incoming, ...humanValues };
41
38
  }
42
- return merged;
39
+ return { ...current, ...incoming };
43
40
  }
44
41
  function nodesEqual(a, b) {
45
42
  return JSON.stringify(a) === JSON.stringify(b);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atolis-hq/corum",
3
- "version": "0.1.10",
3
+ "version": "0.1.12",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",
@@ -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 (schemaIdx < 0 || fieldIdx < 0) return null;
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