{{ message }}
Correctly parse response bodies as JSON where the Content-Type is application/scim+json - #731
Merged
Merged
Conversation
…plication/scim+json`
GitHub has APIs that return `application/scim+json` response bodies. Currently, these responses are not parsed as JSON, and instead, an `ArrayBuffer` is returned in `response.data`.
This adds handling for `application/scim+json` so they are parsed as JSON as normal.
## Minimal reproduction
```js
import { Octokit } from "@octokit/rest";
import { enterpriseCloud } from "@octokit/plugin-enterprise-cloud";
const MyOctokit = Octokit.plugin(enterpriseCloud);
const myOctokit = new MyOctokit({
auth: "ghp_xxxxxxxx",
});
const resp = await myOctokit.request('GET /scim/v2/enterprises/{enterprise}/Groups', {
enterprise: 'fabrikam'
});
console.log(JSON.stringify(resp.data));
## Detailed changes
* Modify `getResponseData` function in `src/fetch-wrapper.ts` to include a check for `application/scim+json` content type.
* Refactor content type check into a new `isJSONResponse` function.
* Add a test in `test/request.test.ts` to verify that response bodies with `application/scim+json` content type are correctly parsed as JSON.
---
For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/octokit/request.js?shareId=XXXX-XXXX-XXXX-XXXX).
timrogers
commented
Jan 16, 2025
wolfy1339
approved these changes
Jan 16, 2025
newkdr
added a commit
to newkdr/vscode-gitlens
that referenced
this pull request
Feb 13, 2025
 <h3>Snyk has created this PR to upgrade @octokit/request from 9.1.3 to 9.2.0.</h3> :information_source: Keep your dependencies up-to-date. This makes it easier to fix existing vulnerabilities and to more quickly identify and fix newly disclosed vulnerabilities when they affect your project. <hr/> - The recommended version is **2 versions** ahead of your current version. - The recommended version was released **a month ago**. <details> <summary><b>Release notes</b></summary> <br/> <details> <summary>Package name: <b>@octokit/request</b></summary> <ul> <li> <b>9.2.0</b> - <a href="https://redirect.github.com/octokit/request.js/releases/tag/v9.2.0">2025-01-16</a></br><h1><a href="https://redirect.github.com/octokit/request.js/compare/v9.1.4...v9.2.0">9.2.0</a> (2025-01-16)</h1> <h3>Features</h3> <ul> <li>correctly parse response bodies as JSON where the Content-Type is <code>application/scim+json</code> (<a href="https://redirect.github.com/octokit/request.js/issues/731" data-hovercard-type="pull_request" data-hovercard-url="/octokit/request.js/pull/731/hovercard">gitkraken#731</a>) (<a href="https://redirect.github.com/octokit/request.js/commit/00bf316136acf001344a5bacff906f1748e6c368">00bf316</a>)</li> </ul> </li> <li> <b>9.1.4</b> - <a href="https://redirect.github.com/octokit/request.js/releases/tag/v9.1.4">2024-12-29</a></br><h2><a href="https://redirect.github.com/octokit/request.js/compare/v9.1.3...v9.1.4">9.1.4</a> (2024-12-29)</h2> <h3>Bug Fixes</h3> <ul> <li><strong>deps:</strong> bump <code>@ octokit/types</code> to fix deno compat (<a href="https://redirect.github.com/octokit/request.js/issues/730" data-hovercard-type="pull_request" data-hovercard-url="/octokit/request.js/pull/730/hovercard">gitkraken#730</a>) (<a href="https://redirect.github.com/octokit/request.js/commit/324ffef20c305f9db4813b84518c40e2f3cd76b0">324ffef</a>)</li> </ul> </li> <li> <b>9.1.3</b> - <a href="https://redirect.github.com/octokit/request.js/releases/tag/v9.1.3">2024-07-14</a></br><h2><a href="https://redirect.github.com/octokit/request.js/compare/v9.1.2...v9.1.3">9.1.3</a> (2024-07-14)</h2> <h3>Bug Fixes</h3> <ul> <li>improve toErrorMessage (<a href="https://redirect.github.com/octokit/request.js/issues/714" data-hovercard-type="pull_request" data-hovercard-url="/octokit/request.js/pull/714/hovercard">gitkraken#714</a>) (<a href="https://redirect.github.com/octokit/request.js/commit/fcc5b25e044a2dd0fb8c1a76390eb6da9aa06d42">fcc5b25</a>)</li> </ul> </li> </ul> from <a href="https://redirect.github.com/octokit/request.js/releases">@octokit/request GitHub release notes</a> </details> </details> --- > [!IMPORTANT] > > - Check the changes in this PR to ensure they won't cause issues with your project. > - This PR was automatically created by Snyk using the credentials of a real user. --- **Note:** _You are seeing this because you or someone else with access to this repository has authorized Snyk to open upgrade PRs._ **For more information:** <img src="https://api.segment.io/v1/pixel/track?data=eyJ3cml0ZUtleSI6InJyWmxZcEdHY2RyTHZsb0lYd0dUcVg4WkFRTnNCOUEwIiwiYW5vbnltb3VzSWQiOiIwNTJmNjcxMi03NTY5LTQxZDAtODIwNi03NGVmMWRiMDQ2ZGEiLCJldmVudCI6IlBSIHZpZXdlZCIsInByb3BlcnRpZXMiOnsicHJJZCI6IjA1MmY2NzEyLTc1NjktNDFkMC04MjA2LTc0ZWYxZGIwNDZkYSJ9fQ==" width="0" height="0"/> > - 🧐 [View latest project report](https://app.snyk.io/org/newkdr/project/12a8a5f5-3e19-438c-8280-eb8f4ee06d17?utm_source=github&utm_medium=referral&page=upgrade-pr) > - 📜 [Customise PR templates](https://docs.snyk.io/scan-using-snyk/pull-requests/snyk-fix-pull-or-merge-requests/customize-pr-templates?utm_source=&utm_content=fix-pr-template) > - 🛠 [Adjust upgrade PR settings](https://app.snyk.io/org/newkdr/project/12a8a5f5-3e19-438c-8280-eb8f4ee06d17/settings/integration?utm_source=github&utm_medium=referral&page=upgrade-pr) > - 🔕 [Ignore this dependency or unsubscribe from future upgrade PRs](https://app.snyk.io/org/newkdr/project/12a8a5f5-3e19-438c-8280-eb8f4ee06d17/settings/integration?pkg=@octokit/request&utm_source=github&utm_medium=referral&page=upgrade-pr#auto-dep-upgrades) [//]: # 'snyk:metadata:{"customTemplate":{"variablesUsed":[],"fieldsUsed":[]},"dependencies":[{"name":"@octokit/request","from":"9.1.3","to":"9.2.0"}],"env":"prod","hasFixes":false,"isBreakingChange":false,"isMajorUpgrade":false,"issuesToFix":[],"prId":"052f6712-7569-41d0-8206-74ef1db046da","prPublicId":"052f6712-7569-41d0-8206-74ef1db046da","packageManager":"npm","priorityScoreList":[],"projectPublicId":"12a8a5f5-3e19-438c-8280-eb8f4ee06d17","projectUrl":"https://app.snyk.io/org/newkdr/project/12a8a5f5-3e19-438c-8280-eb8f4ee06d17?utm_source=github&utm_medium=referral&page=upgrade-pr","prType":"upgrade","templateFieldSources":{"branchName":"default","commitMessage":"default","description":"default","title":"default"},"templateVariants":[],"type":"auto","upgrade":[],"upgradeInfo":{"versionsDiff":2,"publishedDate":"2025-01-16T16:54:38.296Z"},"vulns":[]}'
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

GitHub has APIs that return
application/scim+jsonresponse bodies. Currently, these responses are not parsed as JSON, and instead, anArrayBufferis returned inresponse.data.This adds handling for
application/scim+jsonso they are parsed as JSON as normal.Minimal reproduction
Detailed changes
getResponseDatafunction insrc/fetch-wrapper.tsto include a check forapplication/scim+jsoncontent type.isJSONResponsefunction.test/request.test.tsto verify that response bodies withapplication/scim+jsoncontent type are correctly parsed as JSON.For more details, open the Copilot Workspace session.