@stackql/provider-utils 0.3.4 → 0.3.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stackql/provider-utils",
3
- "version": "0.3.4",
3
+ "version": "0.3.6",
4
4
  "description": "Utilities for building StackQL providers from OpenAPI specifications.",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
@@ -158,6 +158,15 @@ export async function generate(options) {
158
158
  const files = fs.readdirSync(inputDir);
159
159
 
160
160
  for (const filename of files) {
161
+
162
+ const filePath = path.join(inputDir, filename);
163
+
164
+ // Skip directories
165
+ if (fs.statSync(filePath).isDirectory()) {
166
+ logger.info(`📁 Skipping directory: ${filename}`);
167
+ continue;
168
+ }
169
+
161
170
  if (skipFiles.includes(filename)) {
162
171
  logger.info(`⭐️ Skipping ${filename} (matched --skip)`);
163
172
  continue;
@@ -153,6 +153,40 @@ function getAllRefs(obj) {
153
153
  return refs;
154
154
  }
155
155
 
156
+ /**
157
+ * Extract all $ref values from path-level parameters
158
+ * @param {Object} pathItem - Path item from OpenAPI doc
159
+ * @returns {Set<string>} - Set of refs
160
+ */
161
+ function getPathLevelRefs(pathItem) {
162
+ const refs = new Set();
163
+
164
+ // Check for path-level parameters
165
+ if (pathItem.parameters) {
166
+ for (const param of pathItem.parameters) {
167
+ if (param.$ref) {
168
+ refs.add(param.$ref);
169
+ } else if (typeof param === 'object') {
170
+ // Extract refs from schema if present
171
+ for (const ref of getAllRefs(param)) {
172
+ refs.add(ref);
173
+ }
174
+ }
175
+ }
176
+ }
177
+
178
+ // Check other non-operation fields
179
+ for (const [key, value] of Object.entries(pathItem)) {
180
+ if (!OPERATIONS.includes(key) && typeof value === 'object') {
181
+ for (const ref of getAllRefs(value)) {
182
+ refs.add(ref);
183
+ }
184
+ }
185
+ }
186
+
187
+ return refs;
188
+ }
189
+
156
190
  /**
157
191
  * Add referenced components to service
158
192
  * @param {Set<string>} refs - Set of refs
@@ -240,7 +274,7 @@ export async function split(options) {
240
274
  logger.level = 'debug';
241
275
  }
242
276
 
243
- logger.info(`📄 Splitting OpenAPI doc for ${providerName}`);
277
+ logger.info(`🔄 Splitting OpenAPI doc for ${providerName}`);
244
278
  logger.info(`API Doc: ${apiDoc}`);
245
279
  logger.info(`Output: ${outputDir}`);
246
280
  logger.info(`Service Discriminator: ${svcDiscriminator}`);
@@ -393,6 +427,26 @@ export async function split(options) {
393
427
  }
394
428
  }
395
429
  }
430
+
431
+ // After processing all operations in the path, collect path-level refs
432
+ const pathRefs = getPathLevelRefs(pathItem);
433
+
434
+ // Add path-level refs to all services that use this path
435
+ for (const svcName in services) {
436
+ if (services[svcName].paths[pathKey]) {
437
+ if (verbose) {
438
+ logger.debug(`Adding path-level refs for ${pathKey} to service ${svcName}`);
439
+ }
440
+
441
+ // Copy path-level parameters if they exist
442
+ if (pathItem.parameters) {
443
+ services[svcName].paths[pathKey].parameters = pathItem.parameters;
444
+ }
445
+
446
+ // Add references from path-level parameters
447
+ addRefsToComponents(pathRefs, services[svcName], apiDocObj.components || {}, verbose);
448
+ }
449
+ }
396
450
  }
397
451
 
398
452
  // Add non-operations to each service
@@ -476,10 +530,7 @@ export async function split(options) {
476
530
  for (const service in services) {
477
531
  logger.info(`✅ Writing out OpenAPI doc for [${service}]`);
478
532
 
479
- // const svcDir = path.join(outputDir, service);
480
- // const outputFile = path.join(svcDir, `${service}.yaml`);
481
533
  const outputFile = path.join(outputDir, `${service}.yaml`);
482
- // fs.mkdirSync(svcDir, { recursive: true });
483
534
 
484
535
  fs.writeFileSync(outputFile, yaml.dump(services[service], {
485
536
  noRefs: true,
@@ -489,4 +540,4 @@ export async function split(options) {
489
540
 
490
541
  logger.info(`🎉 Successfully split OpenAPI doc into ${Object.keys(services).length} services`);
491
542
  return true;
492
- }
543
+ }