Repository navigation
fix: send an empty JSON object for operations without a body - #109
Merged
Merged
Conversation
runOperation() set "Content-Type: application/json" but sent no body
when $body was empty, e.g. for activate, merge, pause, resume, redeploy
and deactivate. Send "{}" instead, so the request is valid JSON as the
API spec requires. GET operations still send no body.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Note
Reviewed — No blocking findings · 🔵 2 minor points
🔍 Full review · 2 files reviewed
🔵 Minor points
src/Model/ApiResourceBase.php:307— The GET branch sets$encodedtonullwithout checking$body. Before this change,runOperation('x', 'GET', ['a' => 1])sent{"a":1}. Now the caller's parameters are dropped with no error or warning. The PR description only promises that GET requests with an empty body keep sending no body, but this rule also applies to GET requests that carry data. To keep the old behaviour, the GET check should only replace the empty case, e.g.$body ? json_encode($body) : (strtoupper($method) === 'GET' ? null : '{}'). Throwing when GET is given a body would also work.src/Model/ApiResourceBase.php:307— Only GET is exempt, so DELETE, HEAD and OPTIONS operations run throughrunOperation()now always get a{}body. HEAD and OPTIONS are generally expected to have no body, and DELETE with a body is handled differently by different servers and proxies. Some reject it. No current caller insrc/uses those methods withrunOperation()(delete()usessendRequest). Still,runOperation()is public, and an API user callingrunOperation('foo', 'DELETE')would now send a body they never asked for.
Verification
- Every bodyless caller (activate, merge, pause, resume, redeploy, deactivate, cancel, clear-build-cache, validate) uses POST, so each now sends
{}as intended. - The method comparison uses
strtoupper, so lowercase 'get' still sends no body, and the 'lowercase GET' test case covers this. - The new test builds a full resource with a
#operatelink, sooperationAvailablenever makes an extra refresh request andassertCount(1, $history)holds. Resultbuilt from an empty 200 response body works:send()returns[], andResult's constructor accepts that withMockApiResource::class.
The PR adds testRunOperationBody in tests/ResourceTest.php, a data-provider test (PHPUnit 11 attribute) covering POST with and without a body, PATCH, GET and lowercase GET. The ./vendor/bin/phpunit step in .github/workflows/ci.yml runs it. No test covers GET with a non-empty body or DELETE/HEAD, which are the two cases I flagged.
Review details
- Commit: 75e2cdd
- Model: claude-opus-5-5
Review 1 of 10 for this pull request · View the full run
Keep the body of GET operations that pass data, and send no body for other methods without one (e.g. DELETE), as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The operations that need a body are all POST requests. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
So update([]) sends a valid (empty) merge patch. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
runOperation()setsContent-Type: application/jsonbut sent no body when$bodywas empty (e.g.activate,merge,pause,resume,redeploy,deactivate, orupdate([])). The API spec requires a JSON request body for these operations, so this sends{}instead for POST and PATCH requests. Other methods are unchanged.🤖 Generated with Claude Code