Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion config/clients/js/template/apiInner.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ export const {{classname}}AxiosParamCreator = function (configuration: Configura

{{/bodyParam}}
setSearchParams(localVarUrlObj, localVarQueryParameter, options.query);
localVarRequestOptions.headers = {...localVarHeaderParameter, ...options.headers};
localVarRequestOptions.headers = { ...baseOptions?.headers, ...localVarHeaderParameter, ...options.headers };
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Avoid spreading possibly-undefined headers to prevent runtime errors

If either baseOptions?.headers or options.headers is undefined/null, spreading them may throw at runtime depending on transpilation target. Use a safe fallback when merging.

Apply this diff:

-            localVarRequestOptions.headers = { ...baseOptions?.headers, ...localVarHeaderParameter, ...options.headers };
+            localVarRequestOptions.headers = {
+                ...(baseOptions?.headers ?? {}),
+                ...localVarHeaderParameter,
+                ...(options?.headers ?? {}),
+            };

This preserves your intended precedence (options.headers > localVarHeaderParameter > baseOptions.headers) while making the merge resilient.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
localVarRequestOptions.headers = { ...baseOptions?.headers, ...localVarHeaderParameter, ...options.headers };
localVarRequestOptions.headers = {
...(baseOptions?.headers ?? {}),
...localVarHeaderParameter,
...(options?.headers ?? {}),
};
🤖 Prompt for AI Agents
In config/clients/js/template/apiInner.mustache around line 174, the current
header merge spreads baseOptions?.headers and options.headers directly which can
throw if they are undefined; change the merge to use safe fallbacks so you
spread (baseOptions?.headers ?? {}) first, then localVarHeaderParameter, then
(options?.headers ?? {}) to preserve the intended precedence (options.headers >
localVarHeaderParameter > baseOptions.headers) and avoid runtime errors.

{{#hasFormParams}}
localVarRequestOptions.data = localVarFormParams{{#vendorExtensions}}{{^multipartFormData}}.toString(){{/multipartFormData}}{{/vendorExtensions}};
{{/hasFormParams}}
Expand Down
11 changes: 11 additions & 0 deletions config/clients/js/template/tests/client.test.ts.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ describe("{{appTitleCaseName}} Client", () => {
expect(response.stores).toHaveLength(1);
expect(response.stores?.[0]).toMatchObject(store);
});

it("should include custom headers when provided", async () => {
const scope = nock(defaultConfiguration.getBasePath())
.get("/stores")
.matchHeader("X-Correlation-ID", "abc123")
.reply(200, { continuation_token: "", stores: [] });

await fgaClient.listStores({ headers: { "X-Correlation-ID": "abc123" } });

expect(scope.isDone()).toBe(true);
});
});

describe("CreateStore", () => {
Expand Down
Loading