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

Allow and support doctrine/annotations ^2.0 #1375

Merged
merged 1 commit into from
Jan 3, 2023
Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"require": {
"php": ">=7.2",
"ext-json": "*",
"doctrine/annotations": "^1.7",
"doctrine/annotations": "^1.7 || ^2.0",
"psr/log": "^1.1 || ^2.0 || ^3.0",
"symfony/deprecation-contracts": "^2 || ^3",
"symfony/finder": ">=2.2",
Expand Down
3 changes: 2 additions & 1 deletion src/Generator.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,14 @@ public function __construct(?LoggerInterface $logger = null)
$this->setNamespaces(self::DEFAULT_NAMESPACES);

// kinda config stack to stay BC...
// @deprecated Can be removed once doctrine/annotations 2.0 becomes mandatory
$this->configStack = new class() {
protected $generator;

public function push(Generator $generator): void
{
$this->generator = $generator;
if (class_exists(AnnotationRegistry::class, true)) {
if (class_exists(AnnotationRegistry::class, true) && method_exists(AnnotationRegistry::class, 'registerLoader')) {
// keeping track of &this->generator allows to 'disable' the loader after we are done;
// no unload, unfortunately :/
$gref = &$this->generator;
Expand Down
5 changes: 5 additions & 0 deletions tests/Analysers/DocBlockParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace OpenApi\Tests\Analysers;

use Doctrine\Common\Annotations\AnnotationRegistry;
use OpenApi\Tests\OpenApiTestCase;

class DocBlockParserTest extends OpenApiTestCase
Expand All @@ -23,6 +24,10 @@ public function testParseContents(): void

public function testDeprecatedAnnotationWarning(): void
{
if (!class_exists(AnnotationRegistry::class, true) || !method_exists(AnnotationRegistry::class, 'registerLoader')) {
$this->markTestSkipped('Not supported in doctrine/annotations v2');
}

$this->assertOpenApiLogEntryContains('The annotation @SWG\Definition() is deprecated.');
$this->annotationsFromDocBlockParser('@SWG\Definition()', self::SWG_ALIAS);
}
Expand Down