@atolis-hq/corum 0.1.11 → 0.1.13

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,
@@ -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.11",
3
+ "version": "0.1.13",
4
4
  "type": "module",
5
5
  "repository": {
6
6
  "type": "git",