@bagelink/sdk 1.8.35 → 1.8.37

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
@@ -421,28 +421,35 @@ function schemaToTypeWithCollection(schema) {
421
421
  }
422
422
  function getResponseType(response) {
423
423
  if (isReferenceObject(response)) {
424
- return void 0;
424
+ return { type: void 0, isArray: false };
425
425
  }
426
426
  const mediaTypeObject = response.content?.["application/json"];
427
427
  if (!mediaTypeObject?.schema) {
428
- return void 0;
428
+ return { type: void 0, isArray: false };
429
429
  }
430
- return schemaToTypeWithCollection(mediaTypeObject.schema);
430
+ const schema = dereference(mediaTypeObject.schema);
431
+ const typeString = schemaToTypeWithCollection(schema);
432
+ const isArray = schema?.type === "array" || typeString?.endsWith("[]") || false;
433
+ return { type: typeString, isArray };
431
434
  }
432
435
  function generateResponseType(responses) {
433
436
  if (!responses) {
434
- return "";
437
+ return { type: "", isArray: false };
435
438
  }
436
439
  const types = [];
440
+ let isArrayResponse = false;
437
441
  for (const [statusCode, response] of Object.entries(responses)) {
438
442
  if (statusCode.startsWith("2")) {
439
- const responseType = getResponseType(response);
443
+ const { type: responseType, isArray } = getResponseType(response);
440
444
  if (responseType && responseType !== "any") {
441
445
  types.push(responseType);
446
+ if (isArray) {
447
+ isArrayResponse = true;
448
+ }
442
449
  }
443
450
  }
444
451
  }
445
- return types.join(" | ");
452
+ return { type: types.join(" | "), isArray: isArrayResponse };
446
453
  }
447
454
  function getParamsFromPath(path) {
448
455
  const pathParamRegex = /\{[^}]+\}/g;
@@ -726,8 +733,8 @@ function generateFunctionForOperation(method, path, operation) {
726
733
  operation.requestBody
727
734
  );
728
735
  const allParams = isFileUpload ? "file: File, options?: UploadOptions & { dirPath?: string, tags?: string[] }" : combineAllParams(parameters, requestBodyParam);
729
- const responseType = generateResponseType(operation.responses);
730
- const responseTypeStr = responseType ? `: Promise<ApiResponse<${responseType}>>` : "";
736
+ const { type: responseType, isArray: isArrayResponse } = generateResponseType(operation.responses);
737
+ const responseTypeStr = responseType ? isArrayResponse ? `: Promise<ApiResponse<${responseType}>>` : `: Promise<${responseType}>` : "";
731
738
  const functionComment = buildJSDocComment(operation, method, path);
732
739
  if (isStream) {
733
740
  const eventTypes = extractSSEEventTypes(operation);
package/dist/index.mjs CHANGED
@@ -415,28 +415,35 @@ function schemaToTypeWithCollection(schema) {
415
415
  }
416
416
  function getResponseType(response) {
417
417
  if (isReferenceObject(response)) {
418
- return void 0;
418
+ return { type: void 0, isArray: false };
419
419
  }
420
420
  const mediaTypeObject = response.content?.["application/json"];
421
421
  if (!mediaTypeObject?.schema) {
422
- return void 0;
422
+ return { type: void 0, isArray: false };
423
423
  }
424
- return schemaToTypeWithCollection(mediaTypeObject.schema);
424
+ const schema = dereference(mediaTypeObject.schema);
425
+ const typeString = schemaToTypeWithCollection(schema);
426
+ const isArray = schema?.type === "array" || typeString?.endsWith("[]") || false;
427
+ return { type: typeString, isArray };
425
428
  }
426
429
  function generateResponseType(responses) {
427
430
  if (!responses) {
428
- return "";
431
+ return { type: "", isArray: false };
429
432
  }
430
433
  const types = [];
434
+ let isArrayResponse = false;
431
435
  for (const [statusCode, response] of Object.entries(responses)) {
432
436
  if (statusCode.startsWith("2")) {
433
- const responseType = getResponseType(response);
437
+ const { type: responseType, isArray } = getResponseType(response);
434
438
  if (responseType && responseType !== "any") {
435
439
  types.push(responseType);
440
+ if (isArray) {
441
+ isArrayResponse = true;
442
+ }
436
443
  }
437
444
  }
438
445
  }
439
- return types.join(" | ");
446
+ return { type: types.join(" | "), isArray: isArrayResponse };
440
447
  }
441
448
  function getParamsFromPath(path) {
442
449
  const pathParamRegex = /\{[^}]+\}/g;
@@ -720,8 +727,8 @@ function generateFunctionForOperation(method, path, operation) {
720
727
  operation.requestBody
721
728
  );
722
729
  const allParams = isFileUpload ? "file: File, options?: UploadOptions & { dirPath?: string, tags?: string[] }" : combineAllParams(parameters, requestBodyParam);
723
- const responseType = generateResponseType(operation.responses);
724
- const responseTypeStr = responseType ? `: Promise<ApiResponse<${responseType}>>` : "";
730
+ const { type: responseType, isArray: isArrayResponse } = generateResponseType(operation.responses);
731
+ const responseTypeStr = responseType ? isArrayResponse ? `: Promise<ApiResponse<${responseType}>>` : `: Promise<${responseType}>` : "";
725
732
  const functionComment = buildJSDocComment(operation, method, path);
726
733
  if (isStream) {
727
734
  const eventTypes = extractSSEEventTypes(operation);
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bagelink/sdk",
3
3
  "type": "module",
4
- "version": "1.8.35",
4
+ "version": "1.8.37",
5
5
  "description": "Bagel core sdk packages",
6
6
  "author": {
7
7
  "name": "Bagel Studio",
@@ -101,36 +101,49 @@ function schemaToTypeWithCollection(schema?: OpenAPISchema | SchemaObject): stri
101
101
  /**
102
102
  * Extracts the response type from an OpenAPI response object
103
103
  * @param response - The OpenAPI response object
104
- * @returns The TypeScript type string or undefined
104
+ * @returns Object with type string and whether it's an array
105
105
  */
106
- function getResponseType(response: OpenAPIResponse | ReferenceObject): string | undefined {
106
+ function getResponseType(response: OpenAPIResponse | ReferenceObject): { type: string | undefined, isArray: boolean } {
107
107
  if (isReferenceObject(response)) {
108
- return undefined // TODO: handle references properly
108
+ return { type: undefined, isArray: false }
109
109
  }
110
110
  const mediaTypeObject = response.content?.['application/json']
111
- if (!mediaTypeObject?.schema) { return undefined }
112
- return schemaToTypeWithCollection(mediaTypeObject.schema)
111
+ if (!mediaTypeObject?.schema) { return { type: undefined, isArray: false } }
112
+
113
+ const schema = dereference(mediaTypeObject.schema)
114
+ const typeString = schemaToTypeWithCollection(schema)
115
+
116
+ // Check if schema is an array type
117
+ const isArray = schema?.type === 'array' || typeString?.endsWith('[]') || false
118
+
119
+ return { type: typeString, isArray }
113
120
  }
114
121
 
115
122
  /**
116
123
  * Generates the response type string from OpenAPI responses
117
124
  * @param responses - The OpenAPI responses object
118
- * @returns The TypeScript response type string
125
+ * @returns Object with type string and array detection
119
126
  */
120
- function generateResponseType(responses?: OpenAPIResponses): string {
121
- if (!responses) { return '' }
127
+ function generateResponseType(responses?: OpenAPIResponses): { type: string, isArray: boolean } {
128
+ if (!responses) { return { type: '', isArray: false } }
122
129
 
123
130
  const types: string[] = []
131
+ let isArrayResponse = false
132
+
124
133
  for (const [statusCode, response] of Object.entries(responses)) {
125
134
  if (statusCode.startsWith('2')) {
126
- const responseType = getResponseType(response)
135
+ const { type: responseType, isArray } = getResponseType(response)
127
136
  if (responseType && responseType !== 'any') {
128
137
  types.push(responseType)
138
+ // If any successful response is an array, mark as array
139
+ if (isArray) {
140
+ isArrayResponse = true
141
+ }
129
142
  }
130
143
  }
131
144
  }
132
145
 
133
- return types.join(' | ')
146
+ return { type: types.join(' | '), isArray: isArrayResponse }
134
147
  }
135
148
 
136
149
  /**
@@ -628,12 +641,15 @@ function generateFunctionForOperation(
628
641
  ? 'file: File, options?: UploadOptions & { dirPath?: string, tags?: string[] }'
629
642
  : combineAllParams(parameters, requestBodyParam)
630
643
 
631
- const responseType = generateResponseType(operation.responses)
644
+ const { type: responseType, isArray: isArrayResponse } = generateResponseType(operation.responses)
632
645
 
633
- // Always use ApiResponse wrapper for type consistency
634
- // The create() method will handle single objects vs arrays at runtime
646
+ // For arrays: ApiResponse<T[]> (works as array, has metadata)
647
+ // For single objects: T (runtime adds metadata, but type is plain T for assignment)
648
+ // Note: At runtime, single objects have metadata but TypeScript sees plain type for better DX
635
649
  const responseTypeStr = responseType
636
- ? `: Promise<ApiResponse<${responseType}>>`
650
+ ? isArrayResponse
651
+ ? `: Promise<ApiResponse<${responseType}>>`
652
+ : `: Promise<${responseType}>`
637
653
  : ''
638
654
 
639
655
  // Create JSDoc comment with OpenAPI documentation