@bagelink/sdk 1.6.2 → 1.6.7

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
@@ -496,6 +496,21 @@ function generateFunctionForOperation(method, path, operation) {
496
496
  if (!operation) {
497
497
  return "";
498
498
  }
499
+ const methodLower = method.toLowerCase();
500
+ if (["get", "delete"].includes(methodLower) && operation.requestBody) {
501
+ const requestBodyDeref = dereference(operation.requestBody);
502
+ const content = requestBodyDeref?.content;
503
+ if (content && Object.keys(content).length > 0) {
504
+ const hasSchema = Object.values(content).some(
505
+ (mediaType) => mediaType && "schema" in mediaType && mediaType.schema !== void 0 && mediaType.schema !== null
506
+ );
507
+ if (hasSchema) {
508
+ throw new Error(
509
+ `Invalid OpenAPI spec: ${method.toUpperCase()} request at path "${path}" has a request body. GET and DELETE requests should not have request bodies according to HTTP standards. Please move the body parameters to query parameters or use a different HTTP method.`
510
+ );
511
+ }
512
+ }
513
+ }
499
514
  const multiPartSchema = dereference(operation.requestBody)?.content?.["multipart/form-data"]?.schema;
500
515
  const isFileUpload = isReferenceObject(multiPartSchema) && multiPartSchema?.$ref?.includes("Body_upload_files");
501
516
  const parameters = generateFunctionParameters(
package/dist/index.mjs CHANGED
@@ -490,6 +490,21 @@ function generateFunctionForOperation(method, path, operation) {
490
490
  if (!operation) {
491
491
  return "";
492
492
  }
493
+ const methodLower = method.toLowerCase();
494
+ if (["get", "delete"].includes(methodLower) && operation.requestBody) {
495
+ const requestBodyDeref = dereference(operation.requestBody);
496
+ const content = requestBodyDeref?.content;
497
+ if (content && Object.keys(content).length > 0) {
498
+ const hasSchema = Object.values(content).some(
499
+ (mediaType) => mediaType && "schema" in mediaType && mediaType.schema !== void 0 && mediaType.schema !== null
500
+ );
501
+ if (hasSchema) {
502
+ throw new Error(
503
+ `Invalid OpenAPI spec: ${method.toUpperCase()} request at path "${path}" has a request body. GET and DELETE requests should not have request bodies according to HTTP standards. Please move the body parameters to query parameters or use a different HTTP method.`
504
+ );
505
+ }
506
+ }
507
+ }
493
508
  const multiPartSchema = dereference(operation.requestBody)?.content?.["multipart/form-data"]?.schema;
494
509
  const isFileUpload = isReferenceObject(multiPartSchema) && multiPartSchema?.$ref?.includes("Body_upload_files");
495
510
  const parameters = generateFunctionParameters(
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/sdk",
3
3
  "type": "module",
4
- "version": "1.6.2",
4
+ "version": "1.6.7",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Neveh Allon",
@@ -384,8 +384,6 @@ function generateAxiosFunction(
384
384
  } else {
385
385
  const configParams = paramStr ? `, { ${paramStr} }` : ''
386
386
  const bodyVar = requestBodyPayload || '{}'
387
-
388
- // Handle different HTTP methods appropriately
389
387
  axiosFunction += `return axios.${method}(${formattedPath}${
390
388
  ['get', 'delete'].includes(method)
391
389
  ? configParams
@@ -445,6 +443,27 @@ function generateFunctionForOperation(
445
443
  ): string {
446
444
  if (!operation) { return '' }
447
445
 
446
+ // Validate: GET and DELETE requests should not have request bodies
447
+ const methodLower = method.toLowerCase()
448
+ if (['get', 'delete'].includes(methodLower) && operation.requestBody) {
449
+ const requestBodyDeref = dereference(operation.requestBody)
450
+ const content = requestBodyDeref?.content
451
+ // Check if request body has actual content with schemas
452
+ if (content && Object.keys(content).length > 0) {
453
+ // Check if any content type has a schema (indicating actual body data)
454
+ const hasSchema = Object.values(content).some(
455
+ mediaType => mediaType && 'schema' in mediaType && mediaType.schema !== undefined && mediaType.schema !== null
456
+ )
457
+ if (hasSchema) {
458
+ throw new Error(
459
+ `Invalid OpenAPI spec: ${method.toUpperCase()} request at path "${path}" has a request body. `
460
+ + `GET and DELETE requests should not have request bodies according to HTTP standards. `
461
+ + `Please move the body parameters to query parameters or use a different HTTP method.`
462
+ )
463
+ }
464
+ }
465
+ }
466
+
448
467
  // Check if this is a file upload
449
468
  const multiPartSchema = dereference(operation.requestBody)?.content?.[
450
469
  'multipart/form-data'