@@ -422,7 +422,7 @@ class CreateBookPublication
422
422
public function __construct(
423
423
private BookPublishingHandler $bookPublishingHandler
424
424
) {}
425
-
425
+
426
426
#[Route(
427
427
path: '/books/{id}/publication',
428
428
name: 'book_post_publication',
@@ -620,34 +620,46 @@ class Weather
620
620
This way, we expose a route that will do… nothing. Note that the controller does not even need to exist.
621
621
622
622
It's almost done, we have just one final issue: our fake item operation is visible in the API docs.
623
- To remove it, we will need to [ decorate the Swagger documentation] ( swagger .md#overriding-the-openapi-specification) .
623
+ To remove it, we will need to [ decorate the Swagger documentation] ( openapi .md#overriding-the-openapi-specification) .
624
624
Then, remove the route from the decorator:
625
625
626
626
``` php
627
627
<?php
628
- // src/Swagger/SwaggerDecorator .php
628
+ // src/OpenApi/OpenApiFactory .php
629
629
630
- namespace App\Swagger ;
630
+ namespace App\OpenApi ;
631
631
632
- use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
632
+ use ApiPlatform\Core\OpenApi\Factory\OpenApiFactoryInterface;
633
+ use ApiPlatform\Core\OpenApi\OpenApi;
634
+ use ApiPlatform\Core\OpenApi\Model;
633
635
634
- final class SwaggerDecorator implements NormalizerInterface
636
+ final class OpenApiFactory implements OpenApiFactoryInterface
635
637
{
636
- public function __construct(
637
- private NormalizerInterface $decorated
638
- ) {}
638
+ private $decorated;
639
+
640
+ public function __construct(OpenApiFactoryInterface $decorated)
641
+ {
642
+ $this->decorated = $decorated;
643
+ }
639
644
640
- public function normalize($object, string $format = null, array $context = [])
645
+ public function __invoke( array $context = []): OpenApi
641
646
{
642
- $docs = $this->decorated->normalize($object, $format, $context);
647
+ $openApi = $this->decorated->__invoke( $context);
643
648
644
- // If a prefix is configured on API Platform's routes, it must appear here.
645
- unset($docs['paths']['/weathers/{id}']);
649
+ $paths = $openApi->getPaths()->getPaths();
646
650
647
- return $docs;
648
- }
651
+ $filteredPaths = new Model\Paths();
652
+ foreach ($paths as $path => $pathItem) {
653
+ // If a prefix is configured on API Platform's routes, it must appear here.
654
+ if ($path === '/weathers/{id}') {
655
+ continue;
656
+ }
657
+ $filteredPaths->addPath($path, $pathItem);
658
+ }
649
659
650
- // ...
660
+ return $openApi->withPaths($filteredPaths);
661
+ }
662
+ }
651
663
```
652
664
653
665
That's it: your route is gone!
0 commit comments