Skip to content

fix: send an empty JSON object for operations without a body - #109

Merged
pjcdawkins merged 4 commits into
3.xfrom
fix/empty-operation-body
Oct 22, 2026
Merged

pjcdawkins merged 4 commits into
3.xfrom
fix/empty-operation-body

Conversation

@pjcdawkins

@pjcdawkins pjcdawkins commented Oct 22, 2026 •

Copy link
Copy Markdown
Collaborator

runOperation() sets Content-Type: application/json but sent no body when $body was empty (e.g. activate, merge, pause, resume, redeploy, deactivate, or update([])). 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

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>

@upsun-dispatch upsun-dispatch Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note

Reviewed — No blocking findings · 🔵 2 minor points

🔍 Full review · 2 files reviewed

🔵 Minor points

  • src/Model/ApiResourceBase.php:307 — The GET branch sets $encoded to null without 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 through runOperation() 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 in src/ uses those methods with runOperation() (delete() uses sendRequest). Still, runOperation() is public, and an API user calling runOperation('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 #operate link, so operationAvailable never makes an extra refresh request and assertCount(1, $history) holds.
  • Result built from an empty 200 response body works: send() returns [], and Result's constructor accepts that with MockApiResource::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

pjcdawkins and others added 3 commits October 22, 2026 10:11
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>
@pjcdawkins
pjcdawkins merged commit 6d8f2de into 3.x Oct 22, 2026
2 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.

1 participant