Skip to content

Conversation

@aaguiarz
Copy link
Member

@aaguiarz aaguiarz commented Aug 14, 2025

Summary

  • include base and custom headers in generated requests for JS SDK
  • test that JS client forwards per-request headers

Testing

  • make test-client-js (fails: docker: not found)

https://chatgpt.com/codex/tasks/task_e_689e30cc7cac8322bb66ce1ec6428da3

Summary by CodeRabbit

  • Bug Fixes

    • Per-request custom headers now correctly merge and take precedence over default headers in the JavaScript client, ensuring values like correlation IDs and other custom headers are reliably sent with API calls.
  • Tests

    • Added coverage verifying custom headers are included when calling listStores, ensuring header merging behaves as expected.

@aaguiarz aaguiarz requested a review from a team as a code owner August 14, 2025 20:51
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 14, 2025

Walkthrough

Updated Axios request header merge logic in the JS client template to include baseOptions.headers with defined precedence. Added a test in the test template to verify custom headers are sent on ListStores requests.

Changes

Cohort / File(s) Summary
JS client header merge
config/clients/js/template/apiInner.mustache
Modified header composition to { ...baseOptions?.headers, ...localVarHeaderParameter, ...options.headers }, changing precedence to options > localVar > baseOptions. No other request-building logic changed.
Tests for custom headers
config/clients/js/template/tests/client.test.ts.mustache
Added test ensuring custom headers (X-Correlation-ID) are included in ListStores GET request using nock; no production exports altered.

Sequence Diagram(s)

sequenceDiagram
  participant Caller
  participant AxiosParamCreator
  participant Axios

  Caller->>AxiosParamCreator: create request (options.headers, baseOptions.headers)
  AxiosParamCreator->>AxiosParamCreator: Merge headers: baseOptions < localVar < options
  AxiosParamCreator->>Axios: send request with merged headers
  Axios-->>Caller: response
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Tip

🔌 Remote MCP (Model Context Protocol) integration is now available!

Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch codex/determine-feature-exposure-in-javascript-sdk

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (1)
config/clients/js/template/tests/client.test.ts.mustache (1)

103-112: Good addition: validates per-request headers are forwarded

This test effectively verifies that request-scoped headers make it through the client.

Two quick follow-ups to harden coverage:

  • Also verify precedence when the same header exists in both the base configuration and per-request options (per-request should win).
  • Add one similar assertion for a non-GET endpoint (e.g., CreateStore) to ensure parity across verbs.
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these settings in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 7c39d23 and 9d93198.

📒 Files selected for processing (2)
  • config/clients/js/template/apiInner.mustache (1 hunks)
  • config/clients/js/template/tests/client.test.ts.mustache (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build-and-test-go-sdk
  • GitHub Check: build-and-test-java-sdk

{{/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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants