Skip to content
Snippets Groups Projects
Commit ecec19b0 authored by Reiter, Christoph's avatar Reiter, Christoph :snake:
Browse files

Move swagger decorator/normalizer to core

parent cd659a17
No related branches found
No related tags found
No related merge requests found
......@@ -11,6 +11,7 @@ parameters:
- vendor/bin/.phpunit/phpunit-8-0/vendor/autoload.php
excludes_analyse:
- tests/bootstrap.php
- src/Swagger/DocumentationNormalizer.php
ignoreErrors:
- message: '#.*NodeDefinition::children.*#'
path: ./src/DependencyInjection
......
......@@ -11,6 +11,7 @@
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
<file name="src/Swagger/DocumentationNormalizer.php" />
</ignoreFiles>
</projectFiles>
</psalm>
......@@ -42,3 +42,40 @@ services:
autowire: true
autoconfigure: true
DBP\API\CoreBundle\Swagger\SwaggerDecorator:
decorates: 'api_platform.swagger.normalizer.api_gateway'
autowire: true
autoconfigure: false
DBP\API\CoreBundle\Swagger\DocumentationNormalizer:
decorates: 'api_platform.swagger.normalizer.documentation'
# arguments were taken from service definition of ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer
# from vendor/api-platform/core/src/Bridge/Symfony/Bundle/Resources/config/swagger.xml and translated to yaml
arguments:
- "@api_platform.metadata.resource.metadata_factory"
- "@api_platform.metadata.property.name_collection_factory"
- "@api_platform.metadata.property.metadata_factory"
- "@api_platform.json_schema.schema_factory"
- "@api_platform.json_schema.type_factory"
- "@api_platform.operation_path_resolver"
- null
- "@api_platform.filter_locator"
- null
- "%api_platform.oauth.enabled%"
- "%api_platform.oauth.type%"
- "%api_platform.oauth.flow%"
- "%api_platform.oauth.tokenUrl%"
- "%api_platform.oauth.authorizationUrl%"
- "%api_platform.oauth.scopes%"
- "%api_platform.swagger.api_keys%"
- "@api_platform.subresource_operation_factory"
- "%api_platform.collection.pagination.enabled%"
- "%api_platform.collection.pagination.page_parameter_name%"
- "%api_platform.collection.pagination.client_items_per_page%"
- "%api_platform.collection.pagination.items_per_page_parameter_name%"
- "%api_platform.formats%"
- "%api_platform.collection.pagination.client_enabled%"
- "%api_platform.collection.pagination.enabled_parameter_name%"
- "%api_platform.swagger.versions%"
autoconfigure: false
autowire: true
This diff is collapsed.
<?php
namespace DBP\API\CoreBundle\Swagger;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
/**
* Class SwaggerDecorator
* see: https://api-platform.com/docs/core/swagger/#overriding-the-openapi-specification
*
* @package App\Swagger
*/
final class SwaggerDecorator implements NormalizerInterface
{
private $decorated;
private $container;
public function __construct(NormalizerInterface $decorated, ContainerInterface $container)
{
$this->decorated = $decorated;
$this->container = $container;
}
public function normalize($object, $format = null, array $context = [])
{
$docs = $this->decorated->normalize($object, $format, $context);
$pathsToHide = [];
if ($this->container->hasParameter('dbp_api.paths_to_hide')) {
$pathsToHide = array_merge($pathsToHide, $this->container->getParameter('dbp_api.paths_to_hide'));
}
foreach ($pathsToHide as $path) {
unset($docs["paths"][$path]);
}
return $docs;
}
public function supportsNormalization($data, $format = null)
{
return $this->decorated->supportsNormalization($data, $format);
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment