Browse Source

Fix parsing no content into null instead of 'null' (#911)

Oliver Nybroe 6 months ago
parent
commit
6837c03c08

+ 5 - 1
src/Attributes/Response.php

@@ -18,7 +18,11 @@ class Response
     {
         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,
         ];
     }

+ 5 - 0
tests/Strategies/Responses/UseResponseAttributesTest.php

@@ -73,6 +73,10 @@ class UseResponseAttributesTest extends BaseLaravelTest
                 'status' => 201,
                 'content' => json_encode(["all" => "good"]),
             ],
+            [
+                'status' => 404,
+                'content' => null,
+            ]
         ], $results);
     }
 
@@ -246,6 +250,7 @@ class ResponseAttributesTestController
 {
     #[Response(["all" => "good"], 200, "Success")]
     #[Response('{"all":"good"}', 201)]
+    #[Response(status: 404)]
     public function plainResponseAttributes()
     {