Skip to content

Fix snake_case to camelCase deserialization in API responses#41

Merged
Subterrane merged 4 commits into
developfrom
copilot/fix-attribute-mapping
Nov 21, 2025
Merged

Fix snake_case to camelCase deserialization in API responses#41
Subterrane merged 4 commits into
developfrom
copilot/fix-attribute-mapping

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Nov 21, 2025

API response properties like access_token were not being mapped to their camelCase TypeScript equivalents (accessToken), causing all response fields to be undefined.

Root Cause

The request() method used body?.constructor?.name for deserialization type inference, which returns "Object" for JSON responses instead of the expected model type name (e.g., "GenerateToken200Response"). This bypassed the ObjectSerializer's snake_case→camelCase mapping.

Changes

  • Added optional responseTypeName parameter to request() method signature
  • Updated deserialization to use explicit type name: ObjectSerializer.deserialize(body, responseTypeName || body?.constructor?.name)
  • Passed response type names to all 151 API method calls

Example

// Before: deserialization fails, accessToken is undefined
const { body } = await api.generateToken(auth, request);
console.log(body.accessToken); // undefined ❌

// After: proper mapping from access_token → accessToken
return this.request<GenerateToken200Response>(
  "POST",
  "/auth/oauth2/v2/token",
  authorization,
  generateTokenRequest,
  {},
  options,
  "GenerateToken200Response" // explicit type for deserialization
);

const { body } = await api.generateToken(auth, request);
console.log(body.accessToken); // "eyJhbGc..." ✅

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • onelogininc.onelogin.com
    • Triggering command: /usr/local/bin/node node /tmp/test_token_mapping.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>Attribute mapping not working</issue_title>
<issue_description>Hello Team,

When testing the sdk, I followed the steps to clone, build and use the sdk locally. However, when I make the first call to generate the accessToken, the request works just fine. However, body.accessToken returns an undefined, as the mapping from snake_case to camelCase is not handled well

it('generates an access token', async () => {
        const authorization = `client_id:${config.clientId}, client_secret:${config.clientSecret}`;
        const generateTokenRequest = new GenerateTokenRequest();
        generateTokenRequest.grantType = GenerateTokenRequest.GrantTypeEnum.ClientCredentials;

        const { body } = await onelogin.generateToken(authorization, generateTokenRequest);

        expect(body.accessToken).toBeDefined();
    });

I'm using the version v3 of the sdk</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ 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 3 commits November 21, 2025 23:06
Co-authored-by: Subterrane <5290140+Subterrane@users.noreply.github.com>
- Modified request() method to accept responseTypeName parameter
- Updated all API method calls to pass the expected type name
- Fixed deserialization to use provided type name instead of runtime constructor name
- Resolves snake_case to camelCase mapping issues for all API responses

Co-authored-by: Subterrane <5290140+Subterrane@users.noreply.github.com>
Co-authored-by: Subterrane <5290140+Subterrane@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix attribute mapping for accessToken Fix snake_case to camelCase deserialization in API responses Nov 21, 2025
Copilot AI requested a review from Subterrane November 21, 2025 23:25
@Subterrane Subterrane marked this pull request as ready for review November 21, 2025 23:42
@Subterrane Subterrane merged commit 97774c9 into develop Nov 21, 2025
6 checks passed
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.

Attribute mapping not working

2 participants