Skip to content

Commit 42ec8f7

Browse files
committed
add swagger-php attributes support and supports symfony with version >= 6.0
1 parent 1704435 commit 42ec8f7

28 files changed

Lines changed: 743 additions & 247 deletions

File tree

.github/workflows/ci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Set up PHP
1919
uses: shivammathur/setup-php@v2
2020
with:
21-
php-version: '7.2'
21+
php-version: '8.1'
2222
coverage: 'none'
2323

2424
- name: Checkout code
@@ -76,4 +76,4 @@ jobs:
7676

7777
- name: Run tests
7878
continue-on-error: true
79-
run: vendor/bin/simple-phpunit
79+
run: vendor/bin/simple-phpunit tests

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ Version < 1.2 requires zircote/swagger-php 2.x which works with the OpenAPI Spec
1313
So tobion/openapi-symfony-routing can be used with both OpenAPI v2 and v3 and composer will select the compatible one for your dependencies.
1414
Route loading stays the same between those versions. You just need to update the annotations when migrating from OpenAPI v2 to v3.
1515

16+
Version >= 1.3 requires zircote/swagger-php 4.x which is compatible with the OpenAPI Specification version 3.0.1 and supports attributes. This package need php >= 8.1 for attributes support from zircote/swagger-php.
17+
1618
## Basic Usage
1719

1820
This library allows to (re-)use your OpenAPI documentation to configure the routing of your Symfony-based API.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"symfony/finder": "^4.4|^5.0|^6.0",
1717
"symfony/framework-bundle": "^4.4|^5.0|^6.0",
1818
"symfony/routing": "^4.4|^5.0|^6.0",
19-
"zircote/swagger-php": "^3.0.3"
19+
"zircote/swagger-php": "^3.0.3|^4.0"
2020
},
2121
"require-dev": {
2222
"symfony/phpunit-bridge": "^5.2|^6.0"

phpunit.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
>
1010
<testsuites>
1111
<testsuite name="Test Suite">
12-
<directory>tests/</directory>
12+
<directory>tests/Annotations</directory>
1313
</testsuite>
1414
</testsuites>
1515

src/OpenApiRouteLoader.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
namespace Tobion\OpenApiSymfonyRouting;
66

7+
use OpenApi\Analysers\AttributeAnnotationFactory;
8+
use OpenApi\Analysers\DocBlockAnnotationFactory;
9+
use OpenApi\Analysers\ReflectionAnalyser;
710
use OpenApi\Analysis;
811
use OpenApi\Annotations\OpenApi;
912
use OpenApi\Annotations\Operation;
@@ -86,12 +89,23 @@ private function createOpenApi(): OpenApi
8689
return \OpenApi\scan($this->finder);
8790
}
8891

89-
$processors = array_filter(Analysis::processors(), static function ($processor): bool {
90-
// remove OperationId processor which would hash the controller starting in 3.2.2 breaking the default route name logic
91-
return !$processor instanceof OperationId && !$processor instanceof DocBlockDescriptions;
92-
});
92+
if (method_exists(Analysis::class, 'processors')) {
93+
$processors = array_filter(Analysis::processors(), static function ($processor): bool {
94+
// remove OperationId processor which would hash the controller starting in 3.2.2 breaking the default route name logic
95+
return !$processor instanceof OperationId && !$processor instanceof DocBlockDescriptions;
96+
});
9397

94-
return (new Generator())->setProcessors($processors)->generate($this->finder);
98+
return (new Generator())->setProcessors($processors)->generate($this->finder);
99+
}
100+
101+
$analyser = new ReflectionAnalyser([
102+
new AttributeAnnotationFactory(),
103+
new DocBlockAnnotationFactory()]
104+
);
105+
106+
return (new Generator())
107+
->setAnalyser($analyser)
108+
->generate($this->finder);
95109
}
96110

97111
/**

tests/Fixtures/Basic/Controller.php renamed to tests/Annotations/Fixtures/Basic/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\Basic;
5+
namespace Tobion\OpenApiSymfonyRouting\Tests\Annotations\Fixtures\Basic;
66

77
use OpenApi\Annotations as OA;
88

tests/Fixtures/FormatSuffix/Controller.php renamed to tests/Annotations/Fixtures/FormatSuffix/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\FormatSuffix;
5+
namespace Tobion\OpenApiSymfonyRouting\Tests\Annotations\Fixtures\FormatSuffix;
66

77
use OpenApi\Annotations as OA;
88

tests/Fixtures/OperationId/Controller.php renamed to tests/Annotations/Fixtures/OperationId/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\OperationId;
5+
namespace Tobion\OpenApiSymfonyRouting\Tests\Annotations\Fixtures\OperationId;
66

77
use OpenApi\Annotations as OA;
88

tests/Fixtures/PathParameterPattern/Controller.php renamed to tests/Annotations/Fixtures/PathParameterPattern/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\PathParameterPattern;
5+
namespace Tobion\OpenApiSymfonyRouting\Tests\Annotations\Fixtures\PathParameterPattern;
66

77
use OpenApi\Annotations as OA;
88

tests/Fixtures/Priority/Controller.php renamed to tests/Annotations/Fixtures/Priority/Controller.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\Priority;
5+
namespace Tobion\OpenApiSymfonyRouting\Tests\Annotations\Fixtures\Priority;
66

77
use OpenApi\Annotations as OA;
88

0 commit comments

Comments
 (0)