mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-03-11 18:16:13 +03:00
default documentation
This commit is contained in:
parent
6bce4e0a8a
commit
a9120e95bd
DependencyInjection
Tests
@ -40,6 +40,12 @@ final class Configuration implements ConfigurationInterface
|
||||
->thenInvalid('You must not use both `nelmio_api_doc.areas` and `nelmio_api_doc.routes` config options. Please update your config to only use `nelmio_api_doc.areas`.')
|
||||
->end()
|
||||
->children()
|
||||
->arrayNode('documentation')
|
||||
->useAttributeAsKey('key')
|
||||
->info('The documentation used as base')
|
||||
->example(['info' => ['title' => 'My App']])
|
||||
->prototype('variable')->end()
|
||||
->end()
|
||||
->arrayNode('areas')
|
||||
->info('Filter the routes that are documented')
|
||||
->defaultValue(['default' => ['path_patterns' => [], 'host_patterns' => [], 'documentation' => []]])
|
||||
@ -73,7 +79,8 @@ final class Configuration implements ConfigurationInterface
|
||||
->end()
|
||||
->arrayNode('documentation')
|
||||
->useAttributeAsKey('key')
|
||||
->info('The documentation used as base')
|
||||
->defaultValue([])
|
||||
->info('The documentation used for area')
|
||||
->example(['info' => ['title' => 'My App']])
|
||||
->prototype('variable')->end()
|
||||
->end()
|
||||
|
@ -105,15 +105,18 @@ final class NelmioApiDocExtension extends Extension implements PrependExtensionI
|
||||
])
|
||||
->addTag(sprintf('nelmio_api_doc.describer.%s', $area), ['priority' => -200]);
|
||||
|
||||
$container->register(sprintf('nelmio_api_doc.describers.config.%s', $area), ExternalDocDescriber::class)
|
||||
->setPublic(false)
|
||||
->setArguments([
|
||||
$config['areas'][$area]['documentation'],
|
||||
true,
|
||||
])
|
||||
->addTag(sprintf('nelmio_api_doc.describer.%s', $area), ['priority' => 1000]);
|
||||
if (isset($config['areas'][$area]['documentation'])) {
|
||||
$container->register(sprintf('nelmio_api_doc.describers.config.%s', $area), ExternalDocDescriber::class)
|
||||
->setPublic(false)
|
||||
->setArguments([
|
||||
$config['areas'][$area]['documentation'],
|
||||
true,
|
||||
])
|
||||
->addTag(sprintf('nelmio_api_doc.describer.%s', $area), ['priority' => 1000]);
|
||||
|
||||
$container->getDefinition(sprintf('nelmio_api_doc.describers.config.%s', $area))->replaceArgument(0, $config['areas'][$area]['documentation']);
|
||||
}
|
||||
|
||||
$container->getDefinition(sprintf('nelmio_api_doc.describers.config.%s', $area))->replaceArgument(0, $config['areas'][$area]['documentation']);
|
||||
}
|
||||
|
||||
$container->register('nelmio_api_doc.generator_locator')
|
||||
@ -162,6 +165,9 @@ final class NelmioApiDocExtension extends Extension implements PrependExtensionI
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
// Import the base configuration
|
||||
$container->getDefinition('nelmio_api_doc.describers.config')->replaceArgument(0, $config['documentation']);
|
||||
}
|
||||
|
||||
private function findNameAliases(array $names, string $area): array
|
||||
|
@ -92,52 +92,39 @@ class NelmioApiDocExtensionTest extends TestCase
|
||||
$extension = new NelmioApiDocExtension();
|
||||
$extension->load([
|
||||
[
|
||||
'areas' => [
|
||||
'default' => [
|
||||
'documentation' => [
|
||||
'info' => [
|
||||
'title' => 'API documentation',
|
||||
'description' => 'This is the api documentation, use it wisely',
|
||||
],
|
||||
],
|
||||
]
|
||||
]
|
||||
'documentation' => [
|
||||
'info' => [
|
||||
'title' => 'API documentation',
|
||||
'description' => 'This is the api documentation, use it wisely',
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'areas' => [
|
||||
'default' => [
|
||||
'documentation' => [
|
||||
'tags' => [
|
||||
[
|
||||
'name' => 'secured',
|
||||
'description' => 'Requires authentication',
|
||||
],
|
||||
[
|
||||
'name' => 'another',
|
||||
'description' => 'Another tag serving another purpose',
|
||||
],
|
||||
],
|
||||
'documentation' => [
|
||||
'tags' => [
|
||||
[
|
||||
'name' => 'secured',
|
||||
'description' => 'Requires authentication',
|
||||
],
|
||||
[
|
||||
'name' => 'another',
|
||||
'description' => 'Another tag serving another purpose',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
[
|
||||
'areas' => [
|
||||
'default' => [
|
||||
'documentation' => [
|
||||
'paths' => [
|
||||
'/api/v1/model' => [
|
||||
'get' => [
|
||||
'tags' => ['secured'],
|
||||
],
|
||||
],
|
||||
'documentation' => [
|
||||
'paths' => [
|
||||
'/api/v1/model' => [
|
||||
'get' => [
|
||||
'tags' => ['secured'],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
], $container);
|
||||
|
||||
$this->assertSame([
|
||||
'info' => [
|
||||
'title' => 'API documentation',
|
||||
@ -160,6 +147,6 @@ class NelmioApiDocExtensionTest extends TestCase
|
||||
],
|
||||
],
|
||||
],
|
||||
], $container->getDefinition('nelmio_api_doc.describers.config.default')->getArgument(0));
|
||||
], $container->getDefinition('nelmio_api_doc.describers.config')->getArgument(0));
|
||||
}
|
||||
}
|
||||
|
@ -59,7 +59,6 @@ class SwaggerUiTest extends WebTestCase
|
||||
$client = self::createClient();
|
||||
$crawler = $client->request('GET', '/app_dev.php/docs.json');
|
||||
|
||||
|
||||
$response = $client->getResponse();
|
||||
$this->assertEquals(200, $response->getStatusCode());
|
||||
$this->assertEquals('application/json', $response->headers->get('Content-Type'));
|
||||
|
@ -117,6 +117,23 @@ class TestKernel extends Kernel
|
||||
|
||||
// Filter routes
|
||||
$c->loadFromExtension('nelmio_api_doc', [
|
||||
'documentation' => [
|
||||
'info' => [
|
||||
'title' => 'My Test App',
|
||||
],
|
||||
'definitions' => [
|
||||
'Test' => [
|
||||
'type' => 'string',
|
||||
],
|
||||
],
|
||||
'parameters' => [
|
||||
'test' => [
|
||||
'name' => 'id',
|
||||
'in' => 'path',
|
||||
'required' => true,
|
||||
],
|
||||
],
|
||||
],
|
||||
'areas' => [
|
||||
'default' => [
|
||||
'path_patterns' => ['^/api(?!/admin)'],
|
||||
|
Loading…
x
Reference in New Issue
Block a user