@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.cjs +34 -28
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -25
- package/dist/index.js +34 -28
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -106,31 +106,6 @@ function screamingSnakeCase(text, { prefix = "", suffix = "" } = {}) {
|
|
|
106
106
|
}).toUpperCase();
|
|
107
107
|
}
|
|
108
108
|
//#endregion
|
|
109
|
-
//#region ../../internals/utils/src/fs.ts
|
|
110
|
-
/**
|
|
111
|
-
* Builds a nested file path from a dotted name. Splits on dots that precede a letter
|
|
112
|
-
* (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
|
|
113
|
-
* every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
|
|
114
|
-
*
|
|
115
|
-
* Empty segments are dropped before joining. They arise when the name starts with a dot
|
|
116
|
-
* followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
|
|
117
|
-
* an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
|
|
118
|
-
* absolute path, letting generated files escape the configured output directory.
|
|
119
|
-
*
|
|
120
|
-
* @example Nested path from a dotted name
|
|
121
|
-
* `toFilePath('pet.petId') // 'pet/petId'`
|
|
122
|
-
*
|
|
123
|
-
* @example PascalCase the final segment
|
|
124
|
-
* `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
|
|
125
|
-
*
|
|
126
|
-
* @example Suffix applied to the final segment only
|
|
127
|
-
* `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
|
|
128
|
-
*/
|
|
129
|
-
function toFilePath(name, caseLast = camelCase) {
|
|
130
|
-
const parts = name.split(/\.(?=[a-zA-Z])/);
|
|
131
|
-
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : camelCase(part)).filter(Boolean).join("/");
|
|
132
|
-
}
|
|
133
|
-
//#endregion
|
|
134
109
|
//#region ../../internals/utils/src/reserved.ts
|
|
135
110
|
/**
|
|
136
111
|
* JavaScript and Java reserved words.
|
|
@@ -331,6 +306,31 @@ function jsStringEscape(input) {
|
|
|
331
306
|
});
|
|
332
307
|
}
|
|
333
308
|
//#endregion
|
|
309
|
+
//#region ../../internals/utils/src/fs.ts
|
|
310
|
+
/**
|
|
311
|
+
* Builds a nested file path from a dotted name. Splits on dots that precede a letter
|
|
312
|
+
* (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
|
|
313
|
+
* every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
|
|
314
|
+
*
|
|
315
|
+
* Empty segments are dropped before joining. They arise when the name starts with a dot
|
|
316
|
+
* followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
|
|
317
|
+
* an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
|
|
318
|
+
* absolute path, letting generated files escape the configured output directory.
|
|
319
|
+
*
|
|
320
|
+
* @example Nested path from a dotted name
|
|
321
|
+
* `toFilePath('pet.petId') // 'pet/petId'`
|
|
322
|
+
*
|
|
323
|
+
* @example PascalCase the final segment
|
|
324
|
+
* `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
|
|
325
|
+
*
|
|
326
|
+
* @example Suffix applied to the final segment only
|
|
327
|
+
* `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
|
|
328
|
+
*/
|
|
329
|
+
function toFilePath(name, caseLast = camelCase) {
|
|
330
|
+
const parts = name.split(/\.(?=[a-zA-Z])/);
|
|
331
|
+
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : camelCase(part)).filter(Boolean).join("/");
|
|
332
|
+
}
|
|
333
|
+
//#endregion
|
|
334
334
|
//#region src/constants.ts
|
|
335
335
|
/**
|
|
336
336
|
* `optionalType` values that cause a property's type to include `| undefined`.
|
|
@@ -1190,6 +1190,10 @@ function isInlineConstEnum(node, enumSchemaNames) {
|
|
|
1190
1190
|
function isSchemaOptional(schema) {
|
|
1191
1191
|
return Boolean("optional" in schema && schema.optional || "nullish" in schema && schema.nullish);
|
|
1192
1192
|
}
|
|
1193
|
+
function formatExample(value) {
|
|
1194
|
+
if (value === null || typeof value !== "object") return String(value);
|
|
1195
|
+
return (JSON.stringify(value) ?? String(value)).replaceAll("*/", "*\\/");
|
|
1196
|
+
}
|
|
1193
1197
|
function buildPropertyJSDocComments(schema, optional) {
|
|
1194
1198
|
const meta = kubb_kit.ast.syncSchemaRef(schema);
|
|
1195
1199
|
const isArray = meta?.primitive === "array";
|
|
@@ -1204,7 +1208,7 @@ function buildPropertyJSDocComments(schema, optional) {
|
|
|
1204
1208
|
!isArray && meta && "max" in meta && meta.max !== void 0 ? `@maxLength ${meta.max}` : null,
|
|
1205
1209
|
meta && "pattern" in meta && meta.pattern ? `@pattern ${meta.pattern}` : null,
|
|
1206
1210
|
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,
|
|
1207
|
-
...exampleValues.map((example) => `@example ${example}`),
|
|
1211
|
+
...exampleValues.map((example) => `@example ${formatExample(example)}`),
|
|
1208
1212
|
meta && "primitive" in meta && meta.primitive ? [`@type ${meta.primitive}`, optional ?? isSchemaOptional(schema) ? " | undefined" : null].filter(Boolean).join("") : null
|
|
1209
1213
|
].filter(Boolean);
|
|
1210
1214
|
}
|
|
@@ -1437,7 +1441,8 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1437
1441
|
if (!node.name) return null;
|
|
1438
1442
|
const refName = kubb_kit.ast.resolveRefName(node);
|
|
1439
1443
|
if (!refName) return null;
|
|
1440
|
-
|
|
1444
|
+
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;
|
|
1445
|
+
return createTypeReferenceNode(name, void 0);
|
|
1441
1446
|
},
|
|
1442
1447
|
enum(node) {
|
|
1443
1448
|
const values = node.namedEnumValues?.map((v) => v.value) ?? node.enumValues ?? [];
|
|
@@ -1445,7 +1450,8 @@ const printerTs = kubb_kit.ast.createPrinter((options) => {
|
|
|
1445
1450
|
withParentheses: true,
|
|
1446
1451
|
nodes: values.filter((v) => v !== null && v !== void 0).map((value) => constToTypeNode(value, typeof value)).filter(isNonNullable)
|
|
1447
1452
|
}) ?? void 0;
|
|
1448
|
-
|
|
1453
|
+
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);
|
|
1454
|
+
return createTypeReferenceNode(resolvedName, void 0);
|
|
1449
1455
|
},
|
|
1450
1456
|
union(node) {
|
|
1451
1457
|
const members = node.members ?? [];
|