@bagelink/sdk 1.2.54 → 1.2.58
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 +17 -49
- package/dist/index.mjs +17 -49
- package/package.json +1 -1
- package/src/openAPITools/functionGenerator.ts +35 -72
package/dist/index.cjs
CHANGED
|
@@ -258,19 +258,7 @@ function generateAxiosFunction(method, formattedPath, allParams, responseTypeStr
|
|
|
258
258
|
axiosFunction += "}";
|
|
259
259
|
return axiosFunction;
|
|
260
260
|
}
|
|
261
|
-
function
|
|
262
|
-
if (!operation) return "";
|
|
263
|
-
const isFileUpload = operation.requestBody?.content["multipart/form-data"]?.schema?.$ref?.includes("Body_upload_files");
|
|
264
|
-
const parameters = generateFunctionParameters(
|
|
265
|
-
operation.parameters,
|
|
266
|
-
isFileUpload
|
|
267
|
-
);
|
|
268
|
-
const { requestBodyParam, requestBodyPayload } = generateRequestBody(
|
|
269
|
-
operation.requestBody
|
|
270
|
-
);
|
|
271
|
-
const allParams = isFileUpload ? "file: File, options?: UploadOptions & { dirPath?: string, tags?: string[] }" : combineAllParams(parameters, requestBodyParam);
|
|
272
|
-
const responseType = generateResponseType(operation.responses);
|
|
273
|
-
const responseTypeStr = responseType ? `: Promise<AxiosResponse<${responseType}>>` : "";
|
|
261
|
+
function buildJSDocComment(operation, method, path) {
|
|
274
262
|
let functionComment = "/**\n";
|
|
275
263
|
if (operation.summary) {
|
|
276
264
|
functionComment += ` * ${operation.summary}
|
|
@@ -288,43 +276,23 @@ function generateFunctionForOperation(method, path, operation) {
|
|
|
288
276
|
functionComment += ` *
|
|
289
277
|
* @endpoint ${method.toUpperCase()} ${path}
|
|
290
278
|
`;
|
|
291
|
-
if (operation.parameters?.length) {
|
|
292
|
-
functionComment += " *\n";
|
|
293
|
-
operation.parameters.forEach((param) => {
|
|
294
|
-
const paramType = schemaToType(param.schema);
|
|
295
|
-
const paramName = toCamelCase(param.name);
|
|
296
|
-
const required = param.required ? "" : "?";
|
|
297
|
-
functionComment += ` * @param {${paramType}} ${paramName}${required}`;
|
|
298
|
-
if (param.description) {
|
|
299
|
-
functionComment += ` - ${param.description}`;
|
|
300
|
-
} else {
|
|
301
|
-
functionComment += ` - ${param.name} parameter`;
|
|
302
|
-
}
|
|
303
|
-
functionComment += "\n";
|
|
304
|
-
});
|
|
305
|
-
}
|
|
306
|
-
if (operation.requestBody && requestBodyParam) {
|
|
307
|
-
const bodyParamName = requestBodyParam.split(":")[0].trim();
|
|
308
|
-
const bodyParamType = requestBodyParam.split(":")[1]?.split("=")[0]?.trim() || "any";
|
|
309
|
-
functionComment += ` * @param {${bodyParamType}} ${bodyParamName}`;
|
|
310
|
-
if (operation.requestBody.description) {
|
|
311
|
-
functionComment += ` - ${operation.requestBody.description}`;
|
|
312
|
-
} else {
|
|
313
|
-
functionComment += ` - Request body`;
|
|
314
|
-
}
|
|
315
|
-
functionComment += "\n";
|
|
316
|
-
}
|
|
317
|
-
if (responseType) {
|
|
318
|
-
functionComment += ` * @returns {Promise<AxiosResponse<${responseType}>>} The API response
|
|
319
|
-
`;
|
|
320
|
-
for (const [statusCode, response] of Object.entries(operation.responses)) {
|
|
321
|
-
if (statusCode.startsWith("2") && response.description) {
|
|
322
|
-
functionComment += ` * @response ${statusCode} - ${response.description}
|
|
323
|
-
`;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
279
|
functionComment += " */\n";
|
|
280
|
+
return functionComment;
|
|
281
|
+
}
|
|
282
|
+
function generateFunctionForOperation(method, path, operation) {
|
|
283
|
+
if (!operation) return "";
|
|
284
|
+
const isFileUpload = operation.requestBody?.content["multipart/form-data"]?.schema?.$ref?.includes("Body_upload_files");
|
|
285
|
+
const parameters = generateFunctionParameters(
|
|
286
|
+
operation.parameters,
|
|
287
|
+
isFileUpload
|
|
288
|
+
);
|
|
289
|
+
const { requestBodyParam, requestBodyPayload } = generateRequestBody(
|
|
290
|
+
operation.requestBody
|
|
291
|
+
);
|
|
292
|
+
const allParams = isFileUpload ? "file: File, options?: UploadOptions & { dirPath?: string, tags?: string[] }" : combineAllParams(parameters, requestBodyParam);
|
|
293
|
+
const responseType = generateResponseType(operation.responses);
|
|
294
|
+
const responseTypeStr = responseType ? `: Promise<AxiosResponse<${responseType}>>` : "";
|
|
295
|
+
const functionComment = buildJSDocComment(operation, method, path);
|
|
328
296
|
return functionComment + generateAxiosFunction(
|
|
329
297
|
method,
|
|
330
298
|
formatPathWithParams(path),
|
package/dist/index.mjs
CHANGED
|
@@ -252,19 +252,7 @@ function generateAxiosFunction(method, formattedPath, allParams, responseTypeStr
|
|
|
252
252
|
axiosFunction += "}";
|
|
253
253
|
return axiosFunction;
|
|
254
254
|
}
|
|
255
|
-
function
|
|
256
|
-
if (!operation) return "";
|
|
257
|
-
const isFileUpload = operation.requestBody?.content["multipart/form-data"]?.schema?.$ref?.includes("Body_upload_files");
|
|
258
|
-
const parameters = generateFunctionParameters(
|
|
259
|
-
operation.parameters,
|
|
260
|
-
isFileUpload
|
|
261
|
-
);
|
|
262
|
-
const { requestBodyParam, requestBodyPayload } = generateRequestBody(
|
|
263
|
-
operation.requestBody
|
|
264
|
-
);
|
|
265
|
-
const allParams = isFileUpload ? "file: File, options?: UploadOptions & { dirPath?: string, tags?: string[] }" : combineAllParams(parameters, requestBodyParam);
|
|
266
|
-
const responseType = generateResponseType(operation.responses);
|
|
267
|
-
const responseTypeStr = responseType ? `: Promise<AxiosResponse<${responseType}>>` : "";
|
|
255
|
+
function buildJSDocComment(operation, method, path) {
|
|
268
256
|
let functionComment = "/**\n";
|
|
269
257
|
if (operation.summary) {
|
|
270
258
|
functionComment += ` * ${operation.summary}
|
|
@@ -282,43 +270,23 @@ function generateFunctionForOperation(method, path, operation) {
|
|
|
282
270
|
functionComment += ` *
|
|
283
271
|
* @endpoint ${method.toUpperCase()} ${path}
|
|
284
272
|
`;
|
|
285
|
-
if (operation.parameters?.length) {
|
|
286
|
-
functionComment += " *\n";
|
|
287
|
-
operation.parameters.forEach((param) => {
|
|
288
|
-
const paramType = schemaToType(param.schema);
|
|
289
|
-
const paramName = toCamelCase(param.name);
|
|
290
|
-
const required = param.required ? "" : "?";
|
|
291
|
-
functionComment += ` * @param {${paramType}} ${paramName}${required}`;
|
|
292
|
-
if (param.description) {
|
|
293
|
-
functionComment += ` - ${param.description}`;
|
|
294
|
-
} else {
|
|
295
|
-
functionComment += ` - ${param.name} parameter`;
|
|
296
|
-
}
|
|
297
|
-
functionComment += "\n";
|
|
298
|
-
});
|
|
299
|
-
}
|
|
300
|
-
if (operation.requestBody && requestBodyParam) {
|
|
301
|
-
const bodyParamName = requestBodyParam.split(":")[0].trim();
|
|
302
|
-
const bodyParamType = requestBodyParam.split(":")[1]?.split("=")[0]?.trim() || "any";
|
|
303
|
-
functionComment += ` * @param {${bodyParamType}} ${bodyParamName}`;
|
|
304
|
-
if (operation.requestBody.description) {
|
|
305
|
-
functionComment += ` - ${operation.requestBody.description}`;
|
|
306
|
-
} else {
|
|
307
|
-
functionComment += ` - Request body`;
|
|
308
|
-
}
|
|
309
|
-
functionComment += "\n";
|
|
310
|
-
}
|
|
311
|
-
if (responseType) {
|
|
312
|
-
functionComment += ` * @returns {Promise<AxiosResponse<${responseType}>>} The API response
|
|
313
|
-
`;
|
|
314
|
-
for (const [statusCode, response] of Object.entries(operation.responses)) {
|
|
315
|
-
if (statusCode.startsWith("2") && response.description) {
|
|
316
|
-
functionComment += ` * @response ${statusCode} - ${response.description}
|
|
317
|
-
`;
|
|
318
|
-
}
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
273
|
functionComment += " */\n";
|
|
274
|
+
return functionComment;
|
|
275
|
+
}
|
|
276
|
+
function generateFunctionForOperation(method, path, operation) {
|
|
277
|
+
if (!operation) return "";
|
|
278
|
+
const isFileUpload = operation.requestBody?.content["multipart/form-data"]?.schema?.$ref?.includes("Body_upload_files");
|
|
279
|
+
const parameters = generateFunctionParameters(
|
|
280
|
+
operation.parameters,
|
|
281
|
+
isFileUpload
|
|
282
|
+
);
|
|
283
|
+
const { requestBodyParam, requestBodyPayload } = generateRequestBody(
|
|
284
|
+
operation.requestBody
|
|
285
|
+
);
|
|
286
|
+
const allParams = isFileUpload ? "file: File, options?: UploadOptions & { dirPath?: string, tags?: string[] }" : combineAllParams(parameters, requestBodyParam);
|
|
287
|
+
const responseType = generateResponseType(operation.responses);
|
|
288
|
+
const responseTypeStr = responseType ? `: Promise<AxiosResponse<${responseType}>>` : "";
|
|
289
|
+
const functionComment = buildJSDocComment(operation, method, path);
|
|
322
290
|
return functionComment + generateAxiosFunction(
|
|
323
291
|
method,
|
|
324
292
|
formatPathWithParams(path),
|
package/package.json
CHANGED
|
@@ -339,6 +339,40 @@ function generateAxiosFunction(
|
|
|
339
339
|
return axiosFunction
|
|
340
340
|
}
|
|
341
341
|
|
|
342
|
+
/**
|
|
343
|
+
* Builds a JSDoc comment for an OpenAPI operation
|
|
344
|
+
* @param operation - The OpenAPI operation object
|
|
345
|
+
* @param method - The HTTP method
|
|
346
|
+
* @param path - The API path
|
|
347
|
+
* @returns The JSDoc comment as a string
|
|
348
|
+
*/
|
|
349
|
+
function buildJSDocComment(operation: OperationObject, method: string, path: string) {
|
|
350
|
+
let functionComment = '/**\n'
|
|
351
|
+
|
|
352
|
+
// Add summary
|
|
353
|
+
if (operation.summary) {
|
|
354
|
+
functionComment += ` * ${operation.summary}\n`
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// Add description if available
|
|
358
|
+
if (operation.description) {
|
|
359
|
+
// If there's already a summary, add a line break
|
|
360
|
+
if (operation.summary) functionComment += ` *\n`
|
|
361
|
+
|
|
362
|
+
// Split description into lines and add each line with proper JSDoc formatting
|
|
363
|
+
const descriptionLines = operation.description.split('\n')
|
|
364
|
+
descriptionLines.forEach((line: string) => {
|
|
365
|
+
functionComment += ` * ${line}\n`
|
|
366
|
+
})
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
// Add endpoint path and method information
|
|
370
|
+
functionComment += ` *\n * @endpoint ${method.toUpperCase()} ${path}\n`
|
|
371
|
+
|
|
372
|
+
functionComment += ' */\n'
|
|
373
|
+
return functionComment
|
|
374
|
+
}
|
|
375
|
+
|
|
342
376
|
/**
|
|
343
377
|
* Generates a function for an OpenAPI operation
|
|
344
378
|
* @param method - The HTTP method
|
|
@@ -377,78 +411,7 @@ function generateFunctionForOperation(
|
|
|
377
411
|
: ''
|
|
378
412
|
|
|
379
413
|
// Create JSDoc comment with OpenAPI documentation
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
// Add summary
|
|
383
|
-
if (operation.summary) {
|
|
384
|
-
functionComment += ` * ${operation.summary}\n`
|
|
385
|
-
}
|
|
386
|
-
|
|
387
|
-
// Add description if available
|
|
388
|
-
if (operation.description) {
|
|
389
|
-
// If there's already a summary, add a line break
|
|
390
|
-
if (operation.summary) functionComment += ` *\n`
|
|
391
|
-
|
|
392
|
-
// Split description into lines and add each line with proper JSDoc formatting
|
|
393
|
-
const descriptionLines = operation.description.split('\n')
|
|
394
|
-
descriptionLines.forEach((line: string) => {
|
|
395
|
-
functionComment += ` * ${line}\n`
|
|
396
|
-
})
|
|
397
|
-
}
|
|
398
|
-
|
|
399
|
-
// Add endpoint path and method information
|
|
400
|
-
functionComment += ` *\n * @endpoint ${method.toUpperCase()} ${path}\n`
|
|
401
|
-
|
|
402
|
-
// Add parameter documentation if available
|
|
403
|
-
if (operation.parameters?.length) {
|
|
404
|
-
functionComment += ' *\n'
|
|
405
|
-
operation.parameters.forEach((param) => {
|
|
406
|
-
const paramType = schemaToType(param.schema)
|
|
407
|
-
const paramName = toCamelCase(param.name)
|
|
408
|
-
const required = param.required ? '' : '?'
|
|
409
|
-
|
|
410
|
-
functionComment += ` * @param {${paramType}} ${paramName}${required}`
|
|
411
|
-
|
|
412
|
-
// Add parameter description if available
|
|
413
|
-
if (param.description) {
|
|
414
|
-
functionComment += ` - ${param.description}`
|
|
415
|
-
} else {
|
|
416
|
-
functionComment += ` - ${param.name} parameter`
|
|
417
|
-
}
|
|
418
|
-
|
|
419
|
-
functionComment += '\n'
|
|
420
|
-
})
|
|
421
|
-
}
|
|
422
|
-
|
|
423
|
-
// Add requestBody documentation if available
|
|
424
|
-
if (operation.requestBody && requestBodyParam) {
|
|
425
|
-
const bodyParamName = requestBodyParam.split(':')[0].trim()
|
|
426
|
-
const bodyParamType = requestBodyParam.split(':')[1]?.split('=')[0]?.trim() || 'any'
|
|
427
|
-
|
|
428
|
-
functionComment += ` * @param {${bodyParamType}} ${bodyParamName}`
|
|
429
|
-
|
|
430
|
-
if (operation.requestBody.description) {
|
|
431
|
-
functionComment += ` - ${operation.requestBody.description}`
|
|
432
|
-
} else {
|
|
433
|
-
functionComment += ` - Request body`
|
|
434
|
-
}
|
|
435
|
-
|
|
436
|
-
functionComment += '\n'
|
|
437
|
-
}
|
|
438
|
-
|
|
439
|
-
// Add response documentation
|
|
440
|
-
if (responseType) {
|
|
441
|
-
functionComment += ` * @returns {Promise<AxiosResponse<${responseType}>>} The API response\n`
|
|
442
|
-
|
|
443
|
-
// Include any response descriptions for 2xx status codes
|
|
444
|
-
for (const [statusCode, response] of Object.entries(operation.responses)) {
|
|
445
|
-
if (statusCode.startsWith('2') && response.description) {
|
|
446
|
-
functionComment += ` * @response ${statusCode} - ${response.description}\n`
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
|
|
451
|
-
functionComment += ' */\n'
|
|
414
|
+
const functionComment = buildJSDocComment(operation, method, path)
|
|
452
415
|
|
|
453
416
|
return functionComment + generateAxiosFunction(
|
|
454
417
|
method,
|