diff --git a/src/ResponseLocation/JsonLocation.php b/src/ResponseLocation/JsonLocation.php index fa620417..6752d661 100644 --- a/src/ResponseLocation/JsonLocation.php +++ b/src/ResponseLocation/JsonLocation.php @@ -109,7 +109,7 @@ private function recurse(Parameter $param, $value) if ($properties = $param->getProperties()) { foreach ($properties as $property) { $key = $property->getWireName(); - if (isset($value[$key])) { + if (array_key_exists($key, $value)) { $result[$property->getName()] = $this->recurse( $property, $value[$key] diff --git a/tests/ResponseLocation/JsonLocationTest.php b/tests/ResponseLocation/JsonLocationTest.php index 6be87d65..b918673b 100644 --- a/tests/ResponseLocation/JsonLocationTest.php +++ b/tests/ResponseLocation/JsonLocationTest.php @@ -290,4 +290,64 @@ public function testVisitsNestedProperties($desc) $this->assertEquals($expected, $result); } + + public function testVisitsNullResponseProperties() + { + $hclient = new Client(); + + $hclient->getEmitter()->on('before', function (BeforeEvent $event) { + $json = [ + 'data' => [ + 'link' => null + ] + ]; + $response = new Response(200, [ + 'Content-Type' => 'application/json' + ], Stream::factory(json_encode($json))); + $event->intercept($response); + }); + + $description = new Description( + [ + 'operations' => [ + 'foo' => [ + 'uri' => 'http://httpbin.org', + 'httpMethod' => 'GET', + 'responseModel' => 'j' + ] + ], + 'models' => [ + 'j' => [ + 'type' => 'object', + 'location' => 'json', + 'properties' => [ + 'scalar' => ['type' => 'string'], + 'data' => [ + 'type' => 'object', + 'location' => 'json', + 'properties' => [ + 'link' => [ + 'name' => 'val', + 'type' => 'string', + 'location' => 'json' + ], + ], + 'additionalProperties' => false + ] + ] + ] + ] + ] + ); + $client = new GuzzleClient($hclient, $description); + $result = $client->foo(); + + $expected = [ + 'data' => [ + 'link' => null + ] + ]; + + $this->assertEquals($expected, $result); + } }