Skip to content

Commit 42481b4

Browse files
committed
fix: responseFile convert empty object to array
responseFile convert empty object to array due to `json_decode($content, true)` Example ```json {"foo":{}} ``` convert to ```json {"foo":[]} ```
1 parent 8085086 commit 42481b4

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/Extracting/Strategies/Responses/UseResponseFileTag.php

+6-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ protected function getFileResponses(array $tags)
6262
}
6363
$status = $result[1] ?: 200;
6464
$content = $result[2] ? file_get_contents($filePath, true) : '{}';
65-
$json = ! empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}';
65+
66+
if (empty($result[3])) {
67+
return ['content' => $content, 'status' => (int) $status];
68+
}
69+
70+
$json = str_replace("'", '"', $result[3]);
6671
$merged = array_merge(json_decode($content, true), json_decode($json, true));
6772

6873
return ['content' => json_encode($merged), 'status' => (int) $status];

0 commit comments

Comments
 (0)