@kubb/ast 5.0.0-beta.27 → 5.0.0-beta.29
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 +29 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +43 -15
- package/dist/index.js +29 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/factory.ts +15 -4
- package/src/nodes/response.ts +34 -13
- package/src/utils.ts +12 -1
- package/src/visitor.ts +9 -2
package/dist/index.cjs
CHANGED
|
@@ -605,7 +605,9 @@ function* getChildren(node, recurse) {
|
|
|
605
605
|
return;
|
|
606
606
|
}
|
|
607
607
|
if (node.kind === "Response") {
|
|
608
|
-
if (node.
|
|
608
|
+
if (node.content) {
|
|
609
|
+
for (const c of node.content) if (c.schema) yield c.schema;
|
|
610
|
+
}
|
|
609
611
|
return;
|
|
610
612
|
}
|
|
611
613
|
}
|
|
@@ -741,10 +743,13 @@ function transform(node, options) {
|
|
|
741
743
|
const response = visitor.response?.(node, { parent }) ?? node;
|
|
742
744
|
return {
|
|
743
745
|
...response,
|
|
744
|
-
|
|
745
|
-
...
|
|
746
|
-
|
|
747
|
-
|
|
746
|
+
content: response.content?.map((entry) => ({
|
|
747
|
+
...entry,
|
|
748
|
+
schema: entry.schema ? transform(entry.schema, {
|
|
749
|
+
...options,
|
|
750
|
+
parent: response
|
|
751
|
+
}) : entry.schema
|
|
752
|
+
}))
|
|
748
753
|
};
|
|
749
754
|
}
|
|
750
755
|
return node;
|
|
@@ -1213,6 +1218,11 @@ function combineImports(imports, exports, source) {
|
|
|
1213
1218
|
if (!importNameMemo.has(key)) importNameMemo.set(key, n);
|
|
1214
1219
|
return importNameMemo.get(key);
|
|
1215
1220
|
};
|
|
1221
|
+
const pathsWithUsedNamedImport = /* @__PURE__ */ new Set();
|
|
1222
|
+
for (const node of imports) {
|
|
1223
|
+
if (!Array.isArray(node.name)) continue;
|
|
1224
|
+
if (node.name.some((item) => typeof item === "string" ? isUsed(item) : isUsed(item.name ?? item.propertyName))) pathsWithUsedNamedImport.add(node.path);
|
|
1225
|
+
}
|
|
1216
1226
|
const result = [];
|
|
1217
1227
|
const namedByPath = /* @__PURE__ */ new Map();
|
|
1218
1228
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -1243,7 +1253,7 @@ function combineImports(imports, exports, source) {
|
|
|
1243
1253
|
namedByPath.set(key, newItem);
|
|
1244
1254
|
}
|
|
1245
1255
|
} else {
|
|
1246
|
-
if (name && !isUsed(name)) continue;
|
|
1256
|
+
if (name && !isUsed(name) && !pathsWithUsedNamedImport.has(path)) continue;
|
|
1247
1257
|
const key = importKey(path, name, isTypeOnly);
|
|
1248
1258
|
if (!seen.has(key)) {
|
|
1249
1259
|
result.push(curr);
|
|
@@ -1659,19 +1669,28 @@ function createParameter(props) {
|
|
|
1659
1669
|
/**
|
|
1660
1670
|
* Creates a `ResponseNode`.
|
|
1661
1671
|
*
|
|
1672
|
+
* Response body schemas live inside `content`. For convenience a single legacy `schema`
|
|
1673
|
+
* (with optional `mediaType`/`keysToOmit`) is normalized into one `content` entry, so the same
|
|
1674
|
+
* schema is never stored both at the node root and inside `content`.
|
|
1675
|
+
*
|
|
1662
1676
|
* @example
|
|
1663
1677
|
* ```ts
|
|
1664
1678
|
* const response = createResponse({
|
|
1665
1679
|
* statusCode: '200',
|
|
1666
|
-
*
|
|
1667
|
-
* schema: createSchema({ type: 'object', properties: [] }),
|
|
1680
|
+
* content: [{ contentType: 'application/json', schema: createSchema({ type: 'object', properties: [] }) }],
|
|
1668
1681
|
* })
|
|
1669
1682
|
* ```
|
|
1670
1683
|
*/
|
|
1671
1684
|
function createResponse(props) {
|
|
1685
|
+
const { schema, mediaType, keysToOmit, content, ...rest } = props;
|
|
1672
1686
|
return {
|
|
1673
|
-
...
|
|
1674
|
-
kind: "Response"
|
|
1687
|
+
...rest,
|
|
1688
|
+
kind: "Response",
|
|
1689
|
+
content: content ?? (schema ? [{
|
|
1690
|
+
contentType: mediaType ?? "application/json",
|
|
1691
|
+
schema,
|
|
1692
|
+
keysToOmit: keysToOmit ?? null
|
|
1693
|
+
}] : void 0)
|
|
1675
1694
|
};
|
|
1676
1695
|
}
|
|
1677
1696
|
/**
|