From cd32ae7e22653561ee00e4629887ac7b6ca4789b Mon Sep 17 00:00:00 2001 From: Bart Heyrman Date: Wed, 12 Mar 2025 12:23:09 +0100 Subject: [PATCH] Update operations: A required operation is no longer necessary. --- core/operations.md | 68 ++-------------------------------------------- 1 file changed, 2 insertions(+), 66 deletions(-) diff --git a/core/operations.md b/core/operations.md index 8e637c2d473..529fed04190 100644 --- a/core/operations.md +++ b/core/operations.md @@ -572,74 +572,10 @@ namespace App\Entity; use ApiPlatform\Metadata\ApiResource; -#[ApiResource] +#[ApiResource(operations: [])] class Weather { // ... ``` -This will expose the `Weather` model, but also all the default CRUD routes: `GET`, `PATCH`, `DELETE` and `POST`, which is nonsense in our context. -Since we are required to expose at least one route, let's expose just one: - -```php -decorated = $decorated; - } - - public function __invoke(array $context = []): OpenApi - { - $openApi = $this->decorated->__invoke($context); - - $paths = $openApi->getPaths()->getPaths(); - - $filteredPaths = new Model\Paths(); - foreach ($paths as $path => $pathItem) { - // If a prefix is configured on API Platform's routes, it must appear here. - if ($path === '/weathers/{id}') { - continue; - } - $filteredPaths->addPath($path, $pathItem); - } - - return $openApi->withPaths($filteredPaths); - } -} -``` - -That's it: your route is gone! +That's it!