mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-02 23:59:26 +03:00
Provide default host to generated .json documentation (#1492)
* Add default host to the current request host to keep the same behaviour as js does * Add host to test case * Revert deleted code * Revert not needed update on expected result
This commit is contained in:
parent
0bd54ea99a
commit
253e71a46e
@ -48,10 +48,15 @@ final class DocumentationController
|
|||||||
}
|
}
|
||||||
|
|
||||||
$spec = $this->generatorLocator->get($area)->generate()->toArray();
|
$spec = $this->generatorLocator->get($area)->generate()->toArray();
|
||||||
|
|
||||||
if ('' !== $request->getBaseUrl()) {
|
if ('' !== $request->getBaseUrl()) {
|
||||||
$spec['basePath'] = $request->getBaseUrl();
|
$spec['basePath'] = $request->getBaseUrl();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (empty($spec['host'])) {
|
||||||
|
$spec['host'] = $request->getHost();
|
||||||
|
}
|
||||||
|
|
||||||
return new JsonResponse($spec);
|
return new JsonResponse($spec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -58,7 +58,7 @@ class SwaggerUiTest extends WebTestCase
|
|||||||
public function testJsonDocs()
|
public function testJsonDocs()
|
||||||
{
|
{
|
||||||
$client = self::createClient();
|
$client = self::createClient();
|
||||||
$crawler = $client->request('GET', '/app_dev.php/docs.json');
|
$client->request('GET', '/app_dev.php/docs.json');
|
||||||
|
|
||||||
$response = $client->getResponse();
|
$response = $client->getResponse();
|
||||||
$this->assertEquals(200, $response->getStatusCode());
|
$this->assertEquals(200, $response->getStatusCode());
|
||||||
@ -66,6 +66,7 @@ class SwaggerUiTest extends WebTestCase
|
|||||||
|
|
||||||
$expected = $this->getSwaggerDefinition()->toArray();
|
$expected = $this->getSwaggerDefinition()->toArray();
|
||||||
$expected['basePath'] = '/app_dev.php';
|
$expected['basePath'] = '/app_dev.php';
|
||||||
|
$expected['host'] = 'api.example.com';
|
||||||
|
|
||||||
$this->assertEquals($expected, json_decode($response->getContent(), true));
|
$this->assertEquals($expected, json_decode($response->getContent(), true));
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user