Skip to content

Commit

Permalink
Create security schema
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Feb 14, 2025
1 parent 6296a03 commit ba756b9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
9 changes: 2 additions & 7 deletions src/Describer/SecurityDescriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@

namespace Nelmio\ApiDocBundle\Describer;

use Nelmio\ApiDocBundle\OpenApiPhp\Util;
use OpenApi\Annotations as OA;
use OpenApi\Generator;

final class SecurityDescriber implements DescriberInterface
{
Expand All @@ -31,13 +31,8 @@ public function __construct(array $securitySchemes)

public function describe(OA\OpenApi $api): void
{
$securitySchemes = Generator::UNDEFINED !== $api->components && Generator::UNDEFINED !== $api->components->securitySchemes ? $api->components->securitySchemes : [];

foreach ($this->securitySchemes as $name => $securityScheme) {
$securitySchemes[] = new OA\SecurityScheme([
'securityScheme' => $name,
...$securitySchemes,
]);
Util::getSecuritySchema($api, $name, $securityScheme);
}
}
}
9 changes: 9 additions & 0 deletions src/OpenApiPhp/Util.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,15 @@ public static function getSchema(OA\OpenApi $api, string $schema): OA\Schema
return self::getIndexedCollectionItem($api->components, OA\Schema::class, $schema);
}

public static function getSecuritySchema(OA\OpenApi $api, string $name, array $properties = []): OA\SecurityScheme
{
if (!$api->components instanceof OA\Components) {
$api->components = new OA\Components(['_context' => self::createWeakContext($api->_context)]);
}

return self::getCollectionItem($api->components, OA\SecurityScheme::class, [...$properties, 'securityScheme' => $name]);
}

/**
* Return an existing Property object from $schema->properties[]
* having its member property set to $property.
Expand Down

0 comments on commit ba756b9

Please sign in to comment.