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

Not 403 response on openAPI #6872

Open
p-pichet opened this issue Dec 16, 2024 · 1 comment
Open

Not 403 response on openAPI #6872

p-pichet opened this issue Dec 16, 2024 · 1 comment

Comments

@p-pichet
Copy link

API Platform version(s) affected: 3.3.0

Description
On an apiResource, we set a security but this not appear on the swagger

How to reproduce

#[ApiResource(
    operations: [
        new GetCollection()],
    security: "is_granted('ROLE_ADMIN')"
)]
class Author
{
}

then on the documentation, i like to see a 403 response like the one i get if I don't have access
like this :
image

Possible Solution

Additional Context

@soyuka
Copy link
Member

soyuka commented Dec 16, 2024

PR welcome code is at

if (true === $overrideResponses && !$operation instanceof CollectionOperationInterface && 'POST' !== $operation->getMethod()) {
if (!isset($existingResponses[404])) {
$openapiOperation = $openapiOperation->withResponse(404, new Response('Resource not found'));
}
}
if (!$openapiOperation->getResponses()) {
$openapiOperation = $openapiOperation->withResponse('default', new Response('Unexpected error'));
}

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

No branches or pull requests

2 participants