@kubb/plugin-ts 5.0.0-beta.77 → 5.0.0-beta.79
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 +73 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +5 -0
- package/dist/index.js +73 -21
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -137,7 +137,7 @@ function toFilePath(name, caseLast = camelCase) {
|
|
|
137
137
|
* JavaScript and Java reserved words.
|
|
138
138
|
* @link https://github.com/jonschlinkert/reserved/blob/master/index.js
|
|
139
139
|
*/
|
|
140
|
-
const reservedWords = new Set([
|
|
140
|
+
const reservedWords = /* @__PURE__ */ new Set([
|
|
141
141
|
"abstract",
|
|
142
142
|
"arguments",
|
|
143
143
|
"boolean",
|
|
@@ -259,19 +259,19 @@ function ensureValidVarName(name) {
|
|
|
259
259
|
/**
|
|
260
260
|
* `optionalType` values that cause a property's type to include `| undefined`.
|
|
261
261
|
*/
|
|
262
|
-
const OPTIONAL_ADDS_UNDEFINED = new Set(["undefined", "questionTokenAndUndefined"]);
|
|
262
|
+
const OPTIONAL_ADDS_UNDEFINED = /* @__PURE__ */ new Set(["undefined", "questionTokenAndUndefined"]);
|
|
263
263
|
/**
|
|
264
264
|
* `optionalType` values that render the property key with a `?` token.
|
|
265
265
|
*/
|
|
266
|
-
const OPTIONAL_ADDS_QUESTION_TOKEN = new Set(["questionToken", "questionTokenAndUndefined"]);
|
|
266
|
+
const OPTIONAL_ADDS_QUESTION_TOKEN = /* @__PURE__ */ new Set(["questionToken", "questionTokenAndUndefined"]);
|
|
267
267
|
/**
|
|
268
268
|
* `enum.type` values that append a `typeSuffix` to the generated enum type alias.
|
|
269
269
|
*/
|
|
270
|
-
const ENUM_TYPES_WITH_KEY_SUFFIX = new Set(["asConst"]);
|
|
270
|
+
const ENUM_TYPES_WITH_KEY_SUFFIX = /* @__PURE__ */ new Set(["asConst"]);
|
|
271
271
|
/**
|
|
272
272
|
* `enum.type` values that require a runtime value declaration (object, enum, or literal).
|
|
273
273
|
*/
|
|
274
|
-
const ENUM_TYPES_WITH_RUNTIME_VALUE = new Set([
|
|
274
|
+
const ENUM_TYPES_WITH_RUNTIME_VALUE = /* @__PURE__ */ new Set([
|
|
275
275
|
"enum",
|
|
276
276
|
"asConst",
|
|
277
277
|
"constEnum",
|
|
@@ -281,7 +281,7 @@ const ENUM_TYPES_WITH_RUNTIME_VALUE = new Set([
|
|
|
281
281
|
/**
|
|
282
282
|
* `enum.type` values whose type declaration is type-only (no runtime value emitted for the type alias).
|
|
283
283
|
*/
|
|
284
|
-
const ENUM_TYPES_WITH_TYPE_ONLY = new Set([
|
|
284
|
+
const ENUM_TYPES_WITH_TYPE_ONLY = /* @__PURE__ */ new Set([
|
|
285
285
|
"asConst",
|
|
286
286
|
"literal",
|
|
287
287
|
void 0
|
|
@@ -839,7 +839,7 @@ function buildIndexSignatures(node, propertyCount, print) {
|
|
|
839
839
|
* resolve to the same name, which TypeScript merges into a single value+type declaration.
|
|
840
840
|
*/
|
|
841
841
|
function getEnumNames({ node, enum: enumOptions, resolver }) {
|
|
842
|
-
const resolved = resolver.
|
|
842
|
+
const resolved = resolver.resolveTypeName(node.name);
|
|
843
843
|
return {
|
|
844
844
|
enumName: enumOptions.constCasing === "pascalCase" ? resolved : camelCase(node.name),
|
|
845
845
|
typeName: ENUM_TYPES_WITH_KEY_SUFFIX.has(enumOptions.type) ? resolver.resolveEnumKeyName(node, enumOptions.typeSuffix) : resolved
|
|
@@ -909,6 +909,23 @@ function caseParams(params, casing) {
|
|
|
909
909
|
caseParamsCache.set(params, result);
|
|
910
910
|
return result;
|
|
911
911
|
}
|
|
912
|
+
/**
|
|
913
|
+
* Drops parameters that collapse to the same property identity once camelCased, keeping the first.
|
|
914
|
+
*
|
|
915
|
+
* Some specs declare the same parameter twice under different casings (for example AWS S3 lists both
|
|
916
|
+
* `max-uploads` and `MaxUploads`). Both resolve to one output property, so emitting both would yield
|
|
917
|
+
* an object type with a duplicate member, which TypeScript rejects. De-duplicate by the camelCased
|
|
918
|
+
* identity so the resulting group is collision-free regardless of the names each caller carries.
|
|
919
|
+
*/
|
|
920
|
+
function dedupeByCasedName(params) {
|
|
921
|
+
const seen = /* @__PURE__ */ new Set();
|
|
922
|
+
return params.filter((param) => {
|
|
923
|
+
const key = camelCase(param.name);
|
|
924
|
+
if (seen.has(key)) return false;
|
|
925
|
+
seen.add(key);
|
|
926
|
+
return true;
|
|
927
|
+
});
|
|
928
|
+
}
|
|
912
929
|
//#endregion
|
|
913
930
|
//#region ../../internals/shared/src/operation.ts
|
|
914
931
|
/**
|
|
@@ -962,10 +979,10 @@ function resolveContentTypeVariants(entries, baseName) {
|
|
|
962
979
|
function getOperationParameters(node, options = {}) {
|
|
963
980
|
const params = caseParams(node.parameters, options.paramsCasing === "original" ? void 0 : "camelcase");
|
|
964
981
|
return {
|
|
965
|
-
path: params.filter((param) => param.in === "path"),
|
|
966
|
-
query: params.filter((param) => param.in === "query"),
|
|
967
|
-
header: params.filter((param) => param.in === "header"),
|
|
968
|
-
cookie: params.filter((param) => param.in === "cookie")
|
|
982
|
+
path: dedupeByCasedName(params.filter((param) => param.in === "path")),
|
|
983
|
+
query: dedupeByCasedName(params.filter((param) => param.in === "query")),
|
|
984
|
+
header: dedupeByCasedName(params.filter((param) => param.in === "header")),
|
|
985
|
+
cookie: dedupeByCasedName(params.filter((param) => param.in === "cookie"))
|
|
969
986
|
};
|
|
970
987
|
}
|
|
971
988
|
//#endregion
|
|
@@ -1125,17 +1142,48 @@ function buildData(node, { resolver }) {
|
|
|
1125
1142
|
]
|
|
1126
1143
|
});
|
|
1127
1144
|
}
|
|
1145
|
+
/**
|
|
1146
|
+
* The schema a status occupies in the `<Name>Responses` record. A status that documents several
|
|
1147
|
+
* content types becomes a `{ contentType; data }` union so the runtime can surface the negotiated type
|
|
1148
|
+
* on `result.parsed`, while the standalone `<Name>StatusNNN` alias stays the plain body union that the
|
|
1149
|
+
* query hooks and `result.data` use.
|
|
1150
|
+
*/
|
|
1151
|
+
function buildResponseRecordEntry(node, res, resolver) {
|
|
1152
|
+
const statusName = resolver.resolveResponseStatusName(node, res.statusCode);
|
|
1153
|
+
const variants = (res.content ?? []).filter((entry) => entry.schema);
|
|
1154
|
+
if (variants.length <= 1) return _kubb_core.ast.factory.createSchema({
|
|
1155
|
+
type: "ref",
|
|
1156
|
+
name: statusName
|
|
1157
|
+
});
|
|
1158
|
+
return _kubb_core.ast.factory.createSchema({
|
|
1159
|
+
type: "union",
|
|
1160
|
+
members: resolveContentTypeVariants(variants, statusName).map((variant) => _kubb_core.ast.factory.createSchema({
|
|
1161
|
+
type: "object",
|
|
1162
|
+
properties: [_kubb_core.ast.factory.createProperty({
|
|
1163
|
+
name: "contentType",
|
|
1164
|
+
required: true,
|
|
1165
|
+
schema: _kubb_core.ast.factory.createSchema({
|
|
1166
|
+
type: "enum",
|
|
1167
|
+
enumValues: [variant.contentType]
|
|
1168
|
+
})
|
|
1169
|
+
}), _kubb_core.ast.factory.createProperty({
|
|
1170
|
+
name: "data",
|
|
1171
|
+
required: true,
|
|
1172
|
+
schema: _kubb_core.ast.factory.createSchema({
|
|
1173
|
+
type: "ref",
|
|
1174
|
+
name: variant.name
|
|
1175
|
+
})
|
|
1176
|
+
})]
|
|
1177
|
+
}))
|
|
1178
|
+
});
|
|
1179
|
+
}
|
|
1128
1180
|
function buildResponses(node, { resolver }) {
|
|
1129
|
-
if (node.responses.length === 0) return null;
|
|
1130
1181
|
return _kubb_core.ast.factory.createSchema({
|
|
1131
1182
|
type: "object",
|
|
1132
1183
|
properties: node.responses.map((res) => _kubb_core.ast.factory.createProperty({
|
|
1133
1184
|
name: String(res.statusCode),
|
|
1134
1185
|
required: true,
|
|
1135
|
-
schema:
|
|
1136
|
-
type: "ref",
|
|
1137
|
-
name: resolver.resolveResponseStatusName(node, res.statusCode)
|
|
1138
|
-
})
|
|
1186
|
+
schema: buildResponseRecordEntry(node, res, resolver)
|
|
1139
1187
|
}))
|
|
1140
1188
|
});
|
|
1141
1189
|
}
|
|
@@ -1239,8 +1287,8 @@ const printerTs = _kubb_core.ast.createPrinter((options) => {
|
|
|
1239
1287
|
time: dateOrStringNode,
|
|
1240
1288
|
ref(node) {
|
|
1241
1289
|
if (!node.name) return null;
|
|
1242
|
-
const refName = node.ref ? (0, _kubb_ast_utils.extractRefName)(node.ref) ?? node.name : node.name;
|
|
1243
|
-
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.resolveEnumKeyName({ name: refName }, this.options.enum.typeSuffix) : node.ref ? this.options.resolver.
|
|
1290
|
+
const refName = node.ref ? this.options.nameMapping?.get(node.ref) ?? (0, _kubb_ast_utils.extractRefName)(node.ref) ?? node.name : node.name;
|
|
1291
|
+
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.resolveEnumKeyName({ name: refName }, this.options.enum.typeSuffix) : node.ref ? this.options.resolver.resolveTypeName(refName) : refName, void 0);
|
|
1244
1292
|
},
|
|
1245
1293
|
enum(node) {
|
|
1246
1294
|
const values = node.namedEnumValues?.map((v) => v.value) ?? node.enumValues ?? [];
|
|
@@ -1248,7 +1296,7 @@ const printerTs = _kubb_core.ast.createPrinter((options) => {
|
|
|
1248
1296
|
withParentheses: true,
|
|
1249
1297
|
nodes: values.filter((v) => v !== null && v !== void 0).map((value) => constToTypeNode(value, typeof value)).filter(isNonNullable)
|
|
1250
1298
|
}) ?? void 0;
|
|
1251
|
-
return createTypeReferenceNode(ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enum.type) && this.options.enum.typeSuffix ? this.options.resolver.resolveEnumKeyName(node, this.options.enum.typeSuffix) : this.options.resolver.
|
|
1299
|
+
return createTypeReferenceNode(ENUM_TYPES_WITH_KEY_SUFFIX.has(this.options.enum.type) && this.options.enum.typeSuffix ? this.options.resolver.resolveEnumKeyName(node, this.options.enum.typeSuffix) : this.options.resolver.resolveTypeName(node.name), void 0);
|
|
1252
1300
|
},
|
|
1253
1301
|
union(node) {
|
|
1254
1302
|
const members = node.members ?? [];
|
|
@@ -1396,6 +1444,7 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1396
1444
|
description: node.description,
|
|
1397
1445
|
resolver,
|
|
1398
1446
|
enumSchemaNames,
|
|
1447
|
+
nameMapping: adapter.options.nameMapping,
|
|
1399
1448
|
nodes: printer?.nodes
|
|
1400
1449
|
});
|
|
1401
1450
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx.File, {
|
|
@@ -1478,6 +1527,7 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1478
1527
|
keysToOmit,
|
|
1479
1528
|
resolver,
|
|
1480
1529
|
enumSchemaNames,
|
|
1530
|
+
nameMapping: adapter.options.nameMapping,
|
|
1481
1531
|
nodes: printer?.nodes
|
|
1482
1532
|
});
|
|
1483
1533
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [imports.map((imp) => /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
@@ -1498,8 +1548,10 @@ const typeGenerator = (0, _kubb_core.defineGenerator)({
|
|
|
1498
1548
|
})] });
|
|
1499
1549
|
}
|
|
1500
1550
|
/**
|
|
1501
|
-
* Emits an individual type per content type plus a union alias under `baseName`.
|
|
1502
|
-
*
|
|
1551
|
+
* Emits an individual type per content type plus a plain union alias under `baseName`. Shared by
|
|
1552
|
+
* the request body and multi-content-type responses. The response record discriminates these
|
|
1553
|
+
* variants by content type in {@link buildResponses}; the standalone alias stays a plain union so
|
|
1554
|
+
* query hooks and `result.data` keep the bare body.
|
|
1503
1555
|
*/
|
|
1504
1556
|
function buildContentTypeVariants(entries, baseName, decorate) {
|
|
1505
1557
|
const variants = resolveContentTypeVariants(entries, baseName);
|