78 lines
3.1 KiB
PHP
78 lines
3.1 KiB
PHP
<?php
|
|
|
|
namespace App\OpenApi;
|
|
|
|
use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface;
|
|
use ApiPlatform\OpenApi\OpenApi;
|
|
use ApiPlatform\OpenApi\Model;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
final readonly class OpenApiFactory implements OpenApiFactoryInterface
|
|
{
|
|
|
|
public function __construct(private OpenApiFactoryInterface $decorated)
|
|
{
|
|
}
|
|
|
|
public function __invoke(array $context = []): OpenApi
|
|
{
|
|
$openApi = $this->decorated->__invoke($context);
|
|
|
|
$this->addRefreshToken($openApi);
|
|
|
|
return $openApi;
|
|
}
|
|
|
|
private function addRefreshToken(OpenApi $openApi): void
|
|
{
|
|
$openApi
|
|
->getPaths()
|
|
->addPath( '/auth/refresh', (new Model\PathItem())->withPost(
|
|
(new Model\Operation('postRefreshToken'))
|
|
->withTags(['Login check'])
|
|
->withResponses([
|
|
Response::HTTP_OK => [
|
|
'description' => 'Refresh token',
|
|
'content' => [
|
|
'application/json' => [
|
|
'schema' => [
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'token' => [
|
|
'type' => 'string',
|
|
'readOnly' => true,
|
|
'nullable' => false,
|
|
],
|
|
'refreshToken' => [
|
|
'type' => 'string',
|
|
'readOnly' => true,
|
|
'nullable' => false,
|
|
]
|
|
],
|
|
'required' => ['token', 'refreshToken'],
|
|
],
|
|
],
|
|
],
|
|
],
|
|
])
|
|
->withSummary('Create refresh token')
|
|
->withRequestBody(
|
|
(new Model\RequestBody())
|
|
->withDescription('The refresh token data')
|
|
->withContent( new \ArrayObject([
|
|
'application/json' => new Model\MediaType(new \ArrayObject(new \ArrayObject([
|
|
'type' => 'object',
|
|
'properties' => [
|
|
'refreshToken' => [
|
|
'type' => 'string',
|
|
'nullable' => false,
|
|
],
|
|
],
|
|
'required' => ['refreshToken'],
|
|
])))
|
|
]))
|
|
->withRequired(true)
|
|
)
|
|
));
|
|
}
|
|
} |