@bagelink/sdk 1.9.86 → 1.9.90

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
@@ -460,7 +460,7 @@ function formatPathWithParams(path) {
460
460
  if (!params) {
461
461
  return `'${path}'`;
462
462
  }
463
- return `\`${path.replace(/\{([^}]+)\}/g, (_, paramName) => `\${${toCamelCase(paramName)}}`)}\``;
463
+ return `\`${path.replace(/\{([^}]+)\}/g, (_, paramName) => `\${${toCamelCaseSafe(paramName)}}`)}\``;
464
464
  }
465
465
  function generateRequestBody(requestBody) {
466
466
  const content = dereference(requestBody)?.content;
@@ -495,10 +495,7 @@ function generateRequestBody(requestBody) {
495
495
  });
496
496
  return { requestBodyParam, requestBodyPayload };
497
497
  }
498
- function generateFunctionParameters(params, isFileUpload = false) {
499
- if (!params?.length) {
500
- return {};
501
- }
498
+ function generateFunctionParameters(path, params, isFileUpload = false) {
502
499
  if (isFileUpload) {
503
500
  return {
504
501
  config: {
@@ -510,7 +507,8 @@ function generateFunctionParameters(params, isFileUpload = false) {
510
507
  }
511
508
  const functionParams = [];
512
509
  const queryParams = [];
513
- for (const p of params) {
510
+ const declaredPathParams = /* @__PURE__ */ new Set();
511
+ for (const p of params ?? []) {
514
512
  const param = dereference(p);
515
513
  const pSchema = dereference(param.schema);
516
514
  const paramType = schemaToType(pSchema);
@@ -521,6 +519,9 @@ function generateFunctionParameters(params, isFileUpload = false) {
521
519
  if (needsMapping && (param.in === "query" || param.in === "header")) {
522
520
  varName = `_${varName}`;
523
521
  }
522
+ if (param.in === "path") {
523
+ declaredPathParams.add(paramName);
524
+ }
524
525
  if (param.in === "path" || param.in === "query" || param.in === "header") {
525
526
  functionParams.push(
526
527
  formatVarType({
@@ -537,6 +538,16 @@ function generateFunctionParameters(params, isFileUpload = false) {
537
538
  );
538
539
  }
539
540
  }
541
+ const pathParamsInUrl = getParamsFromPath(path) ?? [];
542
+ for (const paramName of pathParamsInUrl) {
543
+ if (!declaredPathParams.has(paramName)) {
544
+ const varName = toCamelCaseSafe(paramName);
545
+ functionParams.unshift(`${varName}: string`);
546
+ }
547
+ }
548
+ if (functionParams.length === 0 && queryParams.length === 0) {
549
+ return {};
550
+ }
540
551
  return {
541
552
  params: functionParams.join(", "),
542
553
  config: queryParams.length ? { params: queryParams.join(", ") } : void 0
@@ -726,6 +737,7 @@ function generateFunctionForOperation(method, path, operation) {
726
737
  const multiPartSchema = dereference(operation.requestBody)?.content?.["multipart/form-data"]?.schema;
727
738
  const isFileUpload = isReferenceObject(multiPartSchema) && multiPartSchema?.$ref?.includes("Body_upload_files");
728
739
  const parameters = generateFunctionParameters(
740
+ path,
729
741
  operation.parameters,
730
742
  isFileUpload
731
743
  );
package/dist/index.mjs CHANGED
@@ -454,7 +454,7 @@ function formatPathWithParams(path) {
454
454
  if (!params) {
455
455
  return `'${path}'`;
456
456
  }
457
- return `\`${path.replace(/\{([^}]+)\}/g, (_, paramName) => `\${${toCamelCase(paramName)}}`)}\``;
457
+ return `\`${path.replace(/\{([^}]+)\}/g, (_, paramName) => `\${${toCamelCaseSafe(paramName)}}`)}\``;
458
458
  }
459
459
  function generateRequestBody(requestBody) {
460
460
  const content = dereference(requestBody)?.content;
@@ -489,10 +489,7 @@ function generateRequestBody(requestBody) {
489
489
  });
490
490
  return { requestBodyParam, requestBodyPayload };
491
491
  }
492
- function generateFunctionParameters(params, isFileUpload = false) {
493
- if (!params?.length) {
494
- return {};
495
- }
492
+ function generateFunctionParameters(path, params, isFileUpload = false) {
496
493
  if (isFileUpload) {
497
494
  return {
498
495
  config: {
@@ -504,7 +501,8 @@ function generateFunctionParameters(params, isFileUpload = false) {
504
501
  }
505
502
  const functionParams = [];
506
503
  const queryParams = [];
507
- for (const p of params) {
504
+ const declaredPathParams = /* @__PURE__ */ new Set();
505
+ for (const p of params ?? []) {
508
506
  const param = dereference(p);
509
507
  const pSchema = dereference(param.schema);
510
508
  const paramType = schemaToType(pSchema);
@@ -515,6 +513,9 @@ function generateFunctionParameters(params, isFileUpload = false) {
515
513
  if (needsMapping && (param.in === "query" || param.in === "header")) {
516
514
  varName = `_${varName}`;
517
515
  }
516
+ if (param.in === "path") {
517
+ declaredPathParams.add(paramName);
518
+ }
518
519
  if (param.in === "path" || param.in === "query" || param.in === "header") {
519
520
  functionParams.push(
520
521
  formatVarType({
@@ -531,6 +532,16 @@ function generateFunctionParameters(params, isFileUpload = false) {
531
532
  );
532
533
  }
533
534
  }
535
+ const pathParamsInUrl = getParamsFromPath(path) ?? [];
536
+ for (const paramName of pathParamsInUrl) {
537
+ if (!declaredPathParams.has(paramName)) {
538
+ const varName = toCamelCaseSafe(paramName);
539
+ functionParams.unshift(`${varName}: string`);
540
+ }
541
+ }
542
+ if (functionParams.length === 0 && queryParams.length === 0) {
543
+ return {};
544
+ }
534
545
  return {
535
546
  params: functionParams.join(", "),
536
547
  config: queryParams.length ? { params: queryParams.join(", ") } : void 0
@@ -720,6 +731,7 @@ function generateFunctionForOperation(method, path, operation) {
720
731
  const multiPartSchema = dereference(operation.requestBody)?.content?.["multipart/form-data"]?.schema;
721
732
  const isFileUpload = isReferenceObject(multiPartSchema) && multiPartSchema?.$ref?.includes("Body_upload_files");
722
733
  const parameters = generateFunctionParameters(
734
+ path,
723
735
  operation.parameters,
724
736
  isFileUpload
725
737
  );
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/sdk",
3
3
  "type": "module",
4
- "version": "1.9.86",
4
+ "version": "1.9.90",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
@@ -21,7 +21,6 @@ import {
21
21
  formatType,
22
22
  formatVarType,
23
23
  schemaToType,
24
- toCamelCase,
25
24
  toCamelCaseSafe,
26
25
  toPascalCase,
27
26
  } from './utils'
@@ -165,7 +164,7 @@ function formatPathWithParams(path: string): string {
165
164
  const params = getParamsFromPath(path)
166
165
  if (!params) { return `'${path}'` }
167
166
 
168
- return `\`${path.replace(/\{([^}]+)\}/g, (_, paramName) => `\${${toCamelCase(paramName)}}`)}\``
167
+ return `\`${path.replace(/\{([^}]+)\}/g, (_, paramName) => `\${${toCamelCaseSafe(paramName)}}`)}\``
169
168
  }
170
169
 
171
170
  /**
@@ -230,16 +229,16 @@ function generateRequestBody(requestBody?: OpenAPIOperation['requestBody']): {
230
229
 
231
230
  /**
232
231
  * Generates function parameters from OpenAPI parameters
232
+ * @param path - The API path (used to detect path params missing from spec)
233
233
  * @param params - The OpenAPI parameters
234
234
  * @param isFileUpload - Whether this is a file upload operation
235
235
  * @returns Object containing parameter information
236
236
  */
237
237
  function generateFunctionParameters(
238
+ path: string,
238
239
  params?: OpenAPIOperation['parameters'],
239
240
  isFileUpload = false
240
241
  ): { params?: string, config?: { params?: string } } {
241
- if (!params?.length) { return {} }
242
-
243
242
  // Special handling for file uploads
244
243
  if (isFileUpload) {
245
244
  return {
@@ -253,7 +252,10 @@ function generateFunctionParameters(
253
252
  const functionParams: string[] = []
254
253
  const queryParams: string[] = []
255
254
 
256
- for (const p of params) {
255
+ // Track which path params are already declared from the spec
256
+ const declaredPathParams = new Set<string>()
257
+
258
+ for (const p of (params ?? [])) {
257
259
  const param = dereference(p)
258
260
  const pSchema = dereference(param.schema)
259
261
 
@@ -269,6 +271,10 @@ function generateFunctionParameters(
269
271
  varName = `_${varName}`
270
272
  }
271
273
 
274
+ if (param.in === 'path') {
275
+ declaredPathParams.add(paramName)
276
+ }
277
+
272
278
  if (param.in === 'path' || param.in === 'query' || param.in === 'header') {
273
279
  functionParams.push(
274
280
  formatVarType({
@@ -287,6 +293,17 @@ function generateFunctionParameters(
287
293
  }
288
294
  }
289
295
 
296
+ // Inject any path params present in the URL but missing from the spec's parameters list
297
+ const pathParamsInUrl = getParamsFromPath(path) ?? []
298
+ for (const paramName of pathParamsInUrl) {
299
+ if (!declaredPathParams.has(paramName)) {
300
+ const varName = toCamelCaseSafe(paramName)
301
+ functionParams.unshift(`${varName}: string`)
302
+ }
303
+ }
304
+
305
+ if (functionParams.length === 0 && queryParams.length === 0) { return {} }
306
+
290
307
  return {
291
308
  params: functionParams.join(', '),
292
309
  config: queryParams.length ? { params: queryParams.join(', ') } : undefined,
@@ -629,6 +646,7 @@ function generateFunctionForOperation(
629
646
  const isFileUpload = isReferenceObject(multiPartSchema) && multiPartSchema?.$ref?.includes('Body_upload_files')
630
647
 
631
648
  const parameters = generateFunctionParameters(
649
+ path,
632
650
  operation.parameters,
633
651
  isFileUpload
634
652
  )