@kubb/plugin-swr 5.0.0-beta.98 → 5.0.0-beta.99

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
@@ -191,33 +191,17 @@ function isIdentifier(name) {
191
191
  }
192
192
  //#endregion
193
193
  //#region ../../internals/utils/src/url.ts
194
- function transformParam(raw, casing) {
195
- const param = isValidVarName(raw) ? raw : camelCase(raw);
196
- return casing === "camelcase" ? camelCase(param) : param;
197
- }
198
- function toParamsObject(path, { replacer, casing } = {}) {
199
- const params = {};
200
- for (const match of path.matchAll(/\{([^}]+)\}/g)) {
201
- const param = transformParam(match[1], casing);
202
- const key = replacer ? replacer(param) : param;
203
- params[key] = key;
204
- }
205
- return Object.keys(params).length > 0 ? params : null;
194
+ /**
195
+ * Keeps the OpenAPI parameter name as-is when it is already a valid JS identifier, and
196
+ * camelCases it only enough to become one otherwise (for example a hyphenated path segment).
197
+ */
198
+ function transformParam(raw) {
199
+ return isValidVarName(raw) ? raw : camelCase(raw);
206
200
  }
207
201
  /**
208
- * Helpers for OpenAPI/Swagger paths, plus a thin wrapper over the native `URL`.
202
+ * Helpers for OpenAPI/Swagger paths.
209
203
  */
210
204
  var Url = class Url {
211
- /**
212
- * Reports whether `url` is a parseable absolute URL. Delegates to the native `URL.canParse`.
213
- *
214
- * @example
215
- * Url.canParse('https://petstore.swagger.io/v2') // true
216
- * Url.canParse('/pet/{petId}') // false
217
- */
218
- static canParse(url, base) {
219
- return URL.canParse(url, base);
220
- }
221
205
  /**
222
206
  * Converts an OpenAPI/Swagger path to Express-style colon syntax.
223
207
  *
@@ -233,15 +217,14 @@ var Url = class Url {
233
217
  * key.
234
218
  *
235
219
  * @example
236
- * Url.toCasedTemplate('/projects/{project_id}', { casing: 'camelcase' }) // '/projects/{projectId}'
220
+ * Url.toSafeTemplate('/user/{monetary-account-id}') // '/user/{monetaryAccountId}'
237
221
  */
238
- static toCasedTemplate(path, { casing } = {}) {
239
- return path.replace(/\{([^}]+)\}/g, (_, name) => `{${transformParam(name, casing)}}`);
222
+ static toSafeTemplate(path) {
223
+ return path.replace(/\{([^}]+)\}/g, (_, name) => `{${transformParam(name)}}`);
240
224
  }
241
225
  /**
242
226
  * Converts an OpenAPI/Swagger path to a TypeScript template literal string.
243
- * `prefix` is prepended inside the literal, `replacer` transforms each parameter name,
244
- * and `casing` controls parameter identifier casing.
227
+ * `prefix` is prepended inside the literal, and `replacer` transforms each parameter name.
245
228
  *
246
229
  * @example
247
230
  * Url.toTemplateString('/pet/{petId}') // '`/pet/${petId}`'
@@ -249,10 +232,10 @@ var Url = class Url {
249
232
  * @example
250
233
  * Url.toTemplateString('/pet/{petId}', { prefix: 'https://api' }) // '`https://api/pet/${petId}`'
251
234
  */
252
- static toTemplateString(path, { prefix, replacer, casing } = {}) {
235
+ static toTemplateString(path, { prefix, replacer } = {}) {
253
236
  const result = path.split(/\{([^}]+)\}/).map((part, i) => {
254
237
  if (i % 2 === 0) return part;
255
- const param = transformParam(part, casing);
238
+ const param = transformParam(part);
256
239
  return `\${${replacer ? replacer(param) : param}}`;
257
240
  }).join("");
258
241
  return `\`${prefix ?? ""}${result}\``;
@@ -260,8 +243,8 @@ var Url = class Url {
260
243
  /**
261
244
  * Converts an OpenAPI/Swagger path to a template literal that reads each parameter off the
262
245
  * grouped `path` request option, e.g. `/pet/{petId}` becomes `` `/pet/${path.petId}` ``. Parameter
263
- * names are camelCased to match the generated `path` type, and `prefix` is prepended inside the
264
- * literal. Shared by the client and cypress generators that pass a grouped `path` object.
246
+ * names match the generated `path` type, and `prefix` is prepended inside the literal. Shared by
247
+ * the client and cypress generators that pass a grouped `path` object.
265
248
  *
266
249
  * @example
267
250
  * Url.toGroupedTemplateString('/pet/{petId}') // '`/pet/${path.petId}`'
@@ -269,72 +252,25 @@ var Url = class Url {
269
252
  static toGroupedTemplateString(path, { prefix } = {}) {
270
253
  return Url.toTemplateString(path, {
271
254
  prefix,
272
- casing: "camelcase",
273
255
  replacer: (name) => `path.${name}`
274
256
  });
275
257
  }
276
- /**
277
- * Returns the path and its extracted params as a structured `URLObject`, or as a stringified
278
- * expression when `stringify` is set.
279
- *
280
- * @example
281
- * Url.toObject('/pet/{petId}')
282
- * // { url: '/pet/:petId', params: { petId: 'petId' } }
283
- */
284
- static toObject(path, { type = "path", replacer, stringify, casing } = {}) {
285
- const object = {
286
- url: type === "path" ? Url.toPath(path) : Url.toTemplateString(path, {
287
- replacer,
288
- casing
289
- }),
290
- params: toParamsObject(path, {
291
- replacer,
292
- casing
293
- })
294
- };
295
- if (stringify) {
296
- if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
297
- if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
298
- return `{ url: '${object.url}' }`;
299
- }
300
- return object;
301
- }
302
258
  };
303
259
  //#endregion
304
260
  //#region ../../internals/shared/src/params.ts
305
- const caseParamsCache = /* @__PURE__ */ new WeakMap();
306
261
  /**
307
- * Applies camelCase to parameter names and returns a new array without mutating the input.
262
+ * Drops parameters that share the same name, keeping the first.
308
263
  *
309
- * Run it before handing parameters to schema builders so output property keys get the right casing
310
- * while `OperationNode.parameters` stays intact for other consumers. When `casing` is unset, the
311
- * original array is returned unchanged. Results are cached per input array.
264
+ * A malformed spec can declare the same parameter name twice within one `in` location. Both would
265
+ * resolve to the same output property, so emitting both would yield an object type with a duplicate
266
+ * member, which TypeScript rejects. This is a defensive guard against that case, not a casing guard:
267
+ * parameter names flow through unchanged, so no two distinct names ever collide here anymore.
312
268
  */
313
- function caseParams(params, casing) {
314
- if (!casing) return params;
315
- const cached = caseParamsCache.get(params);
316
- if (cached) return cached;
317
- const result = params.map((param) => ({
318
- ...param,
319
- name: camelCase(param.name)
320
- }));
321
- caseParamsCache.set(params, result);
322
- return result;
323
- }
324
- /**
325
- * Drops parameters that collapse to the same property identity once camelCased, keeping the first.
326
- *
327
- * Some specs declare the same parameter twice under different casings (for example AWS S3 lists both
328
- * `max-uploads` and `MaxUploads`). Both resolve to one output property, so emitting both would yield
329
- * an object type with a duplicate member, which TypeScript rejects. De-duplicate by the camelCased
330
- * identity so the resulting group is collision-free regardless of the names each caller carries.
331
- */
332
- function dedupeByCasedName(params) {
269
+ function dedupeParams(params) {
333
270
  const seen = /* @__PURE__ */ new Set();
334
271
  return params.filter((param) => {
335
- const key = camelCase(param.name);
336
- if (seen.has(key)) return false;
337
- seen.add(key);
272
+ if (seen.has(param.name)) return false;
273
+ seen.add(param.name);
338
274
  return true;
339
275
  });
340
276
  }
@@ -453,13 +389,15 @@ function buildOperationComments(node, options = {}) {
453
389
  if (!splitLines) return filteredComments;
454
390
  return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
455
391
  }
456
- function getOperationParameters(node, options = {}) {
457
- const params = caseParams(node.parameters, options.paramsCasing === "original" ? void 0 : "camelcase");
392
+ function getOperationParameters(node) {
458
393
  return {
459
- path: dedupeByCasedName(params.filter((param) => param.in === "path")),
460
- query: dedupeByCasedName(params.filter((param) => param.in === "query")),
461
- header: dedupeByCasedName(params.filter((param) => param.in === "header")),
462
- cookie: dedupeByCasedName(params.filter((param) => param.in === "cookie"))
394
+ path: dedupeParams(node.parameters.filter((param) => param.in === "path").map((param) => isValidVarName(param.name) ? param : {
395
+ ...param,
396
+ name: camelCase(param.name)
397
+ })),
398
+ query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
399
+ header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
400
+ cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
463
401
  };
464
402
  }
465
403
  function getStatusCodeNumber(statusCode) {
@@ -491,7 +429,7 @@ function resolveStatusCodeNames(node, resolver) {
491
429
  }
492
430
  const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
493
431
  function resolveOperationTypeNames(node, resolver, options = {}) {
494
- const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
432
+ const cacheKey = `${node.operationId}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${options.includeParams === false ? "noparams" : ""}\0${(options.exclude ?? []).join(",")}`;
495
433
  let byResolver = typeNamesByResolver.get(resolver);
496
434
  if (byResolver) {
497
435
  const cached = byResolver.get(cacheKey);
@@ -500,7 +438,7 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
500
438
  byResolver = /* @__PURE__ */ new Map();
501
439
  typeNamesByResolver.set(resolver, byResolver);
502
440
  }
503
- const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
441
+ const { path, query, header } = getOperationParameters(node);
504
442
  const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
505
443
  const exclude = new Set(options.exclude ?? []);
506
444
  const paramNames = options.includeParams === false ? [] : [