diff --git a/Annotation/ApiDoc.php b/Annotation/ApiDoc.php index 1fbba3f..b297a5e 100644 --- a/Annotation/ApiDoc.php +++ b/Annotation/ApiDoc.php @@ -478,8 +478,10 @@ class ApiDoc $this->host = $route->getHost() ? : null; //replace route placeholders - foreach ($route->getDefaults() as $key => $value) { - $this->host = str_replace('{' . $key . '}', $value, $this->host); + foreach ($route->getDefaults() as $key => $value) { + if (is_string($value)) { + $this->host = str_replace('{' . $key . '}', $value, $this->host); + } } } else { $this->host = null; diff --git a/Tests/Annotation/ApiDocTest.php b/Tests/Annotation/ApiDocTest.php index 551faa5..e52246c 100644 --- a/Tests/Annotation/ApiDocTest.php +++ b/Tests/Annotation/ApiDocTest.php @@ -13,6 +13,7 @@ namespace Nelmio\ApiDocBundle\Tests\Annotation; use Nelmio\ApiDocBundle\Annotation\ApiDoc; use Nelmio\ApiDocBundle\Tests\TestCase; +use Symfony\Component\Routing\Route; class ApiDocTest extends TestCase { @@ -373,4 +374,28 @@ class ApiDocTest extends TestCase $this->assertArrayHasKey(400, $map); $this->assertEquals($apiDoc->getOutput(), $map[200]); } + + public function testSetRoute() + { + $route = new Route( + '/path/{foo}', + [ + 'foo' => 'bar', + 'nested' => [ + 'key1' => 'value1', + 'key2' => 'value2', + ] + ], + [], + [], + '{foo}.awesome_host.com' + ); + + $apiDoc = new ApiDoc([]); + $apiDoc->setRoute($route); + + $this->assertSame($route, $apiDoc->getRoute()); + $this->assertEquals('bar.awesome_host.com', $apiDoc->getHost()); + $this->assertEquals('ANY', $apiDoc->getMethod()); + } }