Skip to content

Commit

Permalink
fill security with all scopes
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Feb 14, 2025
1 parent 4a9ea3e commit 768562b
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/RouteDescriber/RouteAttributeDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,33 +64,34 @@ public function describe(OA\OpenApi $api, Route $route, \ReflectionMethod $refle
}
}

$isGrantedAttributes = array_filter(
$attributes,
static fn ($attribute): bool => $attribute instanceof IsGranted && is_string($attribute->attribute)
);

foreach ($this->getOperations($api, $route) as $operation) {
foreach ($attributes as $attribute) {
if (class_exists(IsGranted::class) && $attribute instanceof IsGranted) {
$this->IsGranted($attribute, $operation);
}
}
$this->isGranted($isGrantedAttributes, $operation);
}
}

private function IsGranted(IsGranted $isGranted, OA\Operation $operation): void
/**
* @param IsGranted[] $isGranted
*/
private function IsGranted(array $isGranted, OA\Operation $operation): void
{
if (!Generator::isDefault($operation->security)) {
return;
}

if (!is_string($isGranted->attribute)) {
return;
}

$operation->security = [];
foreach ($this->securitySchemes as $name => $securityScheme) {
if (!isset($operation->security[$securityScheme])) {
$operation->security[][$securityScheme] = [];
}

// $operation->security[][$securityScheme][] = [$isGranted->attribute];
$operation->security[0][$securityScheme] = array_merge($operation->security[0][$securityScheme], [$isGranted->attribute]);
$scopes = array_map(
static fn (IsGranted $attribute): string => $attribute->attribute,
$isGranted
);

foreach ($this->securitySchemes as $name => $securityScheme) {
$operation->security[] = [$name => [$scopes]];
}
}
}

0 comments on commit 768562b

Please sign in to comment.