Skip to content

Commit

Permalink
Merge pull request #1015 from nelmio/fosrest
Browse files Browse the repository at this point in the history
Fix docs when using FOSRestBundle format listener
  • Loading branch information
GuilhemN authored Jun 22, 2017
2 parents aefdca9 + 91e8af5 commit 6776d78
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
6 changes: 5 additions & 1 deletion Controller/SwaggerUiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ public function __construct(ApiDocGenerator $apiDocGenerator, \Twig_Environment

public function __invoke()
{
return new Response($this->twig->render('@NelmioApiDoc/SwaggerUi/index.html.twig', ['swagger_data' => ['spec' => $this->apiDocGenerator->generate()->toArray()]]));
return new Response(
$this->twig->render('@NelmioApiDoc/SwaggerUi/index.html.twig', ['swagger_data' => ['spec' => $this->apiDocGenerator->generate()->toArray()]]),
Response::HTTP_OK,
['Content-Type' => 'text/html']
);
}
}
1 change: 1 addition & 0 deletions Tests/Functional/SwaggerUiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public function testSwaggerUi()

$response = $client->getResponse();
$this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('text/html; charset=UTF-8', $response->headers->get('Content-Type'));

$swaggerUiSpec = json_decode($crawler->filterXPath('//script[@id="swagger-data"]')->text(), true);
$appSpec = $client->getContainer()->get('nelmio_api_doc.generator')->generate()->toArray();
Expand Down
13 changes: 13 additions & 0 deletions Tests/Functional/TestKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
namespace Nelmio\ApiDocBundle\Tests\Functional;

use ApiPlatform\Core\Bridge\Symfony\Bundle\ApiPlatformBundle;
use FOS\RestBundle\FOSRestBundle;
use Nelmio\ApiDocBundle\NelmioApiDocBundle;
use Nelmio\ApiDocBundle\Tests\Functional\TestBundle;
use Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle;
Expand All @@ -38,6 +39,7 @@ public function registerBundles()
new SensioFrameworkExtraBundle(),
new ApiPlatformBundle(),
new NelmioApiDocBundle(),
new FOSRestBundle(),
new TestBundle(),
];
}
Expand Down Expand Up @@ -67,6 +69,17 @@ protected function configureContainer(ContainerBuilder $c, LoaderInterface $load
'serializer' => ['enable_annotations' => true],
]);

$c->loadFromExtension('fos_rest', [
'format_listener' => [
'rules' => [
[
'path' => '^/',
'fallback_format' => 'json',
]
],
],
]);

// Filter routes
$c->loadFromExtension('nelmio_api_doc', [
'documentation' => [
Expand Down

0 comments on commit 6776d78

Please sign in to comment.