From 90faa0bec4a7d2f696349fee5456f52dd7266b95 Mon Sep 17 00:00:00 2001 From: Daniel Subiabre Date: Tue, 11 Feb 2025 23:27:12 +0100 Subject: [PATCH] Move tag setting from components schemas to own method --- src/OpenApi/OpenApiFactory.php | 58 ++++++++++++++++++---------------- 1 file changed, 31 insertions(+), 27 deletions(-) diff --git a/src/OpenApi/OpenApiFactory.php b/src/OpenApi/OpenApiFactory.php index 056a073..0466b35 100644 --- a/src/OpenApi/OpenApiFactory.php +++ b/src/OpenApi/OpenApiFactory.php @@ -28,6 +28,36 @@ class OpenApiFactory implements OpenApiFactoryInterface ->withDescription($description); } + private function getComponentsSchemasTags(OpenApi $openApi): array + { + $tags = []; + + foreach ($openApi->getComponents()->getSchemas() as $name => $schema) { + if (\preg_match('/.*\.patch/', $name)) { + continue; + } + + if (\preg_match('/.*\.jsonld/', $name)) { + continue; + } + + if (empty($schema['description'])) { + continue; + } + + if (\preg_match('/.*Dto/', $name)) { + $name = preg_replace('/\..*Dto/', '', $name); + } + + $tags[] = [ + 'name' => $name, + 'description' => $schema['description'], + ]; + } + + return $tags; + } + private function updateOperation(Operation $operation): Operation { $idParts = explode('_', $operation->getOperationId()); @@ -105,34 +135,8 @@ class OpenApiFactory implements OpenApiFactoryInterface public function __invoke(array $context = []): OpenApi { $openApi = $this->decorated->__invoke($context); - $openApi = $openApi->withInfo($this->getInfoWithDescription($openApi)); - - $tags = []; - foreach ($openApi->getComponents()->getSchemas() as $name => $schema) { - if (\preg_match('/.*\.patch/', $name)) { - continue; - } - - if (\preg_match('/.*\.jsonld/', $name)) { - continue; - } - - if (empty($schema['description'])) { - continue; - } - - if (\preg_match('/.*Dto/', $name)) { - $name = preg_replace('/\..*Dto/', '', $name); - } - - $tags[] = [ - 'name' => $name, - 'description' => $schema['description'], - ]; - } - - $openApi = $openApi->withTags($tags); + $openApi = $openApi->withTags($this->getComponentsSchemasTags($openApi)); $paths = new Paths(); foreach ($openApi->getPaths()->getPaths() as $path => $pathItem) {