From 955d989a18930431034427160f1cb698bf83e0c5 Mon Sep 17 00:00:00 2001 From: Giacomo92 Date: Mon, 20 Oct 2025 00:10:57 +0200 Subject: [PATCH 1/3] refactor: remove doctrine annotations because it is abandoned --- composer.json | 3 +- src/Generator.php | 5 + tests/Unit/GeneratorTest.php | 6 -- tests/Unit/RoutesTest.php | 3 +- .../L5SwaggerAnnotationsExampleClients.php | 27 +++--- .../L5SwaggerAnnotationsExampleInfo.php | 37 ++++---- .../L5SwaggerAnnotationsExampleProjects.php | 92 ++++++++++--------- .../L5SwaggerAnnotationsExampleSecurity.php | 18 ++-- ...waggerAnnotationsExampleSecurityScheme.php | 36 ++++---- .../L5SwaggerAnnotationsExampleServer.php | 21 ++--- .../L5SwaggerAnnotationsExampleTag.php | 45 +++++---- .../L5SwaggerAnnotationsExampleProducts.php | 25 ++--- 12 files changed, 163 insertions(+), 155 deletions(-) diff --git a/composer.json b/composer.json index 7ef88885..440c4850 100644 --- a/composer.json +++ b/composer.json @@ -37,8 +37,7 @@ "zircote/swagger-php": "^5.0.0", "swagger-api/swagger-ui": ">=5.18.3", "symfony/yaml": "^5.0 || ^6.0 || ^7.0", - "ext-json": "*", - "doctrine/annotations": "^1.0 || ^2.0" + "ext-json": "*" }, "require-dev": { "phpunit/phpunit": "^11.0", diff --git a/src/Generator.php b/src/Generator.php index d4fd26af..df072fe6 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -246,6 +246,11 @@ protected function setAnalyser(OpenApiGenerator $generator): void if (! empty($analyser)) { $generator->setAnalyser($analyser); + } else { + // Use AttributeAnnotationFactory for PHP 8.1+ native attributes + $generator->setAnalyser(new \OpenApi\Analysers\ReflectionAnalyser([ + new \OpenApi\Analysers\AttributeAnnotationFactory(), + ])); } } diff --git a/tests/Unit/GeneratorTest.php b/tests/Unit/GeneratorTest.php index a810a697..bf51cc8d 100644 --- a/tests/Unit/GeneratorTest.php +++ b/tests/Unit/GeneratorTest.php @@ -8,7 +8,6 @@ use L5Swagger\GeneratorFactory; use L5Swagger\L5SwaggerServiceProvider; use OpenApi\Analysers\AttributeAnnotationFactory; -use OpenApi\Analysers\DocBlockAnnotationFactory; use OpenApi\Analysers\ReflectionAnalyser; use OpenApi\OpenApiException; use OpenApi\Processors\CleanUnmerged; @@ -192,12 +191,7 @@ public function testCanGenerateWithScanOptions(): void $cfg['scanOptions'] = [ 'exclude' => [__DIR__.'/../storage/annotations/OpenApi/Clients'], - 'analyser' => new ReflectionAnalyser([ - new AttributeAnnotationFactory(), - new DocBlockAnnotationFactory(), - ]), 'open_api_spec_version' => '3.1.0', - 'processors' => [new CleanUnmerged], 'default_processors_configuration' => ['operationId' => ['hash' => false]], ]; diff --git a/tests/Unit/RoutesTest.php b/tests/Unit/RoutesTest.php index d212a231..19e62fed 100644 --- a/tests/Unit/RoutesTest.php +++ b/tests/Unit/RoutesTest.php @@ -218,8 +218,7 @@ public function testItHandleBadAssetRequest(): void public function testUserCanAccessOauth2Redirect(): void { $this->get(route('l5-swagger.default.oauth2_callback')) - ->assertSee('swaggerUIRedirectOauth2') - ->assertSee('oauth2.auth.code') + ->assertSee('oauth2-redirect.js') ->isOk(); } diff --git a/tests/storage/annotations/OpenApi/Clients/L5SwaggerAnnotationsExampleClients.php b/tests/storage/annotations/OpenApi/Clients/L5SwaggerAnnotationsExampleClients.php index ae8e1a71..d89ae544 100644 --- a/tests/storage/annotations/OpenApi/Clients/L5SwaggerAnnotationsExampleClients.php +++ b/tests/storage/annotations/OpenApi/Clients/L5SwaggerAnnotationsExampleClients.php @@ -2,23 +2,26 @@ namespace Tests\storage\annotations\OpenApi\Clients; +use OpenApi\Attributes as OA; + class L5SwaggerAnnotationsExampleClients { /** - * @OA\Get( - * path="/clients", - * operationId="getClientsList", - * tags={"Clients"}, - * summary="Get list of clients", - * description="Returns list of clients", - * @OA\Response( - * response=200, - * description="successful operation" - * ) - * ) - * * Returns list of clients */ + #[OA\Get( + path: "/clients", + operationId: "getClientsList", + tags: ["Clients"], + summary: "Get list of clients", + description: "Returns list of clients", + responses: [ + new OA\Response( + response: 200, + description: "successful operation" + ) + ] + )] public function getClientsList() { } diff --git a/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleInfo.php b/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleInfo.php index 5cc8f013..631dad0f 100644 --- a/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleInfo.php +++ b/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleInfo.php @@ -2,26 +2,25 @@ namespace Tests\storage\annotations\OpenApi; -/** - * @OA\Info( - * version="1.0.0", - * x={ - * "logo": { - * "url": "https://via.placeholder.com/190x90.png?text=L5-Swagger" - * } - * }, - * title="L5 OpenApi", - * description="L5 Swagger OpenApi description", - * @OA\Contact( - * email="darius@matulionis.lt" - * ), - * @OA\License( - * name="Apache 2.0", - * url="https://www.apache.org/licenses/LICENSE-2.0.html" - * ) - * ) - */ +use OpenApi\Attributes as OA; +#[OA\Info( + version: "1.0.0", + x: [ + "logo" => [ + "url" => "https://via.placeholder.com/190x90.png?text=L5-Swagger" + ] + ], + title: "L5 OpenApi", + description: "L5 Swagger OpenApi description", + contact: new OA\Contact( + email: "darius@matulionis.lt" + ), + license: new OA\License( + name: "Apache 2.0", + url: "https://www.apache.org/licenses/LICENSE-2.0.html" + ) +)] class L5SwaggerAnnotationsExampleInfo { } diff --git a/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleProjects.php b/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleProjects.php index a7f90b90..6d9bc7da 100644 --- a/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleProjects.php +++ b/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleProjects.php @@ -2,60 +2,66 @@ namespace Tests\storage\annotations\OpenApi; +use OpenApi\Attributes as OA; + class L5SwaggerAnnotationsExampleProjects { /** - * @OA\Get( - * path="/projects", - * operationId="getProjectsList", - * tags={"Projects"}, - * summary="Get list of projects", - * description="Returns list of projects", - * @OA\Response( - * response=200, - * description="successful operation" - * ), - * @OA\Response(response=400, description="Bad request"), - * security={ - * {"api_key_security_example": {}} - * } - * ) - * * Returns list of projects */ + #[OA\Get( + path: "/projects", + operationId: "getProjectsList", + tags: ["Projects"], + summary: "Get list of projects", + description: "Returns list of projects", + responses: [ + new OA\Response( + response: 200, + description: "successful operation" + ), + new OA\Response(response: 400, description: "Bad request") + ], + security: [ + ["api_key_security_example" => []] + ] + )] public function getProjectsList() { } /** - * @OA\Get( - * path="/projects/{id}", - * operationId="getProjectById", - * tags={"Projects"}, - * summary="Get project information", - * description="Returns project data", - * @OA\Parameter( - * name="id", - * description="Project id", - * required=true, - * in="path", - * @OA\Schema( - * type="integer" - * ) - * ), - * @OA\Response( - * response=200, - * description="successful operation" - * ), - * @OA\Response(response=400, description="Bad request"), - * @OA\Response(response=404, description="Resource Not Found"), - * security={ - * { - * "oauth2_security_example": {"write:projects", "read:projects"} - * } - * }, - * ) + * Get project information */ + #[OA\Get( + path: "/projects/{id}", + operationId: "getProjectById", + tags: ["Projects"], + summary: "Get project information", + description: "Returns project data", + parameters: [ + new OA\Parameter( + name: "id", + description: "Project id", + required: true, + in: "path", + schema: new OA\Schema(type: "integer") + ) + ], + responses: [ + new OA\Response( + response: 200, + description: "successful operation" + ), + new OA\Response(response: 400, description: "Bad request"), + new OA\Response(response: 404, description: "Resource Not Found") + ], + security: [ + [ + "oauth2_security_example" => ["write:projects", "read:projects"] + ] + ] + )] public function getProjectById() { } diff --git a/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleSecurity.php b/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleSecurity.php index 954c3997..2b683265 100644 --- a/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleSecurity.php +++ b/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleSecurity.php @@ -2,15 +2,15 @@ namespace Tests\storage\annotations\OpenApi; -/** - * @OA\OpenApi( - * security={ - * { - * "oauth2": {"read:oauth2"}, - * } - * } - * ) - */ +use OpenApi\Attributes as OA; + +#[OA\OpenApi( + security: [ + [ + "oauth2" => ["read:oauth2"] + ] + ] +)] class L5SwaggerAnnotationsExampleSecurity { } diff --git a/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleSecurityScheme.php b/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleSecurityScheme.php index 698037fc..b3b06c20 100644 --- a/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleSecurityScheme.php +++ b/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleSecurityScheme.php @@ -2,23 +2,25 @@ namespace Tests\storage\annotations\OpenApi; -/** - * @OA\SecurityScheme( - * type="oauth2", - * description="Use a global client_id / client_secret and your username / password combo to obtain a token", - * name="Password Based", - * in="header", - * scheme="https", - * securityScheme="Password Based", - * @OA\Flow( - * flow="password", - * authorizationUrl="/oauth/authorize", - * tokenUrl="/oauth/token", - * refreshUrl="/oauth/token/refresh", - * scopes={} - * ) - * ) - */ +use OpenApi\Attributes as OA; + +#[OA\SecurityScheme( + type: "oauth2", + description: "Use a global client_id / client_secret and your username / password combo to obtain a token", + name: "Password Based", + in: "header", + scheme: "https", + securityScheme: "Password Based", + flows: [ + new OA\Flow( + flow: "password", + authorizationUrl: "/oauth/authorize", + tokenUrl: "/oauth/token", + refreshUrl: "/oauth/token/refresh", + scopes: [] + ) + ] +)] class L5SwaggerAnnotationsExampleSecurityScheme { } diff --git a/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleServer.php b/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleServer.php index 08b3b05a..97b064d1 100644 --- a/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleServer.php +++ b/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleServer.php @@ -2,17 +2,16 @@ namespace Tests\storage\annotations\OpenApi; -/** - * @OA\Server( - * url=L5_SWAGGER_CONST_HOST, - * description="L5 Swagger OpenApi dynamic host server" - * ) - * - * @OA\Server( - * url="https://projects.dev/api/v1", - * description="L5 Swagger OpenApi Server" - * ) - */ +use OpenApi\Attributes as OA; + +#[OA\Server( + url: "http://my-default-host.com", + description: "L5 Swagger OpenApi dynamic host server" +)] +#[OA\Server( + url: "https://projects.dev/api/v1", + description: "L5 Swagger OpenApi Server" +)] class L5SwaggerAnnotationsExampleServer { } diff --git a/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleTag.php b/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleTag.php index 1c4d208e..4638c5b0 100644 --- a/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleTag.php +++ b/tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleTag.php @@ -2,29 +2,28 @@ namespace Tests\storage\annotations\OpenApi; -/** - * @OA\Tag( - * name="project", - * description="Everything about your Projects", - * @OA\ExternalDocumentation( - * description="Find out more", - * url="https://swagger.io" - * ) - * ) - * - * @OA\Tag( - * name="user", - * description="Operations about user", - * @OA\ExternalDocumentation( - * description="Find out more about", - * url="https://swagger.io" - * ) - * ) - * @OA\ExternalDocumentation( - * description="Find out more about Swagger and OpenApi", - * url="https://swagger.io" - * ) - */ +use OpenApi\Attributes as OA; + +#[OA\Tag( + name: "project", + description: "Everything about your Projects", + externalDocs: new OA\ExternalDocumentation( + description: "Find out more", + url: "https://swagger.io" + ) +)] +#[OA\Tag( + name: "user", + description: "Operations about user", + externalDocs: new OA\ExternalDocumentation( + description: "Find out more about", + url: "https://swagger.io" + ) +)] +#[OA\ExternalDocumentation( + description: "Find out more about Swagger and OpenApi", + url: "https://swagger.io" +)] class L5SwaggerAnnotationsExampleTag { } diff --git a/tests/storage/annotations/OpenApi/Products/L5SwaggerAnnotationsExampleProducts.php b/tests/storage/annotations/OpenApi/Products/L5SwaggerAnnotationsExampleProducts.php index 3da43f76..56f9c236 100644 --- a/tests/storage/annotations/OpenApi/Products/L5SwaggerAnnotationsExampleProducts.php +++ b/tests/storage/annotations/OpenApi/Products/L5SwaggerAnnotationsExampleProducts.php @@ -2,22 +2,25 @@ namespace Tests\storage\annotations\OpenApi\Products; +use OpenApi\Attributes as OA; + class L5SwaggerAnnotationsExampleProducts { /** - * @OA\Post( - * path="/products", - * tags={"Products"}, - * summary="Get list of products", - * description="Returns list of products", - * @OA\Response( - * response=200, - * description="successful operation" - * ) - * ) - * * Returns list of products */ + #[OA\Post( + path: "/products", + tags: ["Products"], + summary: "Get list of products", + description: "Returns list of products", + responses: [ + new OA\Response( + response: 200, + description: "successful operation" + ) + ] + )] public function getProductsList() { } From 7e350bef8ef650b1ff678e89434706e90c435c08 Mon Sep 17 00:00:00 2001 From: Giacomo92 Date: Mon, 20 Oct 2025 00:13:54 +0200 Subject: [PATCH 2/3] fix: ci Static Code Analysis --- src/Generator.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/Generator.php b/src/Generator.php index df072fe6..a3728f72 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -246,12 +246,13 @@ protected function setAnalyser(OpenApiGenerator $generator): void if (! empty($analyser)) { $generator->setAnalyser($analyser); - } else { - // Use AttributeAnnotationFactory for PHP 8.1+ native attributes - $generator->setAnalyser(new \OpenApi\Analysers\ReflectionAnalyser([ - new \OpenApi\Analysers\AttributeAnnotationFactory(), - ])); + return; } + + // Use AttributeAnnotationFactory for PHP 8.1+ native attributes + $generator->setAnalyser(new \OpenApi\Analysers\ReflectionAnalyser([ + new \OpenApi\Analysers\AttributeAnnotationFactory(), + ])); } /** From 5cb950e3a46e722a74e2526f28b48d2fb001c839 Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Sun, 19 Oct 2025 22:15:26 +0000 Subject: [PATCH 3/3] Apply fixes from StyleCI --- src/Generator.php | 1 + tests/Unit/GeneratorTest.php | 3 --- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Generator.php b/src/Generator.php index a3728f72..c2512228 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -246,6 +246,7 @@ protected function setAnalyser(OpenApiGenerator $generator): void if (! empty($analyser)) { $generator->setAnalyser($analyser); + return; } diff --git a/tests/Unit/GeneratorTest.php b/tests/Unit/GeneratorTest.php index bf51cc8d..fcee20c6 100644 --- a/tests/Unit/GeneratorTest.php +++ b/tests/Unit/GeneratorTest.php @@ -7,10 +7,7 @@ use L5Swagger\Generator; use L5Swagger\GeneratorFactory; use L5Swagger\L5SwaggerServiceProvider; -use OpenApi\Analysers\AttributeAnnotationFactory; -use OpenApi\Analysers\ReflectionAnalyser; use OpenApi\OpenApiException; -use OpenApi\Processors\CleanUnmerged; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\TestDox; use Symfony\Component\Yaml\Parser;