Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add zircote/swagger-php attributes support #14

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ jobs:

- name: Run tests
continue-on-error: true
run: vendor/bin/simple-phpunit
run: vendor/bin/simple-phpunit tests
sonrac marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.phpunit.result.cache
composer.lock
vendor/
docker-compose.override.yml
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Version < 1.2 requires zircote/swagger-php 2.x which works with the OpenAPI Spec
So tobion/openapi-symfony-routing can be used with both OpenAPI v2 and v3 and composer will select the compatible one for your dependencies.
Route loading stays the same between those versions. You just need to update the annotations when migrating from OpenAPI v2 to v3.

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.

## Basic Usage

This library allows to (re-)use your OpenAPI documentation to configure the routing of your Symfony-based API.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"symfony/finder": "^4.4|^5.0|^6.0",
"symfony/framework-bundle": "^4.4|^5.0|^6.0",
"symfony/routing": "^4.4|^5.0|^6.0",
"zircote/swagger-php": "^3.0.3"
"zircote/swagger-php": "^3.0.3|^4.0"
sonrac marked this conversation as resolved.
Show resolved Hide resolved
},
"require-dev": {
"symfony/phpunit-bridge": "^5.2|^6.0"
Expand Down
20 changes: 20 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
php7:
image: php:7.2-fpm
user: "1000:1000"
working_dir: /var/www/html
volumes:
- ./:/var/www/html
php8.0:
image: php:8.0-fpm
user: "1000:1000"
working_dir: /var/www/html
volumes:
- ./:/var/www/html
php8.1:
image: php:8.1-fpm
working_dir: /var/www/html
user: "1000:1000"
volumes:
- ./:/var/www/html

2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
>
<testsuites>
<testsuite name="Test Suite">
<directory>tests/</directory>
<directory>tests/Annotations</directory>
sonrac marked this conversation as resolved.
Show resolved Hide resolved
</testsuite>
</testsuites>

Expand Down
24 changes: 19 additions & 5 deletions src/OpenApiRouteLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace Tobion\OpenApiSymfonyRouting;

use OpenApi\Analysers\AttributeAnnotationFactory;
use OpenApi\Analysers\DocBlockAnnotationFactory;
use OpenApi\Analysers\ReflectionAnalyser;
use OpenApi\Analysis;
use OpenApi\Annotations\OpenApi;
use OpenApi\Annotations\Operation;
Expand Down Expand Up @@ -86,12 +89,23 @@ private function createOpenApi(): OpenApi
return \OpenApi\scan($this->finder);
}

$processors = array_filter(Analysis::processors(), static function ($processor): bool {
// remove OperationId processor which would hash the controller starting in 3.2.2 breaking the default route name logic
return !$processor instanceof OperationId && !$processor instanceof DocBlockDescriptions;
});
if (method_exists(Analysis::class, 'processors')) {
$processors = array_filter(Analysis::processors(), static function ($processor): bool {
// remove OperationId processor which would hash the controller starting in 3.2.2 breaking the default route name logic
return !$processor instanceof OperationId && !$processor instanceof DocBlockDescriptions;
});

return (new Generator())->setProcessors($processors)->generate($this->finder);
return (new Generator())->setProcessors($processors)->generate($this->finder);
}

$analyser = new ReflectionAnalyser([
new AttributeAnnotationFactory(),
new DocBlockAnnotationFactory()]
);

return (new Generator())
->setAnalyser($analyser)
->generate($this->finder);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\Basic;
namespace Tobion\OpenApiSymfonyRouting\Tests\Annotations\Fixtures\Basic;

use OpenApi\Annotations as OA;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\FormatSuffix;
namespace Tobion\OpenApiSymfonyRouting\Tests\Annotations\Fixtures\FormatSuffix;

use OpenApi\Annotations as OA;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\OperationId;
namespace Tobion\OpenApiSymfonyRouting\Tests\Annotations\Fixtures\OperationId;

use OpenApi\Annotations as OA;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\PathParameterPattern;
namespace Tobion\OpenApiSymfonyRouting\Tests\Annotations\Fixtures\PathParameterPattern;

use OpenApi\Annotations as OA;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\Priority;
namespace Tobion\OpenApiSymfonyRouting\Tests\Annotations\Fixtures\Priority;

use OpenApi\Annotations as OA;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\SeveralClasses;
namespace Tobion\OpenApiSymfonyRouting\Tests\Annotations\Fixtures\SeveralClasses;

use OpenApi\Annotations as OA;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\SeveralClasses;
namespace Tobion\OpenApiSymfonyRouting\Tests\Annotations\Fixtures\SeveralClasses;

use OpenApi\Annotations as OA;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\SeveralClasses\SubNamespace;
namespace Tobion\OpenApiSymfonyRouting\Tests\Annotations\Fixtures\SeveralClasses\SubNamespace;

use OpenApi\Annotations as OA;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\SeveralHttpMethods;
namespace Tobion\OpenApiSymfonyRouting\Tests\Annotations\Fixtures\SeveralHttpMethods;

use OpenApi\Annotations as OA;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

namespace Tobion\OpenApiSymfonyRouting\Tests\Fixtures\SeveralRoutesOnOneAction;
namespace Tobion\OpenApiSymfonyRouting\Tests\Annotations\Fixtures\SeveralRoutesOnOneAction;

use OpenApi\Annotations as OA;

Expand Down
Loading