@kubb/plugin-ts 5.0.0-beta.95 → 5.0.0-beta.98

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.d.ts CHANGED
@@ -2,6 +2,7 @@ import { n as __name } from "./rolldown-runtime-CNktS9qV.js";
2
2
  import { KubbReactNode } from "kubb/jsx";
3
3
  import { Exclude, Group, Include, Output, OutputOptions, Override, PluginFactoryOptions, Resolver, ResolverPatch, ast } from "kubb/kit";
4
4
  import ts from "typescript";
5
+ import "@kubb/adapter-oas";
5
6
  //#region src/printers/printerTs.d.ts
6
7
  /**
7
8
  * Partial map of node-type overrides for the TypeScript printer.
@@ -445,16 +446,6 @@ type Props$1 = {
445
446
  resolver: ResolverTs;
446
447
  key?: string | number | null;
447
448
  };
448
- /**
449
- * Resolves the runtime identifier name and the TypeScript type name for an enum schema node.
450
- *
451
- * The raw `node.name` may be a YAML key such as `"enumNames.Type"` which is not a
452
- * valid TypeScript identifier. The resolver normalizes it. For inline enum properties the adapter
453
- * already emits a PascalCase+suffix name, so resolution is typically a no-op.
454
- *
455
- * When `constCasing` is `'pascalCase'` and `typeSuffix` is empty, the const and the type
456
- * resolve to the same name, which TypeScript merges into a single value+type declaration.
457
- */
458
449
  /**
459
450
  * Renders the enum declaration(s) for a single named `EnumSchemaNode`.
460
451
  *
@@ -466,11 +457,7 @@ type Props$1 = {
466
457
  * The emitted `File.Source` nodes carry the resolved names so that the barrel
467
458
  * index picks up the correct export identifiers.
468
459
  */
469
- declare function Enum({
470
- node,
471
- enum: enumOptions,
472
- resolver
473
- }: Props$1): KubbReactNode;
460
+ declare function Enum({ node, enum: enumOptions, resolver }: Props$1): KubbReactNode;
474
461
  //#endregion
475
462
  //#region src/components/Type.d.ts
476
463
  type Props = {
@@ -484,13 +471,7 @@ type Props = {
484
471
  enum: PluginTs['resolvedOptions']['enum'];
485
472
  resolver: ResolverTs;
486
473
  };
487
- declare function Type({
488
- name,
489
- node,
490
- printer,
491
- enum: enumOptions,
492
- resolver
493
- }: Props): KubbReactNode;
474
+ declare function Type({ name, node, printer, enum: enumOptions, resolver }: Props): KubbReactNode;
494
475
  //#endregion
495
476
  //#region src/generators/typeGenerator.d.ts
496
477
  /**
@@ -967,9 +948,7 @@ type BuildParamsSchemaOptions = {
967
948
  * header), embedding each param's own schema (and JSDoc) directly rather than referencing a
968
949
  * separate per-param type — the group itself is the only type these params get exported as.
969
950
  */
970
- declare function buildParams({
971
- params
972
- }: BuildParamsSchemaOptions): ast.SchemaNode;
951
+ declare function buildParams({ params }: BuildParamsSchemaOptions): ast.SchemaNode;
973
952
  //#endregion
974
953
  export { type CreateOperationParamsOptions, Enum, type FunctionParameterNode, type FunctionParametersNode, type IndexedAccessTypeNode, type ObjectBindingPatternNode, type PluginTs, type PrinterTsFactory, type PrinterTsNodes, type PrinterTsOptions, type ResolverTs, Type, type TypeExpression, type TypeLiteralNode, buildParams, createFunctionParameter, createFunctionParameters, createIndexedAccessType, createObjectBindingPattern, createOperationParams, createTypeLiteral, pluginTs as default, pluginTs, functionPrinter, pluginTsName, printerTs, renderType, resolverTs, typeGenerator };
975
954
  //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -67,31 +67,6 @@ function screamingSnakeCase(text, { prefix = "", suffix = "" } = {}) {
67
67
  }).toUpperCase();
68
68
  }
69
69
  //#endregion
70
- //#region ../../internals/utils/src/fs.ts
71
- /**
72
- * Builds a nested file path from a dotted name. Splits on dots that precede a letter
73
- * (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
74
- * every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
75
- *
76
- * Empty segments are dropped before joining. They arise when the name starts with a dot
77
- * followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
78
- * an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
79
- * absolute path, letting generated files escape the configured output directory.
80
- *
81
- * @example Nested path from a dotted name
82
- * `toFilePath('pet.petId') // 'pet/petId'`
83
- *
84
- * @example PascalCase the final segment
85
- * `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
86
- *
87
- * @example Suffix applied to the final segment only
88
- * `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
89
- */
90
- function toFilePath(name, caseLast = camelCase) {
91
- const parts = name.split(/\.(?=[a-zA-Z])/);
92
- return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : camelCase(part)).filter(Boolean).join("/");
93
- }
94
- //#endregion
95
70
  //#region ../../internals/utils/src/reserved.ts
96
71
  /**
97
72
  * JavaScript and Java reserved words.
@@ -292,6 +267,31 @@ function jsStringEscape(input) {
292
267
  });
293
268
  }
294
269
  //#endregion
270
+ //#region ../../internals/utils/src/fs.ts
271
+ /**
272
+ * Builds a nested file path from a dotted name. Splits on dots that precede a letter
273
+ * (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
274
+ * every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
275
+ *
276
+ * Empty segments are dropped before joining. They arise when the name starts with a dot
277
+ * followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
278
+ * an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
279
+ * absolute path, letting generated files escape the configured output directory.
280
+ *
281
+ * @example Nested path from a dotted name
282
+ * `toFilePath('pet.petId') // 'pet/petId'`
283
+ *
284
+ * @example PascalCase the final segment
285
+ * `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
286
+ *
287
+ * @example Suffix applied to the final segment only
288
+ * `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
289
+ */
290
+ function toFilePath(name, caseLast = camelCase) {
291
+ const parts = name.split(/\.(?=[a-zA-Z])/);
292
+ return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : camelCase(part)).filter(Boolean).join("/");
293
+ }
294
+ //#endregion
295
295
  //#region src/constants.ts
296
296
  /**
297
297
  * `optionalType` values that cause a property's type to include `| undefined`.
@@ -1151,6 +1151,10 @@ function isInlineConstEnum(node, enumSchemaNames) {
1151
1151
  function isSchemaOptional(schema) {
1152
1152
  return Boolean("optional" in schema && schema.optional || "nullish" in schema && schema.nullish);
1153
1153
  }
1154
+ function formatExample(value) {
1155
+ if (value === null || typeof value !== "object") return String(value);
1156
+ return (JSON.stringify(value) ?? String(value)).replaceAll("*/", "*\\/");
1157
+ }
1154
1158
  function buildPropertyJSDocComments(schema, optional) {
1155
1159
  const meta = ast.syncSchemaRef(schema);
1156
1160
  const isArray = meta?.primitive === "array";
@@ -1165,7 +1169,7 @@ function buildPropertyJSDocComments(schema, optional) {
1165
1169
  !isArray && meta && "max" in meta && meta.max !== void 0 ? `@maxLength ${meta.max}` : null,
1166
1170
  meta && "pattern" in meta && meta.pattern ? `@pattern ${meta.pattern}` : null,
1167
1171
  meta && "default" in meta && meta.default !== void 0 ? `@default ${"primitive" in meta && meta.primitive === "string" && typeof meta.default === "string" ? stringify(meta.default) : meta.default}` : null,
1168
- ...exampleValues.map((example) => `@example ${example}`),
1172
+ ...exampleValues.map((example) => `@example ${formatExample(example)}`),
1169
1173
  meta && "primitive" in meta && meta.primitive ? [`@type ${meta.primitive}`, optional ?? isSchemaOptional(schema) ? " | undefined" : null].filter(Boolean).join("") : null
1170
1174
  ].filter(Boolean);
1171
1175
  }
@@ -1398,7 +1402,8 @@ const printerTs = ast.createPrinter((options) => {
1398
1402
  if (!node.name) return null;
1399
1403
  const refName = ast.resolveRefName(node);
1400
1404
  if (!refName) return null;
1401
- return createTypeReferenceNode(node.ref && ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enum.type) && this.options.enum.typeSuffix && this.options.enumSchemaNames?.has(refName) ? this.options.resolver.enum.keyName({ name: refName }, this.options.enum.typeSuffix) : node.ref ? this.options.resolver.name(refName) : refName, void 0);
1405
+ const name = node.ref && ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enum.type) && this.options.enum.typeSuffix && this.options.enumSchemaNames?.has(refName) ? this.options.resolver.enum.keyName({ name: refName }, this.options.enum.typeSuffix) : node.ref ? this.options.resolver.name(refName) : refName;
1406
+ return createTypeReferenceNode(name, void 0);
1402
1407
  },
1403
1408
  enum(node) {
1404
1409
  const values = node.namedEnumValues?.map((v) => v.value) ?? node.enumValues ?? [];
@@ -1406,7 +1411,8 @@ const printerTs = ast.createPrinter((options) => {
1406
1411
  withParentheses: true,
1407
1412
  nodes: values.filter((v) => v !== null && v !== void 0).map((value) => constToTypeNode(value, typeof value)).filter(isNonNullable)
1408
1413
  }) ?? void 0;
1409
- return createTypeReferenceNode(ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enum.type) && this.options.enum.typeSuffix ? this.options.resolver.enum.keyName(node, this.options.enum.typeSuffix) : this.options.resolver.name(node.name), void 0);
1414
+ const resolvedName = ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enum.type) && this.options.enum.typeSuffix ? this.options.resolver.enum.keyName(node, this.options.enum.typeSuffix) : this.options.resolver.name(node.name);
1415
+ return createTypeReferenceNode(resolvedName, void 0);
1410
1416
  },
1411
1417
  union(node) {
1412
1418
  const members = node.members ?? [];