Skip to content

Commit f0d65a6

Browse files
authored
Allow to disable default tag descriptions (#1860)
1 parent 46141c3 commit f0d65a6

File tree

2 files changed

+38
-3
lines changed

2 files changed

+38
-3
lines changed

src/Processors/AugmentTags.php

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@
1616
class AugmentTags
1717
{
1818
/** @var array<string> */
19-
protected array $whitelist = [];
19+
protected array $whitelist;
2020

21-
public function __construct(array $whitelist = [])
21+
protected bool $withDescription;
22+
23+
public function __construct(array $whitelist = [], bool $withDescription = true)
2224
{
2325
$this->whitelist = $whitelist;
26+
$this->withDescription = $withDescription;
2427
}
2528

2629
/**
@@ -33,6 +36,16 @@ public function setWhitelist(array $whitelist): AugmentTags
3336
return $this;
3437
}
3538

39+
/**
40+
* Enables/disables generation of default tag descriptions.
41+
*/
42+
public function setWithDescription(bool $withDescription): AugmentTags
43+
{
44+
$this->withDescription = $withDescription;
45+
46+
return $this;
47+
}
48+
3649
public function __invoke(Analysis $analysis): void
3750
{
3851
$operations = $analysis->getAnnotationsOfType(OA\Operation::class);
@@ -61,7 +74,12 @@ public function __invoke(Analysis $analysis): void
6174
$declatedTagNames = array_keys($declaredTags);
6275
foreach ($usedTagNames as $tagName) {
6376
if (!in_array($tagName, $declatedTagNames)) {
64-
$analysis->openapi->merge([new OA\Tag(['name' => $tagName, 'description' => $tagName])]);
77+
$analysis->openapi->merge([new OA\Tag([
78+
'name' => $tagName,
79+
'description' => $this->withDescription
80+
? $tagName
81+
: Generator::UNDEFINED,
82+
])]);
6583
}
6684
}
6785
}

tests/Processors/AugmentTagsTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
namespace OpenApi\Tests\Processors;
88

9+
use OpenApi\Generator;
910
use OpenApi\Tests\OpenApiTestCase;
1011

1112
class AugmentTagsTest extends OpenApiTestCase
@@ -56,4 +57,20 @@ public function testAllowUnusedTagsWildcard(): void
5657

5758
$this->assertCount(3, $analysis->openapi->tags, 'Expecting all tags to be preserved');
5859
}
60+
61+
public function testWithoutDescriptions(): void
62+
{
63+
$analysis = $this->analysisFromFixtures(
64+
['Processors/EntityControllerClass.php'],
65+
$this->processorPipeline(),
66+
null,
67+
[
68+
'augmentTags' => ['withDescription' => false],
69+
]
70+
);
71+
72+
$this->assertNotEmpty($analysis->openapi->tags);
73+
$firstTag = $analysis->openapi->tags[0];
74+
$this->assertEquals(Generator::UNDEFINED, $firstTag->description);
75+
}
5976
}

0 commit comments

Comments
 (0)