diff --git a/src/Processors/AugmentTags.php b/src/Processors/AugmentTags.php index 21eeb2c3..171b6387 100644 --- a/src/Processors/AugmentTags.php +++ b/src/Processors/AugmentTags.php @@ -34,6 +34,10 @@ public function __invoke(Analysis $analysis) $declaredTags[$tag->name] = $tag; } } + if ($declaredTags) { + // last one wins + $analysis->openapi->tags = array_values($declaredTags); + } if ($usedTagNames) { $declatedTagNames = array_keys($declaredTags); diff --git a/tests/Fixtures/SurplusTag.php b/tests/Fixtures/SurplusTag.php index 0ac32cc6..ad5d1203 100644 --- a/tests/Fixtures/SurplusTag.php +++ b/tests/Fixtures/SurplusTag.php @@ -14,11 +14,18 @@ description: 'test', version: '2.0.0' ), + tags: [ + // definding tag 'other' globally with nice description + new OAT\Tag('other', 'Other description'), + ] )] class SurplusTag { #[OAT\Get(path: '/world/', tags: ['tag world'], responses: [new OAT\Response(response: '200', description: 'success')])] #[OAT\Get(path: '/hello/', tags: ['tag hello'], responses: [new OAT\Response(response: '200', description: 'success')])] + #[OAT\Get(path: '/other/', tags: ['other'], responses: [new OAT\Response(response: '200', description: 'success')])] + // also definding tag 'other' with another description + #[OAT\Tag('other', 'Another description')] public function hello(): void { } diff --git a/tests/Processors/AugmentTagsTest.php b/tests/Processors/AugmentTagsTest.php index 059c3f9f..bdecf1a6 100644 --- a/tests/Processors/AugmentTagsTest.php +++ b/tests/Processors/AugmentTagsTest.php @@ -13,7 +13,7 @@ class AugmentTagsTest extends OpenApiTestCase /** * @requires PHP 8.1 */ - public function testAugmentTags(): void + public function testFilteredAugmentTags(): void { $this->skipLegacy(); @@ -25,4 +25,17 @@ public function testAugmentTags(): void $this->assertCount(1, $analysis->openapi->tags); } + + /** + * @requires PHP 8.1 + */ + public function testDedupedAugmentTags(): void + { + $this->skipLegacy(); + + $analysis = $this->analysisFromFixtures(['SurplusTag.php'], static::processors()); + + echo $analysis->openapi->toYaml(); + $this->assertCount(3, $analysis->openapi->tags, 'Expecting 3 unique tags'); + } }