(feat): add utf-8 charset to response

`swagger-ui-bundle` is very sensible to encoding changes because of the
RegExp performed.

ensuring UTF-8 on the response prevents end-user config to break it.

the annotations already needs to be UTF-8 compatible to generate the
JSON, so it should not break users applications.
This commit is contained in:
Lucas dos Santos Abreu 2020-10-02 13:52:30 -03:00
parent 290df23dc0
commit b022f6b219
2 changed files with 4 additions and 1 deletions

View File

@ -65,10 +65,12 @@ final class SwaggerUiController
$spec['basePath'] = $request->getBaseUrl(); $spec['basePath'] = $request->getBaseUrl();
} }
return new Response( $response = new Response(
$this->twig->render('@NelmioApiDoc/SwaggerUi/index.html.twig', ['swagger_data' => ['spec' => $spec]]), $this->twig->render('@NelmioApiDoc/SwaggerUi/index.html.twig', ['swagger_data' => ['spec' => $spec]]),
Response::HTTP_OK, Response::HTTP_OK,
['Content-Type' => 'text/html'] ['Content-Type' => 'text/html']
); );
return $response->setCharset('UTF-8');
} }
} }

View File

@ -33,6 +33,7 @@ class SwaggerUiTest extends WebTestCase
$response = $this->client->getResponse(); $response = $this->client->getResponse();
$this->assertEquals(200, $response->getStatusCode()); $this->assertEquals(200, $response->getStatusCode());
$this->assertEquals('UTF-8', $response->getCharset());
$this->assertEquals('text/html; charset=UTF-8', $response->headers->get('Content-Type')); $this->assertEquals('text/html; charset=UTF-8', $response->headers->get('Content-Type'));
$expected = $this->getSwaggerDefinition()->toArray(); $expected = $this->getSwaggerDefinition()->toArray();