Skip to content

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Aug 21, 2025

Fixed a type inconsistency bug where apiVersion was returned as different types depending on the source:

Problem:

  • When apiVersion was extracted from Accept header via regex match, it returned a string (e.g., '1')
  • When apiVersion came from defaultVersion option, it returned a number (e.g., 1)
  • This inconsistency could cause issues in applications using strict type checking

Example of the issue:

const requestVersion = require('@cmsgov/qpp-shared-api-versioning-node');

// Case 1: From Accept header - returned STRING
const req1 = { headers: { accept: 'application/vnd.qpp.cms.gov.v1+json' } };
requestVersion.setVersion()(req1, {}, () => {});
console.log(typeof req1.apiVersion); // "string" (was inconsistent)

// Case 2: From defaultVersion - returned NUMBER  
const req2 = { headers: {} };
requestVersion.setVersion({ defaultVersion: 1 })(req2, {}, () => {});
console.log(typeof req2.apiVersion); // "number" (always consistent)

Solution:

  • Modified index.js line 36 to use parseInt(version) instead of version
  • Now apiVersion consistently returns a number in both scenarios
  • Added focused test with assert.strictEqual() to prevent regression

Impact:

  • All existing tests pass (18/18)
  • Backward compatible - existing code using loose equality (==) continues to work
  • Improves reliability for applications using strict equality (===) or TypeScript

Fixes #33.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits August 21, 2025 15:35
Co-authored-by: bijujoseph <3535395+bijujoseph@users.noreply.github.com>
Co-authored-by: bijujoseph <3535395+bijujoseph@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] go work Fix apiVersion type inconsistency - ensure consistent number return type Aug 21, 2025
@Copilot Copilot AI requested a review from bijujoseph August 21, 2025 15:38
Copilot finished work on behalf of bijujoseph August 21, 2025 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

go work
2 participants