Skip to content

Commit c427799

Browse files
refactor: remove doctrine annotations because it is abandoned (#652)
* refactor: remove doctrine annotations because it is abandoned * fix: ci Static Code Analysis * Apply fixes from StyleCI --------- Co-authored-by: StyleCI Bot <bot@styleci.io>
1 parent f8e2030 commit c427799

12 files changed

Lines changed: 165 additions & 158 deletions

composer.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,7 @@
3737
"zircote/swagger-php": "^5.0.0",
3838
"swagger-api/swagger-ui": ">=5.18.3",
3939
"symfony/yaml": "^5.0 || ^6.0 || ^7.0",
40-
"ext-json": "*",
41-
"doctrine/annotations": "^1.0 || ^2.0"
40+
"ext-json": "*"
4241
},
4342
"require-dev": {
4443
"phpunit/phpunit": "^11.0",

src/Generator.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,14 @@ protected function setAnalyser(OpenApiGenerator $generator): void
246246

247247
if (! empty($analyser)) {
248248
$generator->setAnalyser($analyser);
249+
250+
return;
249251
}
252+
253+
// Use AttributeAnnotationFactory for PHP 8.1+ native attributes
254+
$generator->setAnalyser(new \OpenApi\Analysers\ReflectionAnalyser([
255+
new \OpenApi\Analysers\AttributeAnnotationFactory(),
256+
]));
250257
}
251258

252259
/**

tests/Unit/GeneratorTest.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@
77
use L5Swagger\Generator;
88
use L5Swagger\GeneratorFactory;
99
use L5Swagger\L5SwaggerServiceProvider;
10-
use OpenApi\Analysers\AttributeAnnotationFactory;
11-
use OpenApi\Analysers\DocBlockAnnotationFactory;
12-
use OpenApi\Analysers\ReflectionAnalyser;
1310
use OpenApi\OpenApiException;
14-
use OpenApi\Processors\CleanUnmerged;
1511
use PHPUnit\Framework\Attributes\CoversClass;
1612
use PHPUnit\Framework\Attributes\TestDox;
1713
use Symfony\Component\Yaml\Parser;
@@ -192,12 +188,7 @@ public function testCanGenerateWithScanOptions(): void
192188

193189
$cfg['scanOptions'] = [
194190
'exclude' => [__DIR__.'/../storage/annotations/OpenApi/Clients'],
195-
'analyser' => new ReflectionAnalyser([
196-
new AttributeAnnotationFactory(),
197-
new DocBlockAnnotationFactory(),
198-
]),
199191
'open_api_spec_version' => '3.1.0',
200-
'processors' => [new CleanUnmerged],
201192
'default_processors_configuration' => ['operationId' => ['hash' => false]],
202193
];
203194

tests/Unit/RoutesTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,7 @@ public function testItHandleBadAssetRequest(): void
218218
public function testUserCanAccessOauth2Redirect(): void
219219
{
220220
$this->get(route('l5-swagger.default.oauth2_callback'))
221-
->assertSee('swaggerUIRedirectOauth2')
222-
->assertSee('oauth2.auth.code')
221+
->assertSee('oauth2-redirect.js')
223222
->isOk();
224223
}
225224

tests/storage/annotations/OpenApi/Clients/L5SwaggerAnnotationsExampleClients.php

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,26 @@
22

33
namespace Tests\storage\annotations\OpenApi\Clients;
44

5+
use OpenApi\Attributes as OA;
6+
57
class L5SwaggerAnnotationsExampleClients
68
{
79
/**
8-
* @OA\Get(
9-
* path="/clients",
10-
* operationId="getClientsList",
11-
* tags={"Clients"},
12-
* summary="Get list of clients",
13-
* description="Returns list of clients",
14-
* @OA\Response(
15-
* response=200,
16-
* description="successful operation"
17-
* )
18-
* )
19-
*
2010
* Returns list of clients
2111
*/
12+
#[OA\Get(
13+
path: "/clients",
14+
operationId: "getClientsList",
15+
tags: ["Clients"],
16+
summary: "Get list of clients",
17+
description: "Returns list of clients",
18+
responses: [
19+
new OA\Response(
20+
response: 200,
21+
description: "successful operation"
22+
)
23+
]
24+
)]
2225
public function getClientsList()
2326
{
2427
}

tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleInfo.php

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,25 @@
22

33
namespace Tests\storage\annotations\OpenApi;
44

5-
/**
6-
* @OA\Info(
7-
* version="1.0.0",
8-
* x={
9-
* "logo": {
10-
* "url": "https://via.placeholder.com/190x90.png?text=L5-Swagger"
11-
* }
12-
* },
13-
* title="L5 OpenApi",
14-
* description="L5 Swagger OpenApi description",
15-
* @OA\Contact(
16-
* email="darius@matulionis.lt"
17-
* ),
18-
* @OA\License(
19-
* name="Apache 2.0",
20-
* url="https://www.apache.org/licenses/LICENSE-2.0.html"
21-
* )
22-
* )
23-
*/
5+
use OpenApi\Attributes as OA;
246

7+
#[OA\Info(
8+
version: "1.0.0",
9+
x: [
10+
"logo" => [
11+
"url" => "https://via.placeholder.com/190x90.png?text=L5-Swagger"
12+
]
13+
],
14+
title: "L5 OpenApi",
15+
description: "L5 Swagger OpenApi description",
16+
contact: new OA\Contact(
17+
email: "darius@matulionis.lt"
18+
),
19+
license: new OA\License(
20+
name: "Apache 2.0",
21+
url: "https://www.apache.org/licenses/LICENSE-2.0.html"
22+
)
23+
)]
2524
class L5SwaggerAnnotationsExampleInfo
2625
{
2726
}

tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleProjects.php

Lines changed: 49 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -2,60 +2,66 @@
22

33
namespace Tests\storage\annotations\OpenApi;
44

5+
use OpenApi\Attributes as OA;
6+
57
class L5SwaggerAnnotationsExampleProjects
68
{
79
/**
8-
* @OA\Get(
9-
* path="/projects",
10-
* operationId="getProjectsList",
11-
* tags={"Projects"},
12-
* summary="Get list of projects",
13-
* description="Returns list of projects",
14-
* @OA\Response(
15-
* response=200,
16-
* description="successful operation"
17-
* ),
18-
* @OA\Response(response=400, description="Bad request"),
19-
* security={
20-
* {"api_key_security_example": {}}
21-
* }
22-
* )
23-
*
2410
* Returns list of projects
2511
*/
12+
#[OA\Get(
13+
path: "/projects",
14+
operationId: "getProjectsList",
15+
tags: ["Projects"],
16+
summary: "Get list of projects",
17+
description: "Returns list of projects",
18+
responses: [
19+
new OA\Response(
20+
response: 200,
21+
description: "successful operation"
22+
),
23+
new OA\Response(response: 400, description: "Bad request")
24+
],
25+
security: [
26+
["api_key_security_example" => []]
27+
]
28+
)]
2629
public function getProjectsList()
2730
{
2831
}
2932

3033
/**
31-
* @OA\Get(
32-
* path="/projects/{id}",
33-
* operationId="getProjectById",
34-
* tags={"Projects"},
35-
* summary="Get project information",
36-
* description="Returns project data",
37-
* @OA\Parameter(
38-
* name="id",
39-
* description="Project id",
40-
* required=true,
41-
* in="path",
42-
* @OA\Schema(
43-
* type="integer"
44-
* )
45-
* ),
46-
* @OA\Response(
47-
* response=200,
48-
* description="successful operation"
49-
* ),
50-
* @OA\Response(response=400, description="Bad request"),
51-
* @OA\Response(response=404, description="Resource Not Found"),
52-
* security={
53-
* {
54-
* "oauth2_security_example": {"write:projects", "read:projects"}
55-
* }
56-
* },
57-
* )
34+
* Get project information
5835
*/
36+
#[OA\Get(
37+
path: "/projects/{id}",
38+
operationId: "getProjectById",
39+
tags: ["Projects"],
40+
summary: "Get project information",
41+
description: "Returns project data",
42+
parameters: [
43+
new OA\Parameter(
44+
name: "id",
45+
description: "Project id",
46+
required: true,
47+
in: "path",
48+
schema: new OA\Schema(type: "integer")
49+
)
50+
],
51+
responses: [
52+
new OA\Response(
53+
response: 200,
54+
description: "successful operation"
55+
),
56+
new OA\Response(response: 400, description: "Bad request"),
57+
new OA\Response(response: 404, description: "Resource Not Found")
58+
],
59+
security: [
60+
[
61+
"oauth2_security_example" => ["write:projects", "read:projects"]
62+
]
63+
]
64+
)]
5965
public function getProjectById()
6066
{
6167
}

tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleSecurity.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,15 @@
22

33
namespace Tests\storage\annotations\OpenApi;
44

5-
/**
6-
* @OA\OpenApi(
7-
* security={
8-
* {
9-
* "oauth2": {"read:oauth2"},
10-
* }
11-
* }
12-
* )
13-
*/
5+
use OpenApi\Attributes as OA;
6+
7+
#[OA\OpenApi(
8+
security: [
9+
[
10+
"oauth2" => ["read:oauth2"]
11+
]
12+
]
13+
)]
1414
class L5SwaggerAnnotationsExampleSecurity
1515
{
1616
}

tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleSecurityScheme.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,25 @@
22

33
namespace Tests\storage\annotations\OpenApi;
44

5-
/**
6-
* @OA\SecurityScheme(
7-
* type="oauth2",
8-
* description="Use a global client_id / client_secret and your username / password combo to obtain a token",
9-
* name="Password Based",
10-
* in="header",
11-
* scheme="https",
12-
* securityScheme="Password Based",
13-
* @OA\Flow(
14-
* flow="password",
15-
* authorizationUrl="/oauth/authorize",
16-
* tokenUrl="/oauth/token",
17-
* refreshUrl="/oauth/token/refresh",
18-
* scopes={}
19-
* )
20-
* )
21-
*/
5+
use OpenApi\Attributes as OA;
6+
7+
#[OA\SecurityScheme(
8+
type: "oauth2",
9+
description: "Use a global client_id / client_secret and your username / password combo to obtain a token",
10+
name: "Password Based",
11+
in: "header",
12+
scheme: "https",
13+
securityScheme: "Password Based",
14+
flows: [
15+
new OA\Flow(
16+
flow: "password",
17+
authorizationUrl: "/oauth/authorize",
18+
tokenUrl: "/oauth/token",
19+
refreshUrl: "/oauth/token/refresh",
20+
scopes: []
21+
)
22+
]
23+
)]
2224
class L5SwaggerAnnotationsExampleSecurityScheme
2325
{
2426
}

tests/storage/annotations/OpenApi/L5SwaggerAnnotationsExampleServer.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,16 @@
22

33
namespace Tests\storage\annotations\OpenApi;
44

5-
/**
6-
* @OA\Server(
7-
* url=L5_SWAGGER_CONST_HOST,
8-
* description="L5 Swagger OpenApi dynamic host server"
9-
* )
10-
*
11-
* @OA\Server(
12-
* url="https://projects.dev/api/v1",
13-
* description="L5 Swagger OpenApi Server"
14-
* )
15-
*/
5+
use OpenApi\Attributes as OA;
6+
7+
#[OA\Server(
8+
url: "http://my-default-host.com",
9+
description: "L5 Swagger OpenApi dynamic host server"
10+
)]
11+
#[OA\Server(
12+
url: "https://projects.dev/api/v1",
13+
description: "L5 Swagger OpenApi Server"
14+
)]
1615
class L5SwaggerAnnotationsExampleServer
1716
{
1817
}

0 commit comments

Comments
 (0)