Skip to content

Commit d44efcc

Browse files
committed
fix: add array_key_exists checking in replaceNullValues
1 parent 2b00122 commit d44efcc

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

src/Services/SwaggerService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,7 @@ protected function getClassAnnotations($class): array
737737
protected function replaceNullValues($parameters, $types, &$example)
738738
{
739739
foreach ($parameters as $parameter => $value) {
740-
if (is_null($value) && in_array($parameter, $types)) {
740+
if (is_null($value) && array_key_exists($parameter, $types)) {
741741
$example[$parameter] = $this->getDefaultValueByType($types[$parameter]['type']);
742742
} elseif (is_array($value)) {
743743
$this->replaceNullValues($value, $types, $example[$parameter]);

tests/SwaggerServiceTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,8 @@ public function testAddDataPostRequest()
197197
$service = app(SwaggerService::class);
198198

199199
$request = $this->generateRequest('post', 'users', [
200-
'users' => [1,2]
200+
'users' => [1,2],
201+
'query' => null
201202
], [], [
202203
'authorization' => 'Bearer some_token'
203204
]);

tests/fixtures/SwaggerServiceTest/tmp_data_post_request.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,8 @@
7777
}
7878
},
7979
"example": {
80-
"users": [1,2]
80+
"users": [1,2],
81+
"query": null
8182
},
8283
"required": ["query"]
8384
}

0 commit comments

Comments
 (0)