diff --git a/CHANGELOG.md b/CHANGELOG.md index f40b1aed..51131c93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,10 @@ +## [v2.1.19](https://github.com/roadiz/core-bundle-dev-app/compare/v2.1.18...v2.1.19) (2023-06-23) + + +### Bug Fixes + +* **OpenApi:** Fixed `getByPath` operation overlap with `get` by setting `id` request attribute and api_resource operation configuration ([54a378d](https://github.com/roadiz/core-bundle-dev-app/commit/54a378d151409ef6ec8fb7cfea6b9c74e5115d44)) + ## [v2.1.18](https://github.com/roadiz/core-bundle-dev-app/compare/v2.1.17...v2.1.18) (2023-06-23) diff --git a/config/api_resources/nsarticle.yml b/config/api_resources/nsarticle.yml index e5200f65..58176016 100644 --- a/config/api_resources/nsarticle.yml +++ b/config/api_resources/nsarticle.yml @@ -28,7 +28,11 @@ App\GeneratedEntity\NSArticle: - document_thumbnails - document_display_sources getByPath: - method: GET + method: 'GET' + path: '/web_response_by_path' + read: false + controller: RZ\Roadiz\CoreBundle\Api\Controller\GetWebResponseByPathController + pagination_enabled: false normalization_context: enable_max_depth: true groups: diff --git a/config/api_resources/nsoffer.yml b/config/api_resources/nsoffer.yml index 4c619976..bd2c37d2 100644 --- a/config/api_resources/nsoffer.yml +++ b/config/api_resources/nsoffer.yml @@ -28,7 +28,11 @@ App\GeneratedEntity\NSOffer: - document_thumbnails - document_display_sources getByPath: - method: GET + method: 'GET' + path: '/web_response_by_path' + read: false + controller: RZ\Roadiz\CoreBundle\Api\Controller\GetWebResponseByPathController + pagination_enabled: false normalization_context: enable_max_depth: true groups: diff --git a/config/api_resources/nspage.yml b/config/api_resources/nspage.yml index 345c691c..ec5231db 100644 --- a/config/api_resources/nspage.yml +++ b/config/api_resources/nspage.yml @@ -32,7 +32,11 @@ App\GeneratedEntity\NSPage: - nodes_sources_images - nodes_sources_boolean getByPath: - method: GET + method: 'GET' + path: '/web_response_by_path' + read: false + controller: RZ\Roadiz\CoreBundle\Api\Controller\GetWebResponseByPathController + pagination_enabled: false normalization_context: enable_max_depth: true groups: diff --git a/lib/RoadizCoreBundle/config/services.yaml b/lib/RoadizCoreBundle/config/services.yaml index e509c9a1..29eb5d69 100644 --- a/lib/RoadizCoreBundle/config/services.yaml +++ b/lib/RoadizCoreBundle/config/services.yaml @@ -1,6 +1,6 @@ --- parameters: - roadiz_core.cms_version: '2.1.18' + roadiz_core.cms_version: '2.1.19' roadiz_core.cms_version_prefix: 'main' env(APP_NAMESPACE): "roadiz" env(APP_VERSION): "0.1.0" @@ -124,6 +124,11 @@ services: arguments: [ '@RZ\Roadiz\CoreBundle\Api\OpenApi\JwtDecorator.inner' ] autoconfigure: false + RZ\Roadiz\CoreBundle\Api\OpenApi\WebResponseDecorator: + decorates: 'api_platform.openapi.factory' + arguments: [ '@RZ\Roadiz\CoreBundle\Api\OpenApi\WebResponseDecorator.inner' ] + autoconfigure: false + # # API Platform normalizers # diff --git a/lib/RoadizCoreBundle/src/Api/Controller/GetWebResponseByPathController.php b/lib/RoadizCoreBundle/src/Api/Controller/GetWebResponseByPathController.php index 9b0a9b80..a6513e47 100644 --- a/lib/RoadizCoreBundle/src/Api/Controller/GetWebResponseByPathController.php +++ b/lib/RoadizCoreBundle/src/Api/Controller/GetWebResponseByPathController.php @@ -54,7 +54,11 @@ public function __invoke(): ?WebResponseInterface $resource = $this->normalizeResourcePath( (string) $this->requestStack->getMainRequest()->query->get('path') ); + if (null === $resource) { + throw new ResourceNotFoundException('Resource not found'); + } $this->requestStack->getMainRequest()->attributes->set('data', $resource); + $this->requestStack->getMainRequest()->attributes->set('id', $resource->getId()); /* * Force API Platform to look for real resource configuration and serialization * context. You must define "itemOperations.getByPath" for your API resource configuration. diff --git a/lib/RoadizCoreBundle/src/Api/OpenApi/WebResponseDecorator.php b/lib/RoadizCoreBundle/src/Api/OpenApi/WebResponseDecorator.php new file mode 100644 index 00000000..c44d1c2f --- /dev/null +++ b/lib/RoadizCoreBundle/src/Api/OpenApi/WebResponseDecorator.php @@ -0,0 +1,39 @@ +decorated = $decorated; + } + + public function __invoke(array $context = []): OpenApi + { + $openApi = ($this->decorated)($context); + $schemas = $openApi->getComponents()->getSchemas(); + $pathItem = $openApi->getPaths()->getPath('/api/web_response_by_path'); + $operation = $pathItem->getGet(); + + $openApi->getPaths()->addPath('/api/web_response_by_path', $pathItem->withGet( + $operation->withParameters([new Model\Parameter( + 'path', + 'query', + 'Resource path, or `/` for home page', + true, + )]) + )); + + return $openApi; + } +} diff --git a/lib/RoadizCoreBundle/src/NodeType/ApiResourceGenerator.php b/lib/RoadizCoreBundle/src/NodeType/ApiResourceGenerator.php index 428b6eb5..f4766afb 100644 --- a/lib/RoadizCoreBundle/src/NodeType/ApiResourceGenerator.php +++ b/lib/RoadizCoreBundle/src/NodeType/ApiResourceGenerator.php @@ -138,6 +138,10 @@ protected function getItemOperations(NodeTypeInterface $nodeType): array if ($nodeType->isReachable()) { $operations['getByPath'] = [ 'method' => 'GET', + 'path' => '/web_response_by_path', + 'read' => 'false', + 'controller' => 'RZ\Roadiz\CoreBundle\Api\Controller\GetWebResponseByPathController', + 'pagination_enabled' => 'false', 'normalization_context' => [ 'enable_max_depth' => true, 'groups' => array_merge(array_values(array_filter(array_unique($groups))), [