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

OpenApi platform docs Response missing #372

Open
aarsla opened this issue Jan 10, 2024 · 4 comments
Open

OpenApi platform docs Response missing #372

aarsla opened this issue Jan 10, 2024 · 4 comments

Comments

@aarsla
Copy link

aarsla commented Jan 10, 2024

OpenApi docs for LexikJWTAuthenticationBundle's "Login Check" response schema is missing "refresh_token" attribute.

Screenshot 2024-01-10 at 03 53 12

How can I (decorate OpenApiFactory?) include it in docs response/example value and match the actual response body?

Screenshot 2024-01-10 at 03 56 40

@mbabker
Copy link
Contributor

mbabker commented Jan 10, 2024

Decorate the lexik_jwt_authentication.api_platform.openapi.factory service provided by the LexikJWTAuthenticationBundle to add it, or disable that bundle's API Platform integration and add the info you need with a service in your own app.

I don't actually use API Platform so no idea what is the best solution, but there is no hook point in the Lexik bundle's factory class to extend the login endpoint's response schema. It also seems like you'd need something in your app documenting the refresh endpoint since this bundle doesn't provide an integration for that, either.

@galliroberto
Copy link

galliroberto commented Sep 11, 2024

how to decorate it?

I set in service.yaml:

services:
    App\Documentation\LexikJWTAuthenticationSwagger:
        decorates: 'lexik_jwt_authentication.api_platform.openapi.factory'

And create the file:

final class LexikJWTAuthenticationSwagger implements OpenApiFactoryInterface
{
    public function __construct(private OpenApiFactory $openApiFactory)
    {
    }

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


        $openApi
            ->getPaths()
            ->getPath('/auth/token/request')->withPost(
                (new Operation())
                    ->withOperationId('login_check_post')
                    ->withTags(['Login Check'])
                    ->withResponses([
                        Response::HTTP_OK => [
                            'description' => 'User token created',
                            'content' => [
                                'application/json' => [
                                    'schema' => [
                                        'type' => 'object',
                                        'properties' => [
                                            'token' => [
                                                'readOnly' => true,
                                                'type' => 'string',
                                                'nullable' => false,
                                            ],
                                            'refresh_token' => [
                                                'readOnly' => true,
                                                'type' => 'string',
                                                'nullable' => false,
                                            ],
                                        ],
                                        'required' => ['token'],
                                    ],
                                ],
                            ],
                        ],
                    ])
                    ->withSummary('Creates a user token.')
                    ->withDescription('Creates a user token.')

            );

        return $openApi;
    }
}

I also tried:
$openApi = $this->openApiFactory->__invoke($context);

It doesn't work

@UrbiJr
Copy link

UrbiJr commented Sep 17, 2024

+1

1 similar comment
@mateusfmello
Copy link

+1

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