diff --git a/src/OpenApi/Factory/OpenApiFactory.php b/src/OpenApi/Factory/OpenApiFactory.php index 84a779ccc9..f6290b532c 100644 --- a/src/OpenApi/Factory/OpenApiFactory.php +++ b/src/OpenApi/Factory/OpenApiFactory.php @@ -367,6 +367,13 @@ private function collectPaths(ApiResource $resource, ResourceMetadataCollection $openapiOperation = $openapiOperation->withParameters($openapiParameters); + if ($security = $operation->getSecurity()) { + $openapiOperation = $openapiOperation->withResponse(403, new Response(\sprintf( + 'Access forbidden: You must meet the following condition(s) to access this resource: %s.', + $security + ))); + } + $existingResponses = $openapiOperation?->getResponses() ?: []; $overrideResponses = $operation->getExtraProperties()[self::OVERRIDE_OPENAPI_RESPONSES] ?? $this->openApiOptions->getOverrideResponses(); if ($operation instanceof HttpOperation && null !== ($errors = $operation->getErrors())) {