Skip to content

Commit

Permalink
Fix parsing no content into null instead of 'null' (#911)
Browse files Browse the repository at this point in the history
  • Loading branch information
olivernybroe authored Nov 5, 2024
1 parent da667aa commit 6837c03
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Attributes/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ public function toArray()
{
return [
"status" => $this->status,
"content" => is_string($this->content) ? $this->content : json_encode($this->content, JSON_THROW_ON_ERROR),
"content" => match (true) {
is_null($this->content) => null,
is_string($this->content) => $this->content,
default => json_encode($this->content, JSON_THROW_ON_ERROR),
},
"description" => $this->description,
];
}
Expand Down
5 changes: 5 additions & 0 deletions tests/Strategies/Responses/UseResponseAttributesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ public function can_parse_plain_response_attributes()
'status' => 201,
'content' => json_encode(["all" => "good"]),
],
[
'status' => 404,
'content' => null,
]
], $results);
}

Expand Down Expand Up @@ -246,6 +250,7 @@ class ResponseAttributesTestController
{
#[Response(["all" => "good"], 200, "Success")]
#[Response('{"all":"good"}', 201)]
#[Response(status: 404)]
public function plainResponseAttributes()
{

Expand Down

0 comments on commit 6837c03

Please sign in to comment.