Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to rename tag "Login Check" on swagger ui #1160

Open
SimonDevelop opened this issue Oct 1, 2023 · 5 comments
Open

How to rename tag "Login Check" on swagger ui #1160

SimonDevelop opened this issue Oct 1, 2023 · 5 comments

Comments

@SimonDevelop
Copy link

SimonDevelop commented Oct 1, 2023

Hi,
I can't find anything about naming the lexik Login Check tag on swagger ui.

Change this: image
To get this: image

@TheDjRider
Copy link

Hello @SimonDevelop,
Add or update this part of the code, in your controller -

#[OA\Tag(name: 'Auth')]

probably in your case is -

#[OA\Tag(name: 'Login Check')]

@SimonDevelop
Copy link
Author

This is the bundle controller, so how can you add an attribute if it's not accessible?

@Bryce-Colton
Copy link

Same question on my mind.
I use Api Platform 3 lexik integration with auto generated login route enpoint in swagger.
Nice feature, however it will be great to have the possibility to override the swagger without to do it manually.

@is-krzysztofk
Copy link

Hey,

You can use OpenApi Decorator for that https://api-platform.com/docs/core/openapi/

Important is to change priority that login_check_post is already added to schema.
so works something like.
#[AsDecorator('api_platform.openapi.factory', -25)]

@NeuralClone
Copy link

NeuralClone commented May 24, 2024

I realize this is several months after the fact, but I recently wanted to make this particular change and found this discussion. Here's a fully working solution.

<?php

declare(strict_types=1);

namespace App\ApiPlatform;

use ApiPlatform\OpenApi\Factory\OpenApiFactoryInterface;
use ApiPlatform\OpenApi\Model\Operation;
use ApiPlatform\OpenApi\Model\PathItem;
use ApiPlatform\OpenApi\OpenApi;
use Symfony\Component\DependencyInjection\Attribute\AsDecorator;
use Symfony\Component\DependencyInjection\ContainerInterface;

#[AsDecorator(
    decorates: 'api_platform.openapi.factory',
    priority: -25,
    onInvalid: ContainerInterface::IGNORE_ON_INVALID_REFERENCE,
)]
class OpenApiFactoryDecorator implements OpenApiFactoryInterface
{
    public function __construct(
        private readonly OpenApiFactoryInterface $decorated,
        private readonly string $loginCheck,
    ) {
    }

    /**
     * @param array<string, mixed> $context
     */
    public function __invoke(array $context = []): OpenApi
    {
        $openApi = ($this->decorated)($context);
        $authPath = $openApi->getPaths()->getPath($this->loginCheck);

        if ($authPath instanceof PathItem && $authPath->getPost() instanceof Operation) {
            $post = $authPath->getPost()->withTags(['Auth']);

            $openApi->getPaths()->addPath(
                $this->loginCheck,
                (new PathItem())->withPost($post),
            );
        }

        return $openApi;
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants