Skip to content

Commit

Permalink
fix: responseFile convert empty object to array
Browse files Browse the repository at this point in the history
responseFile convert empty object to array due to `json_decode($content, true)`
Example
```json
{"foo":{}}
```
convert to
```json
{"foo":[]}
```
  • Loading branch information
deathkel committed Sep 15, 2021
1 parent 8085086 commit 50d71ff
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Extracting/Strategies/Responses/UseResponseFileTag.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ protected function getFileResponses(array $tags)
}
$status = $result[1] ?: 200;
$content = $result[2] ? file_get_contents($filePath, true) : '{}';
$json = ! empty($result[3]) ? str_replace("'", '"', $result[3]) : '{}';

if (empty($result[3])) {
return ['content' => $content, 'status' => (int) $status];
}

$json = str_replace("'", '"', $result[3]);
$merged = array_merge(json_decode($content, true), json_decode($json, true));

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

0 comments on commit 50d71ff

Please sign in to comment.