Skip to content

Commit

Permalink
Fix an issue caused by #1007
Browse files Browse the repository at this point in the history
  • Loading branch information
GuilhemN committed Jun 22, 2017
1 parent 6776d78 commit 0bd45e6
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 58 deletions.
22 changes: 20 additions & 2 deletions DependencyInjection/NelmioApiDocExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,13 @@
use phpDocumentor\Reflection\DocBlockFactory;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Extension\PrependExtensionInterface;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
use Symfony\Component\HttpKernel\DependencyInjection\Extension;
use Symfony\Component\Routing\RouteCollection;
use Nelmio\ApiDocBundle\Routing\FilteredRouteCollectionBuilder;

final class NelmioApiDocExtension extends Extension implements PrependExtensionInterface
{
Expand All @@ -40,8 +44,22 @@ public function load(array $configs, ContainerBuilder $container)
$loader->load('services.xml');

// Filter routes
$routeCollectionBuilder = $container->getDefinition('nelmio_api_doc.filtered_route_collection_builder');
$routeCollectionBuilder->replaceArgument(0, $config['routes']['path_patterns']);
$routesDefinition = (new Definition(RouteCollection::class))
->setFactory([new Reference('router'), 'getRouteCollection']);

if (0 === count($config['routes']['path_patterns'])) {
$container->setDefinition('nelmio_api_doc.routes', $routesDefinition)
->setPublic(false);
} else {
$container->register('nelmio_api_doc.routes', RouteCollection::class)
->setPublic(false)
->setFactory([
(new Definition(FilteredRouteCollectionBuilder::class))
->addArgument($config['routes']['path_patterns']),
'filter']
)
->addArgument($routesDefinition);
}

// Import services needed for each library
$loader->load('swagger_php.xml');
Expand Down
15 changes: 1 addition & 14 deletions Resources/config/services.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,6 @@
<argument type="service" id="controller_name_converter" />
</service>

<service id="nelmio_api_doc.filtered_route_collection" class="Symfony\Component\Routing\RouteCollection" public="false">
<factory service="nelmio_api_doc.filtered_route_collection_builder" method="filter" />
<argument type="service">
<service class="Symfony\Component\Routing\RouteCollection">
<factory service="router" method="getRouteCollection" />
</service>
</argument>
</service>

<service id="nelmio_api_doc.filtered_route_collection_builder" class="Nelmio\ApiDocBundle\Routing\FilteredRouteCollectionBuilder" public="false">
<argument type="collection" /> <!-- Path patterns -->
</service>

<!-- Describers -->
<service id="nelmio_api_doc.describers.config" class="Nelmio\ApiDocBundle\Describer\ExternalDocDescriber" public="false">
<argument type="collection" />
Expand All @@ -42,7 +29,7 @@
</service>

<service id="nelmio_api_doc.describers.route" class="Nelmio\ApiDocBundle\Describer\RouteDescriber" public="false">
<argument type="service" id="nelmio_api_doc.filtered_route_collection" />
<argument type="service" id="nelmio_api_doc.routes" />
<argument type="service" id="nelmio_api_doc.controller_reflector" />
<argument type="collection" />

Expand Down
2 changes: 1 addition & 1 deletion Resources/config/swagger_php.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<services>
<service id="nelmio_api_doc.describers.swagger_php" class="Nelmio\ApiDocBundle\Describer\SwaggerPhpDescriber" public="false">
<argument type="service" id="nelmio_api_doc.filtered_route_collection" />
<argument type="service" id="nelmio_api_doc.routes" />
<argument type="service" id="nelmio_api_doc.controller_reflector" />
<argument type="service" id="annotation_reader" />

Expand Down
41 changes: 0 additions & 41 deletions Resources/public/init-swagger-ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,46 +21,5 @@ window.onload = () => {
layout: 'StandaloneLayout'
});

if (data.oauth.enabled) {
ui.initOAuth({
clientId: data.oauth.clientId,
clientSecret: data.oauth.clientSecret,
realm: data.oauth.type,
appName: data.spec.info.title,
scopeSeparator: ' ',
additionalQueryStringParams: {}
});
}

window.ui = ui;

if (!data.operationId) return;

const observer = new MutationObserver(function (mutations, self) {
const op = document.getElementById(`operations,${data.method}-${data.path},${data.shortName}`);
if (!op) return;

self.disconnect();

op.querySelector('.opblock-summary').click();
op.querySelector('.try-out__btn').click();

if (data.id) {
const inputId = op.querySelector('.parameters input[placeholder="id"]');
inputId.value = data.id;
inputId.dispatchEvent(new Event('input', { bubbles: true }));
}

for (let input of op.querySelectorAll('.parameters input')) {
if (input.placeholder in data.queryParameters) {
input.value = data.queryParameters[input.placeholder];
input.dispatchEvent(new Event('input', { bubbles: true }));
}
}

op.querySelector('.execute').click();
op.scrollIntoView();
});

observer.observe(document, {childList: true, subtree: true});
};

0 comments on commit 0bd45e6

Please sign in to comment.