Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Arachnophobia mode #2247

Merged
merged 7 commits into from Oct 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php
Expand Up @@ -40,6 +40,7 @@ final class SwaggerUiAction
private $title;
private $description;
private $version;
private $showWebby;
private $formats = [];
private $oauthEnabled;
private $oauthClientId;
Expand All @@ -54,14 +55,15 @@ final class SwaggerUiAction
/**
* @throws InvalidArgumentException
*/
public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, NormalizerInterface $normalizer, \Twig_Environment $twig, UrlGeneratorInterface $urlGenerator, string $title = '', string $description = '', string $version = '', /* FormatsProviderInterface */ $formatsProvider = [], $oauthEnabled = false, $oauthClientId = '', $oauthClientSecret = '', $oauthType = '', $oauthFlow = '', $oauthTokenUrl = '', $oauthAuthorizationUrl = '', $oauthScopes = [])
public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, NormalizerInterface $normalizer, \Twig_Environment $twig, UrlGeneratorInterface $urlGenerator, string $title = '', string $description = '', string $version = '', /* FormatsProviderInterface */ $formatsProvider = [], $oauthEnabled = false, $oauthClientId = '', $oauthClientSecret = '', $oauthType = '', $oauthFlow = '', $oauthTokenUrl = '', $oauthAuthorizationUrl = '', $oauthScopes = [], bool $showWebby = true)
{
$this->resourceNameCollectionFactory = $resourceNameCollectionFactory;
$this->resourceMetadataFactory = $resourceMetadataFactory;
$this->normalizer = $normalizer;
$this->twig = $twig;
$this->urlGenerator = $urlGenerator;
$this->title = $title;
$this->showWebby = $showWebby;
$this->description = $description;
$this->version = $version;
$this->oauthEnabled = $oauthEnabled;
Expand Down Expand Up @@ -110,6 +112,7 @@ private function getContext(Request $request, Documentation $documentation): arr
'title' => $this->title,
'description' => $this->description,
'formats' => $this->formats,
'showWebby' => $this->showWebby,
];

$swaggerData = [
Expand Down
Expand Up @@ -156,6 +156,7 @@ private function handleConfig(ContainerBuilder $container, array $config, array
$container->setParameter('api_platform.title', $config['title']);
$container->setParameter('api_platform.description', $config['description']);
$container->setParameter('api_platform.version', $config['version']);
$container->setParameter('api_platform.show_webby', $config['show_webby']);
$container->setParameter('api_platform.exception_to_status', $config['exception_to_status']);
$container->setParameter('api_platform.formats', $formats);
$container->setParameter('api_platform.error_formats', $errorFormats);
Expand Down
Expand Up @@ -58,6 +58,7 @@ public function getConfigTreeBuilder()
->cannotBeEmpty()
->defaultValue('0.0.0')
->end()
->booleanNode('show_webby')->defaultTrue()->info('If true, show Webby on the documentation page')->end()
->scalarNode('default_operation_path_resolver')
->defaultValue('api_platform.operation_path_resolver.underscore')
->setDeprecated('The use of the `default_operation_path_resolver` has been deprecated in 2.1 and will be removed in 3.0. Use `path_segment_name_generator` instead.')
Expand Down
1 change: 1 addition & 0 deletions src/Bridge/Symfony/Bundle/Resources/config/swagger.xml
Expand Up @@ -69,6 +69,7 @@
<argument>%api_platform.oauth.tokenUrl%</argument>
<argument>%api_platform.oauth.authorizationUrl%</argument>
<argument>%api_platform.oauth.scopes%</argument>
<argument>%api_platform.show_webby%</argument>
</service>

</services>
Expand Down
36 changes: 21 additions & 15 deletions src/Bridge/Symfony/Bundle/Resources/public/init-swagger-ui.js
@@ -1,21 +1,7 @@
'use strict';

window.onload = () => {
const webby = document.getElementsByClassName('webby')[0];
const web = document.getElementsByClassName('web')[0];
webby.classList.add('calm');
web.classList.add('calm');
webby.addEventListener('click', () => {
if (webby.classList.contains('frighten')) {
return;
}
webby.classList.replace('calm', 'frighten');
web.classList.replace('calm', 'frighten');
setTimeout(() => {
webby.classList.replace('frighten', 'calm');
web.classList.replace('frighten', 'calm');
}, 10000);
});
manageWebbyDisplay();

const data = JSON.parse(document.getElementById('swagger-data').innerText);
const ui = SwaggerUIBundle({
Expand Down Expand Up @@ -145,3 +131,23 @@ window.onload = () => {
}
}
};

function manageWebbyDisplay() {
const webby = document.getElementsByClassName('webby')[0];
if (!webby) return;

const web = document.getElementsByClassName('web')[0];
webby.classList.add('calm');
web.classList.add('calm');
webby.addEventListener('click', () => {
if (webby.classList.contains('frighten')) {
return;
}
webby.classList.replace('calm', 'frighten');
web.classList.replace('calm', 'frighten');
setTimeout(() => {
webby.classList.replace('frighten', 'calm');
web.classList.replace('frighten', 'calm');
}, 10000);
});
}
Expand Up @@ -50,8 +50,10 @@
<a id="logo" href="https://api-platform.com"><img src="{{ asset('bundles/apiplatform/logo-header.svg') }}" alt="API Platform"></a>
</header>

<div class="web"><img src="{{ asset('bundles/apiplatform/web.png') }}"></div>
<div class="webby"><img src="{{ asset('bundles/apiplatform/webby.png') }}"></div>
{% if showWebby %}
<div class="web"><img src="{{ asset('bundles/apiplatform/web.png') }}"></div>
<div class="webby"><img src="{{ asset('bundles/apiplatform/webby.png') }}"></div>
{% endif %}

<div id="swagger-ui" class="api-platform"></div>

Expand Down
3 changes: 3 additions & 0 deletions tests/Bridge/Symfony/Bundle/Action/SwaggerUiActionTest.php
Expand Up @@ -75,6 +75,7 @@ public function getInvokeParameters()
'title' => '',
'description' => '',
'formats' => [],
'showWebby' => true,
'swagger_data' => [
'url' => '/url',
'spec' => self::SPEC,
Expand Down Expand Up @@ -102,6 +103,7 @@ public function getInvokeParameters()
'title' => '',
'description' => '',
'formats' => [],
'showWebby' => true,
'swagger_data' => [
'url' => '/url',
'spec' => self::SPEC,
Expand Down Expand Up @@ -148,6 +150,7 @@ public function testDoNotRunCurrentRequest(Request $request)
'title' => '',
'description' => '',
'formats' => [],
'showWebby' => true,
'swagger_data' => [
'url' => '/url',
'spec' => self::SPEC,
Expand Down
Expand Up @@ -458,6 +458,7 @@ private function getPartialContainerBuilderProphecy($test = false)
],
'api_platform.title' => 'title',
'api_platform.version' => 'version',
'api_platform.show_webby' => true,
'api_platform.allow_plain_identifiers' => false,
'api_platform.eager_loading.enabled' => Argument::type('bool'),
'api_platform.eager_loading.max_joins' => 30,
Expand Down
Expand Up @@ -58,6 +58,7 @@ public function testDefaultConfig()
'title' => 'title',
'description' => 'description',
'version' => '1.0.0',
'show_webby' => true,
'formats' => [
'jsonld' => ['mime_types' => ['application/ld+json']],
'json' => ['mime_types' => ['application/json']],
Expand Down