mongodb-atlas-api-client icon indicating copy to clipboard operation
mongodb-atlas-api-client copied to clipboard

Add headers support for MongoDB Atlas API v2 compatibility

Open Copilot opened this issue 3 months ago • 1 comments

This PR adds support for custom headers in the MongoDB Atlas API client to enable compatibility with the new MongoDB Atlas Administration API v2.

Progress Checklist

  • [x] Add headers support to HttpClient constructor and methods
  • [x] Update entry point to pass headers from configuration to HttpClient
  • [x] Add TypeScript interface definition for headers
  • [x] Add comprehensive test suite for headers functionality
  • [x] Update existing tests to include headers parameter
  • [x] Add header verification tests for AtlasSearch methods
  • [x] Ensure all tests pass with 100% code coverage
  • [x] Address code review feedback

Recent Changes

Added specific tests to verify that custom headers are properly passed through when using AtlasSearch methods:

  • Integration test showing headers are included in actual HTTP requests
  • Unit test verifying headers are passed to underlying request calls

Implementation Details

  • HttpClient: Modified constructor to accept optional headers parameter and updated fetch/fetchStream methods to properly merge default headers with method-specific headers
  • Entry Point: Updated getMongodbAtlasApiClient to pass headers from configuration to HttpClient
  • TypeScript: Added headers?: Record<string, string> to AtlasClientConfig interface
  • Header Merging: Custom headers are merged with method-specific headers (like Content-Type) and httpOptions headers, with method-specific headers taking precedence

Testing

Added comprehensive test suite covering:

  • Default header inclusion in requests
  • Header merging with method-specific headers
  • Header merging with httpOptions headers
  • Backward compatibility (works without headers parameter)
  • Edge cases with empty headers
  • AtlasSearch-specific header verification

All tests pass with 100% code coverage maintained.

Fixes #58.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Sep 04 '25 11:09 Copilot

@montumodi 👋 This repository doesn't have Copilot instructions. With Copilot instructions, I can understand the repository better, work faster and produce higher quality PRs.

I can generate a .github/copilot-instructions.md file for you automatically. Click here to open a pre-filled issue and assign it to me. I'll write the instructions, and then tag you for review.

Copilot avatar Sep 04 '25 11:09 Copilot

@copilot I have added copilot instructions in main branch, may be merge main to this branch and redo everything as utillizing that instructions file.

montumodi avatar Dec 03 '25 12:12 montumodi

@copilot I have added copilot instructions in main branch, may be merge main to this branch and redo everything as utillizing that instructions file.

I've merged the master branch containing the copilot instructions and verified that the existing implementation already follows all the guidelines specified in .github/copilot-instructions.md.

The headers support implementation:

  • Follows established code patterns (private properties with underscore, consistent class structure)
  • Test suite follows the documented test framework pattern with MockAgent
  • Maintains 100% code coverage
  • Passes all linting rules
  • Is backward compatible with no breaking changes
  • Makes minimal, surgical changes to the codebase

All tests pass successfully, code review found no issues, and the security scan shows no vulnerabilities. Commit: 0350b54

Copilot avatar Dec 03 '25 12:12 Copilot