@kubb/ast 5.0.0-beta.12 → 5.0.0-beta.14
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/dist/index.cjs +41 -34
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +41 -35
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/utils.ts +7 -6
- package/src/visitor.ts +31 -31
package/dist/index.cjs
CHANGED
|
@@ -533,32 +533,36 @@ function createLimit(concurrency) {
|
|
|
533
533
|
* // returns parameters, requestBody schema (if present), and responses
|
|
534
534
|
* ```
|
|
535
535
|
*/
|
|
536
|
-
function getChildren(node, recurse) {
|
|
536
|
+
function* getChildren(node, recurse) {
|
|
537
537
|
switch (node.kind) {
|
|
538
|
-
case "Input":
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
if (
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
case "
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
case "
|
|
561
|
-
|
|
538
|
+
case "Input":
|
|
539
|
+
yield* node.schemas;
|
|
540
|
+
yield* node.operations;
|
|
541
|
+
break;
|
|
542
|
+
case "Output": break;
|
|
543
|
+
case "Operation":
|
|
544
|
+
yield* node.parameters;
|
|
545
|
+
if (node.requestBody?.content) {
|
|
546
|
+
for (const c of node.requestBody.content) if (c.schema) yield c.schema;
|
|
547
|
+
}
|
|
548
|
+
yield* node.responses;
|
|
549
|
+
break;
|
|
550
|
+
case "Schema":
|
|
551
|
+
if (!recurse) break;
|
|
552
|
+
if ("properties" in node && node.properties.length > 0) yield* node.properties;
|
|
553
|
+
if ("items" in node && node.items) yield* node.items;
|
|
554
|
+
if ("members" in node && node.members) yield* node.members;
|
|
555
|
+
if ("additionalProperties" in node && node.additionalProperties && node.additionalProperties !== true) yield node.additionalProperties;
|
|
556
|
+
break;
|
|
557
|
+
case "Property":
|
|
558
|
+
yield node.schema;
|
|
559
|
+
break;
|
|
560
|
+
case "Parameter":
|
|
561
|
+
yield node.schema;
|
|
562
|
+
break;
|
|
563
|
+
case "Response":
|
|
564
|
+
if (node.schema) yield node.schema;
|
|
565
|
+
break;
|
|
562
566
|
}
|
|
563
567
|
}
|
|
564
568
|
/**
|
|
@@ -745,10 +749,9 @@ function transform(node, options) {
|
|
|
745
749
|
* const values = collect(root, { depth: 'shallow', root: () => 'root' })
|
|
746
750
|
* ```
|
|
747
751
|
*/
|
|
748
|
-
function
|
|
752
|
+
function* collectLazy(node, options) {
|
|
749
753
|
const { depth, parent, ...visitor } = options;
|
|
750
754
|
const recurse = (depth ?? visitorDepths.deep) === visitorDepths.deep;
|
|
751
|
-
const results = [];
|
|
752
755
|
let v;
|
|
753
756
|
switch (node.kind) {
|
|
754
757
|
case "Input":
|
|
@@ -776,12 +779,14 @@ function collect(node, options) {
|
|
|
776
779
|
case "ParameterGroup":
|
|
777
780
|
case "FunctionParameters": break;
|
|
778
781
|
}
|
|
779
|
-
if (v !== void 0)
|
|
780
|
-
for (const child of getChildren(node, recurse))
|
|
782
|
+
if (v !== void 0) yield v;
|
|
783
|
+
for (const child of getChildren(node, recurse)) yield* collectLazy(child, {
|
|
781
784
|
...options,
|
|
782
785
|
parent: node
|
|
783
|
-
})
|
|
784
|
-
|
|
786
|
+
});
|
|
787
|
+
}
|
|
788
|
+
function collect(node, options) {
|
|
789
|
+
return Array.from(collectLazy(node, options));
|
|
785
790
|
}
|
|
786
791
|
//#endregion
|
|
787
792
|
//#region src/utils.ts
|
|
@@ -1331,7 +1336,7 @@ function collectUsedSchemaNames(operations, schemas) {
|
|
|
1331
1336
|
if (namedSchema) visitSchema(namedSchema);
|
|
1332
1337
|
}
|
|
1333
1338
|
}
|
|
1334
|
-
for (const op of operations) for (const schema of
|
|
1339
|
+
for (const op of operations) for (const schema of collectLazy(op, {
|
|
1335
1340
|
depth: "shallow",
|
|
1336
1341
|
schema: (node) => node
|
|
1337
1342
|
})) visitSchema(schema);
|
|
@@ -1380,11 +1385,12 @@ function findCircularSchemas(schemas) {
|
|
|
1380
1385
|
*/
|
|
1381
1386
|
function containsCircularRef(node, { circularSchemas, excludeName }) {
|
|
1382
1387
|
if (!node || circularSchemas.size === 0) return false;
|
|
1383
|
-
|
|
1388
|
+
for (const _ of collectLazy(node, { schema(child) {
|
|
1384
1389
|
if (child.type !== "ref") return void 0;
|
|
1385
1390
|
const name = resolveRefName(child);
|
|
1386
1391
|
return name && name !== excludeName && circularSchemas.has(name) ? true : void 0;
|
|
1387
|
-
} })
|
|
1392
|
+
} })) return true;
|
|
1393
|
+
return false;
|
|
1388
1394
|
}
|
|
1389
1395
|
//#endregion
|
|
1390
1396
|
//#region src/factory.ts
|
|
@@ -2219,6 +2225,7 @@ exports.caseParams = caseParams;
|
|
|
2219
2225
|
exports.childName = childName;
|
|
2220
2226
|
exports.collect = collect;
|
|
2221
2227
|
exports.collectImports = collectImports;
|
|
2228
|
+
exports.collectLazy = collectLazy;
|
|
2222
2229
|
exports.collectReferencedSchemaNames = collectReferencedSchemaNames;
|
|
2223
2230
|
exports.collectUsedSchemaNames = collectUsedSchemaNames;
|
|
2224
2231
|
exports.containsCircularRef = containsCircularRef;
|