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