Skip to content

Commit c901294

Browse files
Deuchnorddunglas
authored andcommitted
Arachnophobia mode (#2247)
* Added value to the configuration to make Webby disappear (woosh!) * Fixed unit tests * Fixed the BC break * Fixed indentation * Refactored Webby's animations * Refactored Webby's presence condition * Coding standard fix
1 parent 1f11969 commit c901294

File tree

9 files changed

+37
-18
lines changed

9 files changed

+37
-18
lines changed

src/Bridge/Symfony/Bundle/Action/SwaggerUiAction.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ final class SwaggerUiAction
4040
private $title;
4141
private $description;
4242
private $version;
43+
private $showWebby;
4344
private $formats = [];
4445
private $oauthEnabled;
4546
private $oauthClientId;
@@ -54,14 +55,15 @@ final class SwaggerUiAction
5455
/**
5556
* @throws InvalidArgumentException
5657
*/
57-
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 = [])
58+
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)
5859
{
5960
$this->resourceNameCollectionFactory = $resourceNameCollectionFactory;
6061
$this->resourceMetadataFactory = $resourceMetadataFactory;
6162
$this->normalizer = $normalizer;
6263
$this->twig = $twig;
6364
$this->urlGenerator = $urlGenerator;
6465
$this->title = $title;
66+
$this->showWebby = $showWebby;
6567
$this->description = $description;
6668
$this->version = $version;
6769
$this->oauthEnabled = $oauthEnabled;
@@ -110,6 +112,7 @@ private function getContext(Request $request, Documentation $documentation): arr
110112
'title' => $this->title,
111113
'description' => $this->description,
112114
'formats' => $this->formats,
115+
'showWebby' => $this->showWebby,
113116
];
114117

115118
$swaggerData = [

src/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,7 @@ private function handleConfig(ContainerBuilder $container, array $config, array
156156
$container->setParameter('api_platform.title', $config['title']);
157157
$container->setParameter('api_platform.description', $config['description']);
158158
$container->setParameter('api_platform.version', $config['version']);
159+
$container->setParameter('api_platform.show_webby', $config['show_webby']);
159160
$container->setParameter('api_platform.exception_to_status', $config['exception_to_status']);
160161
$container->setParameter('api_platform.formats', $formats);
161162
$container->setParameter('api_platform.error_formats', $errorFormats);

src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function getConfigTreeBuilder()
5858
->cannotBeEmpty()
5959
->defaultValue('0.0.0')
6060
->end()
61+
->booleanNode('show_webby')->defaultTrue()->info('If true, show Webby on the documentation page')->end()
6162
->scalarNode('default_operation_path_resolver')
6263
->defaultValue('api_platform.operation_path_resolver.underscore')
6364
->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.')

src/Bridge/Symfony/Bundle/Resources/config/swagger.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969
<argument>%api_platform.oauth.tokenUrl%</argument>
7070
<argument>%api_platform.oauth.authorizationUrl%</argument>
7171
<argument>%api_platform.oauth.scopes%</argument>
72+
<argument>%api_platform.show_webby%</argument>
7273
</service>
7374

7475
</services>

src/Bridge/Symfony/Bundle/Resources/public/init-swagger-ui.js

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,7 @@
11
'use strict';
22

33
window.onload = () => {
4-
const webby = document.getElementsByClassName('webby')[0];
5-
const web = document.getElementsByClassName('web')[0];
6-
webby.classList.add('calm');
7-
web.classList.add('calm');
8-
webby.addEventListener('click', () => {
9-
if (webby.classList.contains('frighten')) {
10-
return;
11-
}
12-
webby.classList.replace('calm', 'frighten');
13-
web.classList.replace('calm', 'frighten');
14-
setTimeout(() => {
15-
webby.classList.replace('frighten', 'calm');
16-
web.classList.replace('frighten', 'calm');
17-
}, 10000);
18-
});
4+
manageWebbyDisplay();
195

206
const data = JSON.parse(document.getElementById('swagger-data').innerText);
217
const ui = SwaggerUIBundle({
@@ -145,3 +131,23 @@ window.onload = () => {
145131
}
146132
}
147133
};
134+
135+
function manageWebbyDisplay() {
136+
const webby = document.getElementsByClassName('webby')[0];
137+
if (!webby) return;
138+
139+
const web = document.getElementsByClassName('web')[0];
140+
webby.classList.add('calm');
141+
web.classList.add('calm');
142+
webby.addEventListener('click', () => {
143+
if (webby.classList.contains('frighten')) {
144+
return;
145+
}
146+
webby.classList.replace('calm', 'frighten');
147+
web.classList.replace('calm', 'frighten');
148+
setTimeout(() => {
149+
webby.classList.replace('frighten', 'calm');
150+
web.classList.replace('frighten', 'calm');
151+
}, 10000);
152+
});
153+
}

src/Bridge/Symfony/Bundle/Resources/views/SwaggerUi/index.html.twig

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,10 @@
5050
<a id="logo" href="https://api-platform.com"><img src="{{ asset('bundles/apiplatform/logo-header.svg') }}" alt="API Platform"></a>
5151
</header>
5252

53-
<div class="web"><img src="{{ asset('bundles/apiplatform/web.png') }}"></div>
54-
<div class="webby"><img src="{{ asset('bundles/apiplatform/webby.png') }}"></div>
53+
{% if showWebby %}
54+
<div class="web"><img src="{{ asset('bundles/apiplatform/web.png') }}"></div>
55+
<div class="webby"><img src="{{ asset('bundles/apiplatform/webby.png') }}"></div>
56+
{% endif %}
5557

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

tests/Bridge/Symfony/Bundle/Action/SwaggerUiActionTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ public function getInvokeParameters()
7575
'title' => '',
7676
'description' => '',
7777
'formats' => [],
78+
'showWebby' => true,
7879
'swagger_data' => [
7980
'url' => '/url',
8081
'spec' => self::SPEC,
@@ -102,6 +103,7 @@ public function getInvokeParameters()
102103
'title' => '',
103104
'description' => '',
104105
'formats' => [],
106+
'showWebby' => true,
105107
'swagger_data' => [
106108
'url' => '/url',
107109
'spec' => self::SPEC,
@@ -148,6 +150,7 @@ public function testDoNotRunCurrentRequest(Request $request)
148150
'title' => '',
149151
'description' => '',
150152
'formats' => [],
153+
'showWebby' => true,
151154
'swagger_data' => [
152155
'url' => '/url',
153156
'spec' => self::SPEC,

tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ private function getPartialContainerBuilderProphecy($test = false)
458458
],
459459
'api_platform.title' => 'title',
460460
'api_platform.version' => 'version',
461+
'api_platform.show_webby' => true,
461462
'api_platform.allow_plain_identifiers' => false,
462463
'api_platform.eager_loading.enabled' => Argument::type('bool'),
463464
'api_platform.eager_loading.max_joins' => 30,

tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ public function testDefaultConfig()
5858
'title' => 'title',
5959
'description' => 'description',
6060
'version' => '1.0.0',
61+
'show_webby' => true,
6162
'formats' => [
6263
'jsonld' => ['mime_types' => ['application/ld+json']],
6364
'json' => ['mime_types' => ['application/json']],

0 commit comments

Comments
 (0)