Skip to content

Commit

Permalink
Merge tag 'v2.1.20' into develop
Browse files Browse the repository at this point in the history
v2.1.20
  • Loading branch information
ambroisemaupate committed Jun 23, 2023
2 parents d0a3fa4 + 6193a31 commit cdc8766
Show file tree
Hide file tree
Showing 13 changed files with 109 additions and 9 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
## [v2.1.20](https://github.com/roadiz/core-bundle-dev-app/compare/v2.1.19...v2.1.20) (2023-06-23)


### Features

* **Preview:** Added OpenAPI decorator to document `_preview` query param and JWT security ([449c9f9](https://github.com/roadiz/core-bundle-dev-app/commit/449c9f9fcdb2114e6c13804be696d558ac7efc49))


### Bug Fixes

* **Preview:** Check strict `_preview` param value (allowing `0`, `false` values to disable preview mode) ([70b60c9](https://github.com/roadiz/core-bundle-dev-app/commit/70b60c972ed13fa1819ef3611521e9a2f6fbf459))

## [v2.1.19](https://github.com/roadiz/core-bundle-dev-app/compare/v2.1.18...v2.1.19) (2023-06-23)


Expand Down
2 changes: 2 additions & 0 deletions lib/Documents/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ parameters:
- '#Property ([a-zA-Z\\\:\$]+) type mapping mismatch: property can contain ([a-zA-Z\\\&\>\<]+)Interface\>? but database expects ([a-zA-Z\\\&\>\<]+)#'
- '#type mapping mismatch: database can contain array\|bool\|float\|int\|JsonSerializable\|stdClass\|string\|null but property expects array\|null#'
- '#Doctrine\\ORM\\Mapping\\GeneratedValue constructor expects#'
- '#type mapping mismatch: property can contain Doctrine\\Common\\Collections\\Collection<int, [^\>]+> but database expects Doctrine\\Common\\Collections\\Collection&iterable<[^\>]+>#'
- '#should return Doctrine\\Common\\Collections\\Collection<int, [^\>]+Interface> but returns Doctrine\\Common\\Collections\\Collection<int, [^\>]+>#'
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
Expand Down
2 changes: 2 additions & 0 deletions lib/RoadizCompatBundle/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ parameters:
- '#Property ([a-zA-Z\\\:\$]+) type mapping mismatch: property can contain ([a-zA-Z\\\&\>\<]+)Interface\>? but database expects ([a-zA-Z\\\&\>\<]+)#'
- '#type mapping mismatch: database can contain array\|bool\|float\|int\|JsonSerializable\|stdClass\|string\|null but property expects array\|null#'
- '#Doctrine\\ORM\\Mapping\\GeneratedValue constructor expects#'
- '#type mapping mismatch: property can contain Doctrine\\Common\\Collections\\Collection<int, [^\>]+> but database expects Doctrine\\Common\\Collections\\Collection&iterable<[^\>]+>#'
- '#should return Doctrine\\Common\\Collections\\Collection<int, [^\>]+Interface> but returns Doctrine\\Common\\Collections\\Collection<int, [^\>]+>#'

reportUnmatchedIgnoredErrors: false
checkGenericClassInNonGenericObjectType: false
Expand Down
8 changes: 7 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.19'
roadiz_core.cms_version: '2.1.20'
roadiz_core.cms_version_prefix: 'main'
env(APP_NAMESPACE): "roadiz"
env(APP_VERSION): "0.1.0"
Expand Down Expand Up @@ -119,6 +119,12 @@ services:
public: true


RZ\Roadiz\CoreBundle\Api\OpenApi\PreviewDecorator:
decorates: 'api_platform.openapi.factory'
decoration_priority: 100
arguments: [ '@RZ\Roadiz\CoreBundle\Api\OpenApi\PreviewDecorator.inner' ]
autoconfigure: false

RZ\Roadiz\CoreBundle\Api\OpenApi\JwtDecorator:
decorates: 'api_platform.openapi.factory'
arguments: [ '@RZ\Roadiz\CoreBundle\Api\OpenApi\JwtDecorator.inner' ]
Expand Down
2 changes: 2 additions & 0 deletions lib/RoadizCoreBundle/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ parameters:
- '#Property ([a-zA-Z\\\:\$]+) type mapping mismatch: property can contain ([a-zA-Z\\\&\>\<]+)Interface\>? but database expects ([a-zA-Z\\\&\>\<]+)#'
- '#type mapping mismatch: database can contain array\|bool\|float\|int\|JsonSerializable\|stdClass\|string\|null but property expects array\|null#'
- '#Doctrine\\ORM\\Mapping\\GeneratedValue constructor expects#'
- '#type mapping mismatch: property can contain Doctrine\\Common\\Collections\\Collection<int, [^\>]+> but database expects Doctrine\\Common\\Collections\\Collection&iterable<[^\>]+>#'
- '#should return Doctrine\\Common\\Collections\\Collection<int, [^\>]+Interface> but returns Doctrine\\Common\\Collections\\Collection<int, [^\>]+>#'

reportUnmatchedIgnoredErrors: false
checkGenericClassInNonGenericObjectType: false
Expand Down
54 changes: 54 additions & 0 deletions lib/RoadizCoreBundle/src/Api/OpenApi/PreviewDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace RZ\Roadiz\CoreBundle\Api\OpenApi;

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

final class PreviewDecorator implements OpenApiFactoryInterface
{
private OpenApiFactoryInterface $decorated;

public function __construct(
OpenApiFactoryInterface $decorated
) {
$this->decorated = $decorated;
}

public function __invoke(array $context = []): OpenApi
{
$openApi = ($this->decorated)($context);
/** @var PathItem[] $paths */
$paths = $openApi->getPaths()->getPaths();
// For each GET path, add a new query parameter `_preview` to force preview mode
foreach ($paths as $path => $pathItem) {
$operation = $pathItem->getGet();
if (null !== $operation) {
$responses = $operation->getResponses();
$responses['401'] = new Model\Response(
description: 'Invalid JWT Token'
);

$newOperation = $operation->withParameters([
...$operation->getParameters(),
(new Model\Parameter(
'_preview',
'query',
'Enables preview mode (requires a valid bearer JWT token)',
false
))->withSchema(['type' => 'boolean'])->withExample('1')
])->withSecurity([
...$operation->getSecurity() ?? [],
['JWT' => []]
])->withResponses($responses);
$openApi->getPaths()->addPath($path, $pathItem->withGet($newOperation));
}
}

return $openApi;
}
}
22 changes: 15 additions & 7 deletions lib/RoadizCoreBundle/src/Api/OpenApi/WebResponseDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,25 @@ public function __construct(
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,
)])
$operation->withParameters([
// override completely parameters
new Model\Parameter(
'path',
'query',
'Resource path, or `/` for home page',
true,
),
(new Model\Parameter(
'_preview',
'query',
'Enables preview mode (requires a valid bearer JWT token)',
false
))->withSchema(['type' => 'boolean'])->withExample('1')
])
));

return $openApi;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,11 @@ public function onKernelRequest(RequestEvent $event): void
if (
$event->isMainRequest() &&
$request->query->has(static::QUERY_PARAM_NAME) &&
(bool) ($request->query->get(static::QUERY_PARAM_NAME, 0)) === true
\in_array(
$request->query->get(static::QUERY_PARAM_NAME, 0),
['true', true, '1', 1, 'on', 'yes', 'y'],
true
)
) {
$request->attributes->set('preview', true);
}
Expand Down
2 changes: 2 additions & 0 deletions lib/RoadizFontBundle/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ parameters:
- '#Property ([a-zA-Z\\\:\$]+) type mapping mismatch: property can contain ([a-zA-Z\\\&\>\<]+)Interface\>? but database expects ([a-zA-Z\\\&\>\<]+)#'
- '#type mapping mismatch: database can contain array\|bool\|float\|int\|JsonSerializable\|stdClass\|string\|null but property expects array\|null#'
- '#Doctrine\\ORM\\Mapping\\GeneratedValue constructor expects#'
- '#type mapping mismatch: property can contain Doctrine\\Common\\Collections\\Collection<int, [^\>]+> but database expects Doctrine\\Common\\Collections\\Collection&iterable<[^\>]+>#'
- '#should return Doctrine\\Common\\Collections\\Collection<int, [^\>]+Interface> but returns Doctrine\\Common\\Collections\\Collection<int, [^\>]+>#'

reportUnmatchedIgnoredErrors: false
checkGenericClassInNonGenericObjectType: false
Expand Down
2 changes: 2 additions & 0 deletions lib/RoadizRozierBundle/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ parameters:
- '#Property ([a-zA-Z\\\:\$]+) type mapping mismatch: property can contain ([a-zA-Z\\\&\>\<]+)Interface\>? but database expects ([a-zA-Z\\\&\>\<]+)#'
- '#type mapping mismatch: database can contain array\|bool\|float\|int\|JsonSerializable\|stdClass\|string\|null but property expects array\|null#'
- '#Doctrine\\ORM\\Mapping\\GeneratedValue constructor expects#'
- '#type mapping mismatch: property can contain Doctrine\\Common\\Collections\\Collection<int, [^\>]+> but database expects Doctrine\\Common\\Collections\\Collection&iterable<[^\>]+>#'
- '#should return Doctrine\\Common\\Collections\\Collection<int, [^\>]+Interface> but returns Doctrine\\Common\\Collections\\Collection<int, [^\>]+>#'

reportUnmatchedIgnoredErrors: false
checkGenericClassInNonGenericObjectType: false
Expand Down
2 changes: 2 additions & 0 deletions lib/RoadizUserBundle/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ parameters:
- '#Property ([a-zA-Z\\\:\$]+) type mapping mismatch: property can contain ([a-zA-Z\\\&\>\<]+)Interface\>? but database expects ([a-zA-Z\\\&\>\<]+)#'
- '#type mapping mismatch: database can contain array\|bool\|float\|int\|JsonSerializable\|stdClass\|string\|null but property expects array\|null#'
- '#Doctrine\\ORM\\Mapping\\GeneratedValue constructor expects#'
- '#type mapping mismatch: property can contain Doctrine\\Common\\Collections\\Collection<int, [^\>]+> but database expects Doctrine\\Common\\Collections\\Collection&iterable<[^\>]+>#'
- '#should return Doctrine\\Common\\Collections\\Collection<int, [^\>]+Interface> but returns Doctrine\\Common\\Collections\\Collection<int, [^\>]+>#'

reportUnmatchedIgnoredErrors: false
checkGenericClassInNonGenericObjectType: false
Expand Down
2 changes: 2 additions & 0 deletions lib/Rozier/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ parameters:
- '#Property ([a-zA-Z\\\:\$]+) type mapping mismatch: property can contain ([a-zA-Z\\\&\>\<]+)Interface\>? but database expects ([a-zA-Z\\\&\>\<]+)#'
- '#type mapping mismatch: database can contain array\|bool\|float\|int\|JsonSerializable\|stdClass\|string\|null but property expects array\|null#'
- '#Doctrine\\ORM\\Mapping\\GeneratedValue constructor expects#'
- '#type mapping mismatch: property can contain Doctrine\\Common\\Collections\\Collection<int, [^\>]+> but database expects Doctrine\\Common\\Collections\\Collection&iterable<[^\>]+>#'
- '#should return Doctrine\\Common\\Collections\\Collection<int, [^\>]+Interface> but returns Doctrine\\Common\\Collections\\Collection<int, [^\>]+>#'

reportUnmatchedIgnoredErrors: false
checkGenericClassInNonGenericObjectType: false
Expand Down
2 changes: 2 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ parameters:
- '#Property ([a-zA-Z\\\:\$]+) type mapping mismatch: property can contain ([a-zA-Z\\\&\>\<]+)Interface\>? but database expects ([a-zA-Z\\\&\>\<]+)#'
- '#type mapping mismatch: database can contain array\|bool\|float\|int\|JsonSerializable\|stdClass\|string\|null but property expects array\|null#'
- '#Doctrine\\ORM\\Mapping\\GeneratedValue constructor expects#'
- '#type mapping mismatch: property can contain Doctrine\\Common\\Collections\\Collection<int, [^\>]+> but database expects Doctrine\\Common\\Collections\\Collection&iterable<[^\>]+>#'
- '#should return Doctrine\\Common\\Collections\\Collection<int, [^\>]+Interface> but returns Doctrine\\Common\\Collections\\Collection<int, [^\>]+>#'

reportUnmatchedIgnoredErrors: false
checkGenericClassInNonGenericObjectType: false
Expand Down

0 comments on commit cdc8766

Please sign in to comment.