diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 50550a3..7a90cb6 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -23,6 +23,12 @@ class Configuration implements ConfigurationInterface ->root('nelmio_api_doc') ->children() ->scalarNode('name')->defaultValue('API documentation')->end() + ->arrayNode('motd') + ->addDefaultsIfNotSet() + ->children() + ->scalarNode('template')->defaultValue('NelmioApiDocBundle::Components/motd.html.twig')->end() + ->end() + ->end() ->arrayNode('request_listener') ->beforeNormalization() ->ifTrue(function ($a) { return is_bool($a); }) diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php index 2718679..ce10263 100644 --- a/DependencyInjection/NelmioApiDocExtension.php +++ b/DependencyInjection/NelmioApiDocExtension.php @@ -28,6 +28,7 @@ class NelmioApiDocExtension extends Extension $configuration = new Configuration(); $config = $processor->processConfiguration($configuration, $configs); + $container->setParameter('nelmio_api_doc.motd.template', $config['motd']['template']); $container->setParameter('nelmio_api_doc.api_name', $config['name']); $container->setParameter('nelmio_api_doc.sandbox.enabled', $config['sandbox']['enabled']); $container->setParameter('nelmio_api_doc.sandbox.endpoint', $config['sandbox']['endpoint']); diff --git a/Formatter/HtmlFormatter.php b/Formatter/HtmlFormatter.php index 9d5449f..d4520fc 100644 --- a/Formatter/HtmlFormatter.php +++ b/Formatter/HtmlFormatter.php @@ -55,6 +55,11 @@ class HtmlFormatter extends AbstractFormatter */ private $authentication; + /** + * @var string + */ + private $motdTemplate; + /** * @param array $authentication */ @@ -119,6 +124,22 @@ class HtmlFormatter extends AbstractFormatter $this->defaultRequestFormat = $format; } + /** + * @param string $motdTemplate + */ + public function setMotdTemplate($motdTemplate) + { + $this->motdTemplate = $motdTemplate; + } + + /** + * @return string + */ + public function getMotdTemplate() + { + return $this->motdTemplate; + } + /** * {@inheritdoc} */ @@ -162,6 +183,7 @@ class HtmlFormatter extends AbstractFormatter 'date' => date(DATE_RFC822), 'css' => file_get_contents(__DIR__ . '/../Resources/public/css/screen.css'), 'js' => file_get_contents(__DIR__ . '/../Resources/public/js/all.js'), + 'motdTemplate' => $this->motdTemplate ); } } diff --git a/README.md b/README.md index 1e31c15..a93a2cb 100644 --- a/README.md +++ b/README.md @@ -227,6 +227,12 @@ input is used, so you can configure their priorities via container tags. Here's tags: - {name: nelmio_api_doc.extractor.parser, priority: 2} +You can also define your own motd content (above methods list). All you have to do is add to configuration: + + #app/config/config.yml + motd: + template: AcmeApiBundle::Components/motd.html.twig + ## Credits ## The design is heavily inspired by the [swagger-ui](https://github.com/wordnik/swagger-ui) project. diff --git a/Resources/config/formatters.xml b/Resources/config/formatters.xml index 98f29c5..8a21d80 100644 --- a/Resources/config/formatters.xml +++ b/Resources/config/formatters.xml @@ -28,6 +28,9 @@ + + %nelmio_api_doc.motd.template% + %nelmio_api_doc.api_name% diff --git a/Resources/public/css/screen.css b/Resources/public/css/screen.css index 1c0c6b9..4b8d53f 100644 --- a/Resources/public/css/screen.css +++ b/Resources/public/css/screen.css @@ -554,4 +554,8 @@ form .request-content { .icon { height: 12px; margin-left: 3px; +} + +.motd { + padding:20px; } \ No newline at end of file diff --git a/Resources/views/Components/motd.html.twig b/Resources/views/Components/motd.html.twig new file mode 100644 index 0000000..51b34e2 --- /dev/null +++ b/Resources/views/Components/motd.html.twig @@ -0,0 +1,3 @@ +
+ Documentation auto-generated on {{ date }} +
\ No newline at end of file diff --git a/Resources/views/layout.html.twig b/Resources/views/layout.html.twig index 967c105..6f2c29d 100644 --- a/Resources/views/layout.html.twig +++ b/Resources/views/layout.html.twig @@ -27,6 +27,7 @@
+ {% include motdTemplate %}