@stackql/provider-utils 0.3.5 → 0.3.7
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 +1 -1
- package/src/providerdev/split.js +54 -5
package/package.json
CHANGED
package/src/providerdev/split.js
CHANGED
|
@@ -153,6 +153,38 @@ 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
|
+
if (param.$ref.includes('/parameters/')) {
|
|
170
|
+
// Make sure we catch all parameters, especially path parameters
|
|
171
|
+
const paramName = param.$ref.split('/').pop();
|
|
172
|
+
if (paramName) {
|
|
173
|
+
refs.add(`#/components/parameters/${paramName}`);
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
} else if (typeof param === 'object') {
|
|
177
|
+
// Extract refs from schema if present
|
|
178
|
+
for (const ref of getAllRefs(param)) {
|
|
179
|
+
refs.add(ref);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
return refs;
|
|
186
|
+
}
|
|
187
|
+
|
|
156
188
|
/**
|
|
157
189
|
* Add referenced components to service
|
|
158
190
|
* @param {Set<string>} refs - Set of refs
|
|
@@ -240,7 +272,7 @@ export async function split(options) {
|
|
|
240
272
|
logger.level = 'debug';
|
|
241
273
|
}
|
|
242
274
|
|
|
243
|
-
logger.info(
|
|
275
|
+
logger.info(`🔄 Splitting OpenAPI doc for ${providerName}`);
|
|
244
276
|
logger.info(`API Doc: ${apiDoc}`);
|
|
245
277
|
logger.info(`Output: ${outputDir}`);
|
|
246
278
|
logger.info(`Service Discriminator: ${svcDiscriminator}`);
|
|
@@ -393,6 +425,26 @@ export async function split(options) {
|
|
|
393
425
|
}
|
|
394
426
|
}
|
|
395
427
|
}
|
|
428
|
+
|
|
429
|
+
// After processing all operations in the path, collect path-level refs
|
|
430
|
+
const pathRefs = getPathLevelRefs(pathItem);
|
|
431
|
+
|
|
432
|
+
// Add path-level refs to all services that use this path
|
|
433
|
+
for (const svcName in services) {
|
|
434
|
+
if (services[svcName].paths[pathKey]) {
|
|
435
|
+
if (verbose) {
|
|
436
|
+
logger.debug(`Adding path-level refs for ${pathKey} to service ${svcName}`);
|
|
437
|
+
}
|
|
438
|
+
|
|
439
|
+
// Copy path-level parameters if they exist
|
|
440
|
+
if (pathItem.parameters) {
|
|
441
|
+
services[svcName].paths[pathKey].parameters = pathItem.parameters;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
// Add references from path-level parameters
|
|
445
|
+
addRefsToComponents(pathRefs, services[svcName], apiDocObj.components || {}, verbose);
|
|
446
|
+
}
|
|
447
|
+
}
|
|
396
448
|
}
|
|
397
449
|
|
|
398
450
|
// Add non-operations to each service
|
|
@@ -476,10 +528,7 @@ export async function split(options) {
|
|
|
476
528
|
for (const service in services) {
|
|
477
529
|
logger.info(`✅ Writing out OpenAPI doc for [${service}]`);
|
|
478
530
|
|
|
479
|
-
// const svcDir = path.join(outputDir, service);
|
|
480
|
-
// const outputFile = path.join(svcDir, `${service}.yaml`);
|
|
481
531
|
const outputFile = path.join(outputDir, `${service}.yaml`);
|
|
482
|
-
// fs.mkdirSync(svcDir, { recursive: true });
|
|
483
532
|
|
|
484
533
|
fs.writeFileSync(outputFile, yaml.dump(services[service], {
|
|
485
534
|
noRefs: true,
|
|
@@ -489,4 +538,4 @@ export async function split(options) {
|
|
|
489
538
|
|
|
490
539
|
logger.info(`🎉 Successfully split OpenAPI doc into ${Object.keys(services).length} services`);
|
|
491
540
|
return true;
|
|
492
|
-
}
|
|
541
|
+
}
|