Skip to content

Commit

Permalink
Merge tag 'v2.1.19' into develop
Browse files Browse the repository at this point in the history
v2.1.19
  • Loading branch information
ambroisemaupate committed Jun 23, 2023
2 parents 19fc092 + 5bd821b commit d0a3fa4
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 4 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)


Expand Down
6 changes: 5 additions & 1 deletion config/api_resources/nsarticle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion config/api_resources/nsoffer.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 5 additions & 1 deletion config/api_resources/nspage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
7 changes: 6 additions & 1 deletion lib/RoadizCoreBundle/config/services.yaml
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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
#
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
39 changes: 39 additions & 0 deletions lib/RoadizCoreBundle/src/Api/OpenApi/WebResponseDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace RZ\Roadiz\CoreBundle\Api\OpenApi;

use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface;
use ApiPlatform\OpenApi\Model;
use ApiPlatform\OpenApi\OpenApi;

final class WebResponseDecorator implements OpenApiFactoryInterface
{
private OpenApiFactoryInterface $decorated;

public function __construct(
OpenApiFactoryInterface $decorated
) {
$this->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;
}
}
4 changes: 4 additions & 0 deletions lib/RoadizCoreBundle/src/NodeType/ApiResourceGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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))), [
Expand Down

0 comments on commit d0a3fa4

Please sign in to comment.