diff --git a/sdks/ts/src/utils/requestConstructor.ts b/sdks/ts/src/utils/requestConstructor.ts index aa9fcaefe..f7033c858 100644 --- a/sdks/ts/src/utils/requestConstructor.ts +++ b/sdks/ts/src/utils/requestConstructor.ts @@ -1,3 +1,4 @@ +// Utility functions for constructing and handling API requests. import type { OpenAPIConfig } from "../api"; import type { ApiRequestOptions } from "../api/core/ApiRequestOptions"; @@ -7,6 +8,7 @@ import { isPlainObject, mapKeys, camelCase } from "lodash"; import { AxiosHttpRequest } from "../api/core/AxiosHttpRequest"; import { CancelablePromise } from "../api/core/CancelablePromise"; +// Converts all keys in the given object to camelCase. Useful for normalizing API response objects. const camelCaseify = (responseBody: any) => mapKeys(responseBody, (_value: any, key: string) => camelCase(key)); @@ -15,12 +17,14 @@ export class CustomHttpRequest extends AxiosHttpRequest { super(config); } + // Overrides the base request method to apply additional processing on the response, such as camelCasing keys and handling collections. public override request(options: ApiRequestOptions): CancelablePromise { const cancelableResponse = super.request(options); return new CancelablePromise((resolve, reject, onCancel) => { onCancel(() => cancelableResponse.cancel()); + // Processes the API response, converting keys to camelCase and specifically handling 'items' arrays if present. const handleResponse = (responseBody: any) => { // If the response body is not a plain object, return it as is if (!isPlainObject(responseBody)) { @@ -32,6 +36,7 @@ export class CustomHttpRequest extends AxiosHttpRequest { updatedResponseBody = camelCaseify(updatedResponseBody); if ("items" in updatedResponseBody) { + // Apply camelCase conversion to each item in the 'items' array, if it exists. updatedResponseBody.items = updatedResponseBody.items.map(camelCaseify); }