@kubb/plugin-ts 5.4.1 → 5.4.2
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 +20 -10
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +20 -10
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -963,7 +963,7 @@ function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
|
|
|
963
963
|
properties: [
|
|
964
964
|
ast.factory.createProperty({
|
|
965
965
|
name: "body",
|
|
966
|
-
required: hasBody,
|
|
966
|
+
required: hasBody && node.requestBody?.required === true,
|
|
967
967
|
schema: body
|
|
968
968
|
}),
|
|
969
969
|
...groups.map(({ name, params, resolve }) => {
|
|
@@ -1314,6 +1314,14 @@ function formatExample(value) {
|
|
|
1314
1314
|
if (value === null || typeof value !== "object") return String(value);
|
|
1315
1315
|
return (JSON.stringify(value) ?? String(value)).replaceAll("*/", "*\\/");
|
|
1316
1316
|
}
|
|
1317
|
+
/**
|
|
1318
|
+
* Whether a schema is binary, or an array of binary items, so its TypeScript type is `Blob` or `Blob[]`.
|
|
1319
|
+
*/
|
|
1320
|
+
function isBinarySchema(schema) {
|
|
1321
|
+
const meta = syncSchemaRef(schema);
|
|
1322
|
+
const isBlob = (node) => syncSchemaRef(node)?.type === "blob";
|
|
1323
|
+
return !!meta && (isBlob(meta) || meta.type === "array" && "items" in meta && (meta.items ?? []).some(isBlob));
|
|
1324
|
+
}
|
|
1317
1325
|
function buildPropertyJSDocComments(schema, optional) {
|
|
1318
1326
|
const meta = syncSchemaRef(schema);
|
|
1319
1327
|
const isArray = meta?.primitive === "array";
|
|
@@ -1331,7 +1339,7 @@ function buildPropertyJSDocComments(schema, optional) {
|
|
|
1331
1339
|
meta && "default" in meta && meta.default !== void 0 ? `@default ${"primitive" in meta && meta.primitive === "string" && typeof meta.default === "string" ? stringify(meta.default) : formatExample(meta.default)}` : null,
|
|
1332
1340
|
...exampleValues.map((example) => `@example ${formatExample(example)}`)
|
|
1333
1341
|
].filter(Boolean);
|
|
1334
|
-
const typeTag = comments.length && meta && "primitive" in meta && meta.primitive ? [`@type ${meta.primitive}`, optional ?? isSchemaOptional(schema) ? " | undefined" : null].filter(Boolean).join("") : null;
|
|
1342
|
+
const typeTag = comments.length && !isBinarySchema(schema) && meta && "primitive" in meta && meta.primitive ? [`@type ${meta.primitive}`, optional ?? isSchemaOptional(schema) ? " | undefined" : null].filter(Boolean).join("") : null;
|
|
1335
1343
|
return [...comments, typeTag].filter(Boolean);
|
|
1336
1344
|
}
|
|
1337
1345
|
/**
|
|
@@ -1516,14 +1524,16 @@ const printerTs = ast.createPrinter((options) => {
|
|
|
1516
1524
|
const optional = !property.required || !!property.schema.optional || !!property.schema.nullish;
|
|
1517
1525
|
const type = buildPropertyType(property.schema, baseType, options.optionalType, optional);
|
|
1518
1526
|
const propMeta = syncSchemaRef(property.schema);
|
|
1527
|
+
const propertyNode = createPropertySignature({
|
|
1528
|
+
questionToken: optional ? addsQuestionToken : false,
|
|
1529
|
+
name,
|
|
1530
|
+
type,
|
|
1531
|
+
readOnly: propMeta?.readOnly
|
|
1532
|
+
});
|
|
1533
|
+
const binaryRemark = isBinarySchema(property.schema) ? "@remarks Pass a `File` to send its filename. A plain `Blob` is sent with the filename `blob`." : void 0;
|
|
1519
1534
|
return appendJSDocToNode({
|
|
1520
|
-
node:
|
|
1521
|
-
|
|
1522
|
-
name,
|
|
1523
|
-
type,
|
|
1524
|
-
readOnly: propMeta?.readOnly
|
|
1525
|
-
}),
|
|
1526
|
-
comments: buildPropertyJSDocComments(property.schema, optional)
|
|
1535
|
+
node: propertyNode,
|
|
1536
|
+
comments: [...buildPropertyJSDocComments(property.schema, optional), binaryRemark]
|
|
1527
1537
|
});
|
|
1528
1538
|
});
|
|
1529
1539
|
const allElements = [...propertyNodes, ...buildIndexSignatures(node, propertyNodes.length, transform)];
|
|
@@ -1923,7 +1933,7 @@ var compatibility = {
|
|
|
1923
1933
|
"node": ">=22.22"
|
|
1924
1934
|
};
|
|
1925
1935
|
// package.json
|
|
1926
|
-
var version = "5.4.
|
|
1936
|
+
var version = "5.4.2";
|
|
1927
1937
|
// src/resolvers/resolverTs.ts
|
|
1928
1938
|
/**
|
|
1929
1939
|
* Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths
|