-
Notifications
You must be signed in to change notification settings - Fork 62
feat(js-sdk): support per-request custom headers #595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
WalkthroughUpdated 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
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
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
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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 forwardedThis 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.
📒 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 }; |
There was a problem hiding this comment.
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.
| 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.
Summary
Testing
make test-client-js(fails: docker: not found)https://chatgpt.com/codex/tasks/task_e_689e30cc7cac8322bb66ce1ec6428da3
Summary by CodeRabbit
Bug Fixes
Tests