Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 7 additions & 0 deletions src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,14 @@ protected function setAnalyser(OpenApiGenerator $generator): void

if (! empty($analyser)) {
$generator->setAnalyser($analyser);

return;
}

// Use AttributeAnnotationFactory for PHP 8.1+ native attributes
$generator->setAnalyser(new \OpenApi\Analysers\ReflectionAnalyser([
new \OpenApi\Analysers\AttributeAnnotationFactory(),
]));
}

/**
Expand Down
9 changes: 0 additions & 9 deletions tests/Unit/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@
use L5Swagger\Generator;
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;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\TestDox;
use Symfony\Component\Yaml\Parser;
Expand Down Expand Up @@ -192,12 +188,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]],
];

Expand Down
3 changes: 1 addition & 2 deletions tests/Unit/RoutesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -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()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
}
Loading
Loading