diff --git a/Examples/swagger-spec/petstore/petstore.yaml b/Examples/swagger-spec/petstore/petstore.yaml index 845dd2dd..efefad4b 100644 --- a/Examples/swagger-spec/petstore/petstore.yaml +++ b/Examples/swagger-spec/petstore/petstore.yaml @@ -93,3 +93,13 @@ components: tag: type: string type: object +tags: + - + name: pets + description: pets + - + name: pets + description: pets + - + name: pets + description: pets diff --git a/Examples/using-links-php81/using-links-php81.yaml b/Examples/using-links-php81/using-links-php81.yaml index 9279d816..d2a2d02e 100644 --- a/Examples/using-links-php81/using-links-php81.yaml +++ b/Examples/using-links-php81/using-links-php81.yaml @@ -240,3 +240,7 @@ components: username: '$response.body#/author/username' slug: '$response.body#/repository/slug' pid: '$response.body#/id' +tags: + - + name: Users + description: Users diff --git a/Examples/using-refs/using-refs.yaml b/Examples/using-refs/using-refs.yaml index 5481817a..cf0830e2 100644 --- a/Examples/using-refs/using-refs.yaml +++ b/Examples/using-refs/using-refs.yaml @@ -96,3 +96,13 @@ components: application/json: schema: $ref: '#/components/schemas/Product' +tags: + - + name: Products + description: Products + - + name: Products + description: Products + - + name: Products + description: Products diff --git a/Examples/using-traits/using-traits.yaml b/Examples/using-traits/using-traits.yaml index 8227ac1a..3666e2dd 100644 --- a/Examples/using-traits/using-traits.yaml +++ b/Examples/using-traits/using-traits.yaml @@ -133,3 +133,10 @@ components: description: 'The trick.' example: 'recite poem' type: object +tags: + - + name: Entities + description: Entities + - + name: Products + description: Products diff --git a/src/Generator.php b/src/Generator.php index f499e95f..ebcbf320 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -275,6 +275,7 @@ public function getProcessorPipeline(): Pipeline new Processors\MergeJsonContent(), new Processors\MergeXmlContent(), new Processors\OperationId(), + new Processors\AugmentTags(), new Processors\CleanUnmerged(), ]); } diff --git a/src/Processors/AugmentTags.php b/src/Processors/AugmentTags.php new file mode 100644 index 00000000..0aeb8fce --- /dev/null +++ b/src/Processors/AugmentTags.php @@ -0,0 +1,44 @@ +tags list. + */ +class AugmentTags implements ProcessorInterface +{ + public function __invoke(Analysis $analysis) + { + /** @var OA\Operation[] $operations */ + $operations = $analysis->getAnnotationsOfType(OA\Operation::class); + + $usedTags = []; + foreach ($operations as $operation) { + if (!Generator::isDefault($operation->tags)) { + $usedTags = array_merge($usedTags, $operation->tags); + } + } + + if ($usedTags) { + $declaredTags = []; + if (!Generator::isDefault($analysis->openapi->tags)) { + foreach ($analysis->openapi->tags as $tag) { + $declaredTags[] = $tag->name; + } + } + foreach ($usedTags as $tag) { + if (!in_array($tag, $declaredTags)) { + $analysis->openapi->merge([new OA\Tag(['name' => $tag, 'description' => $tag])]); + } + } + } + } +} diff --git a/tests/Fixtures/Scratch/ComplexCustomAttributes3.0.0.yaml b/tests/Fixtures/Scratch/ComplexCustomAttributes3.0.0.yaml index a2e25b93..08e2245d 100644 --- a/tests/Fixtures/Scratch/ComplexCustomAttributes3.0.0.yaml +++ b/tests/Fixtures/Scratch/ComplexCustomAttributes3.0.0.yaml @@ -61,3 +61,7 @@ components: title: TargetId TargetType: title: TargetType +tags: + - + name: 'Target groups' + description: 'Target groups' diff --git a/tests/Fixtures/Scratch/ComplexCustomAttributes3.1.0.yaml b/tests/Fixtures/Scratch/ComplexCustomAttributes3.1.0.yaml index d2d9b15b..56feb209 100644 --- a/tests/Fixtures/Scratch/ComplexCustomAttributes3.1.0.yaml +++ b/tests/Fixtures/Scratch/ComplexCustomAttributes3.1.0.yaml @@ -61,3 +61,7 @@ components: title: TargetId TargetType: title: TargetType +tags: + - + name: 'Target groups' + description: 'Target groups' diff --git a/tests/Fixtures/Scratch/ParameterContent3.0.0.yaml b/tests/Fixtures/Scratch/ParameterContent3.0.0.yaml index 6011a95b..1a338627 100644 --- a/tests/Fixtures/Scratch/ParameterContent3.0.0.yaml +++ b/tests/Fixtures/Scratch/ParameterContent3.0.0.yaml @@ -24,3 +24,7 @@ paths: responses: '200': description: OK +tags: + - + name: endpoints + description: endpoints diff --git a/tests/Fixtures/Scratch/ParameterContent3.1.0.yaml b/tests/Fixtures/Scratch/ParameterContent3.1.0.yaml index 71fadccf..0df4db40 100644 --- a/tests/Fixtures/Scratch/ParameterContent3.1.0.yaml +++ b/tests/Fixtures/Scratch/ParameterContent3.1.0.yaml @@ -24,3 +24,7 @@ paths: responses: '200': description: OK +tags: + - + name: endpoints + description: endpoints diff --git a/tests/Fixtures/Scratch/Tags.php b/tests/Fixtures/Scratch/Tags.php new file mode 100644 index 00000000..09f15c05 --- /dev/null +++ b/tests/Fixtures/Scratch/Tags.php @@ -0,0 +1,31 @@ +