From 89463c73ebab5733bb24391d5f44c0bcf5b3ac63 Mon Sep 17 00:00:00 2001 From: Chris Nizzardini Date: Mon, 5 Sep 2022 00:12:08 -0400 Subject: [PATCH] Docblock parsing of @link not working (#466) Resolves #464 --- src/Lib/Operation/OperationDocBlock.php | 4 -- .../Lib/Operation/OperationDocBlockTest.php | 65 +++++++++++-------- 2 files changed, 37 insertions(+), 32 deletions(-) diff --git a/src/Lib/Operation/OperationDocBlock.php b/src/Lib/Operation/OperationDocBlock.php index 2f457f2c..e9f547f8 100644 --- a/src/Lib/Operation/OperationDocBlock.php +++ b/src/Lib/Operation/OperationDocBlock.php @@ -62,10 +62,6 @@ private function comments(): void $this->operation->setDeprecated(true); } - if (!$this->doc->hasTag('see')) { - return; - } - $this->addExternalDocumentation(); } diff --git a/tests/TestCase/Lib/Operation/OperationDocBlockTest.php b/tests/TestCase/Lib/Operation/OperationDocBlockTest.php index 1883b0fb..831b2a60 100644 --- a/tests/TestCase/Lib/Operation/OperationDocBlockTest.php +++ b/tests/TestCase/Lib/Operation/OperationDocBlockTest.php @@ -10,6 +10,7 @@ use SwaggerBake\Lib\Configuration; use SwaggerBake\Lib\Model\ModelScanner; use SwaggerBake\Lib\OpenApi\Operation; +use SwaggerBake\Lib\OpenApi\OperationExternalDoc; use SwaggerBake\Lib\Operation\OperationDocBlock; use SwaggerBake\Lib\Route\RouteScanner; use SwaggerBake\Lib\Swagger; @@ -65,9 +66,10 @@ public function setUp(): void } /** + * @dataProvider dataProviderForExternalDocs * @throws InternalErrorException */ - public function test_external_documentation_tags(): void + public function test_external_documentation_tags(string $tag): void { $config = new Configuration($this->config, SWAGGER_BAKE_TEST_APP); @@ -75,67 +77,64 @@ public function test_external_documentation_tags(): void $cakeModels = new ModelScanner($cakeRoute, $config); $swagger = new Swagger($cakeModels, $config); - foreach (['see','link'] as $tag) { - $block = <<create($block); - $operation = (new OperationDocBlock($swagger, $config, $this->operation, $docBlock))->getOperation(); - $doc = $operation->getExternalDocs(); - - $this->assertEquals('CakePHP', $doc->getDescription()); - $this->assertEquals('https://www.cakephp.org', $doc->getUrl()); - } + $docBlock = DocBlockFactory::createInstance()->create($block); + $operation = (new OperationDocBlock($swagger, $config, $this->operation, $docBlock))->getOperation(); + $doc = $operation->getExternalDocs(); + $this->assertInstanceOf(OperationExternalDoc::class, $doc); + $this->assertEquals('CakePHP', $doc->getDescription()); + $this->assertEquals('https://www.cakephp.org', $doc->getUrl()); } /** + * @dataProvider dataProviderForExternalDocs * @throws InternalErrorException|\ReflectionException */ - public function test_external_documentation_tags_without_description(): void + public function test_external_documentation_tags_without_description(string $tag): void { $config = new Configuration($this->config, SWAGGER_BAKE_TEST_APP); $cakeRoute = new RouteScanner($this->router, $config); $cakeModels = new ModelScanner($cakeRoute, $config); $swagger = new Swagger($cakeModels, $config); - foreach (['see','link'] as $tag) { - $block = <<create($block); - $operation = (new OperationDocBlock($swagger, $config, $this->operation, $docBlock))->getOperation(); - $doc = $operation->getExternalDocs(); + $docBlock = DocBlockFactory::createInstance()->create($block); + $operation = (new OperationDocBlock($swagger, $config, $this->operation, $docBlock))->getOperation(); + $doc = $operation->getExternalDocs(); - $this->assertEquals('', $doc->getDescription()); - $this->assertEquals('https://www.cakephp.org', $doc->getUrl()); - } + $this->assertInstanceOf(OperationExternalDoc::class, $doc); + $this->assertEquals('', $doc->getDescription()); + $this->assertEquals('https://www.cakephp.org', $doc->getUrl()); } /** + * @dataProvider dataProviderForExternalDocs * @throws \ReflectionException */ - public function test_external_documentation_not_set_when_url_invalid(): void + public function test_external_documentation_not_set_when_url_invalid(string $tag): void { $config = new Configuration($this->config, SWAGGER_BAKE_TEST_APP); $cakeRoute = new RouteScanner($this->router, $config); $cakeModels = new ModelScanner($cakeRoute, $config); $swagger = new Swagger($cakeModels, $config); - foreach (['see','link'] as $tag) { - $block = <<create($block); - $operation = (new OperationDocBlock($swagger, $config, $this->operation, $docBlock))->getOperation(); - $this->assertNull($operation->getExternalDocs()); - } + $docBlock = DocBlockFactory::createInstance()->create($block); + $operation = (new OperationDocBlock($swagger, $config, $this->operation, $docBlock))->getOperation(); + $this->assertNull($operation->getExternalDocs()); } /** @@ -157,6 +156,8 @@ public function test_link_tag_takes_precedence_over_see_tag(): void $docBlock = DocBlockFactory::createInstance()->create($block); $operation = (new OperationDocBlock($swagger, $config, $this->operation, $docBlock))->getOperation(); $doc = $operation->getExternalDocs(); + + $this->assertInstanceOf(OperationExternalDoc::class, $doc); $this->assertEquals('yep', $doc->getDescription()); $this->assertEquals('https://duckduckgo.com', $doc->getUrl()); } @@ -182,4 +183,12 @@ public function test_deprecated_tag(): void $this->assertTrue($operation->isDeprecated()); } + + public function dataProviderForExternalDocs(): array + { + return [ + ['see'], + ['link'], + ]; + } } \ No newline at end of file