@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 CHANGED
@@ -967,7 +967,7 @@ function buildOptionsSchema(node, resolver, { pairContentTypes = false } = {}) {
967
967
  properties: [
968
968
  _kubb_kit.ast.factory.createProperty({
969
969
  name: "body",
970
- required: hasBody,
970
+ required: hasBody && node.requestBody?.required === true,
971
971
  schema: body
972
972
  }),
973
973
  ...groups.map(({ name, params, resolve }) => {
@@ -1318,6 +1318,14 @@ function formatExample(value) {
1318
1318
  if (value === null || typeof value !== "object") return String(value);
1319
1319
  return (JSON.stringify(value) ?? String(value)).replaceAll("*/", "*\\/");
1320
1320
  }
1321
+ /**
1322
+ * Whether a schema is binary, or an array of binary items, so its TypeScript type is `Blob` or `Blob[]`.
1323
+ */
1324
+ function isBinarySchema(schema) {
1325
+ const meta = (0, _kubb_kit.syncSchemaRef)(schema);
1326
+ const isBlob = (node) => (0, _kubb_kit.syncSchemaRef)(node)?.type === "blob";
1327
+ return !!meta && (isBlob(meta) || meta.type === "array" && "items" in meta && (meta.items ?? []).some(isBlob));
1328
+ }
1321
1329
  function buildPropertyJSDocComments(schema, optional) {
1322
1330
  const meta = (0, _kubb_kit.syncSchemaRef)(schema);
1323
1331
  const isArray = meta?.primitive === "array";
@@ -1335,7 +1343,7 @@ function buildPropertyJSDocComments(schema, optional) {
1335
1343
  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,
1336
1344
  ...exampleValues.map((example) => `@example ${formatExample(example)}`)
1337
1345
  ].filter(Boolean);
1338
- const typeTag = comments.length && meta && "primitive" in meta && meta.primitive ? [`@type ${meta.primitive}`, optional ?? isSchemaOptional(schema) ? " | undefined" : null].filter(Boolean).join("") : null;
1346
+ const typeTag = comments.length && !isBinarySchema(schema) && meta && "primitive" in meta && meta.primitive ? [`@type ${meta.primitive}`, optional ?? isSchemaOptional(schema) ? " | undefined" : null].filter(Boolean).join("") : null;
1339
1347
  return [...comments, typeTag].filter(Boolean);
1340
1348
  }
1341
1349
  /**
@@ -1520,14 +1528,16 @@ const printerTs = _kubb_kit.ast.createPrinter((options) => {
1520
1528
  const optional = !property.required || !!property.schema.optional || !!property.schema.nullish;
1521
1529
  const type = buildPropertyType(property.schema, baseType, options.optionalType, optional);
1522
1530
  const propMeta = (0, _kubb_kit.syncSchemaRef)(property.schema);
1531
+ const propertyNode = createPropertySignature({
1532
+ questionToken: optional ? addsQuestionToken : false,
1533
+ name,
1534
+ type,
1535
+ readOnly: propMeta?.readOnly
1536
+ });
1537
+ const binaryRemark = isBinarySchema(property.schema) ? "@remarks Pass a `File` to send its filename. A plain `Blob` is sent with the filename `blob`." : void 0;
1523
1538
  return appendJSDocToNode({
1524
- node: createPropertySignature({
1525
- questionToken: optional ? addsQuestionToken : false,
1526
- name,
1527
- type,
1528
- readOnly: propMeta?.readOnly
1529
- }),
1530
- comments: buildPropertyJSDocComments(property.schema, optional)
1539
+ node: propertyNode,
1540
+ comments: [...buildPropertyJSDocComments(property.schema, optional), binaryRemark]
1531
1541
  });
1532
1542
  });
1533
1543
  const allElements = [...propertyNodes, ...buildIndexSignatures(node, propertyNodes.length, transform)];
@@ -1927,7 +1937,7 @@ var compatibility = {
1927
1937
  "node": ">=22.22"
1928
1938
  };
1929
1939
  // package.json
1930
- var version = "5.4.1";
1940
+ var version = "5.4.2";
1931
1941
  // src/resolvers/resolverTs.ts
1932
1942
  /**
1933
1943
  * Default resolver used by `@kubb/plugin-ts`. Decides the names and file paths