Skip to content

Commit

Permalink
Add bearer access token in docs via decorator, disable webby
Browse files Browse the repository at this point in the history
  • Loading branch information
mattamon committed Mar 5, 2024
1 parent 3ac56d1 commit fd05d23
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 2 deletions.
8 changes: 7 additions & 1 deletion config/pimcore/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,10 @@ api_platform:
enable_docs: true
enable_entrypoint: false
enable_swagger_ui: false
enable_re_doc: false
enable_re_doc: false
show_webby: false
swagger:
api_keys:
access_token:
name: 'Authorization'
type: 'header'
6 changes: 5 additions & 1 deletion config/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,4 +96,8 @@ services:
Pimcore\Bundle\StudioApiBundle\Security\Voter\TokenVoter:
arguments: ['@request_stack']
tags:
- { name: security.voter }
- { name: security.voter }

#Decorators
Pimcore\Bundle\StudioApiBundle\ApiPlatform\OpenApiFactoryDecorator:
decorates: 'api_platform.openapi.factory'
42 changes: 42 additions & 0 deletions src/ApiPlatform/OpenApiFactoryDecorator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php
declare(strict_types=1);

/**
* Pimcore
*
* This source file is available under two different licenses:
* - GNU General Public License version 3 (GPLv3)
* - Pimcore Commercial License (PCL)
* Full copyright and license information is available in
* LICENSE.md which is distributed with this source code.
*
* @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
* @license http://www.pimcore.org/license GPLv3 and PCL
*/

namespace Pimcore\Bundle\StudioApiBundle\ApiPlatform;

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


final readonly class OpenApiFactoryDecorator implements OpenApiFactoryInterface
{
public function __construct(private OpenApiFactoryInterface $decorated)
{
}

public function __invoke(array $context = []): OpenApi
{
$openApi = $this->decorated->__invoke($context);

$securitySchemes = $openApi->getComponents()->getSecuritySchemes() ?: new \ArrayObject();

Check notice on line 34 in src/ApiPlatform/OpenApiFactoryDecorator.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Fully qualified name usage

Qualifier can be replaced with an import

Check notice on line 34 in src/ApiPlatform/OpenApiFactoryDecorator.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Fully qualified name usage

Qualifier can be replaced with an import
$securitySchemes['access_token'] = new SecurityScheme(

Check notice on line 35 in src/ApiPlatform/OpenApiFactoryDecorator.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Parameter/variable is not used

\[EA\] Parameter/variable is overridden, but is never used or appears outside of the scope.

Check notice on line 35 in src/ApiPlatform/OpenApiFactoryDecorator.php

View workflow job for this annotation

GitHub Actions / Qodana for PHP

Parameter/variable is not used

\[EA\] Parameter/variable is overridden, but is never used or appears outside of the scope.
type: 'http',
scheme: 'bearer',
);

return $openApi;
}
}

0 comments on commit fd05d23

Please sign in to comment.