From b4153009220948da67af9b25e4fc04abf3765942 Mon Sep 17 00:00:00 2001 From: Djordy Koert Date: Sun, 31 Dec 2023 18:52:26 +0100 Subject: [PATCH] fix: pass configured openapi version to swagger-php (#2159) --- ApiDocGenerator.php | 13 +++++++++++++ DependencyInjection/NelmioApiDocExtension.php | 1 + 2 files changed, 14 insertions(+) diff --git a/ApiDocGenerator.php b/ApiDocGenerator.php index 83f1a41db..9c9c2b75f 100644 --- a/ApiDocGenerator.php +++ b/ApiDocGenerator.php @@ -47,6 +47,10 @@ final class ApiDocGenerator /** @var string[] */ private $mediaTypes = ['json']; + /** + * @var ?string + */ + private $openApiVersion = null; /** * @param DescriberInterface[]|iterable $describers @@ -70,6 +74,11 @@ public function setMediaTypes(array $mediaTypes) $this->mediaTypes = $mediaTypes; } + public function setOpenApiVersion(?string $openApiVersion) + { + $this->openApiVersion = $openApiVersion; + } + public function generate(): OpenApi { if (null !== $this->openApi) { @@ -84,6 +93,10 @@ public function generate(): OpenApi } $generator = new Generator($this->logger); + if ($this->openApiVersion) { + $generator->setVersion($this->openApiVersion); + } + // Remove OperationId processor as we use a lot of generated annotations which do not have enough information in their context // to generate these ids properly. // @see https://github.com/zircote/swagger-php/issues/1153 diff --git a/DependencyInjection/NelmioApiDocExtension.php b/DependencyInjection/NelmioApiDocExtension.php index edcca5cb7..26d42c216 100644 --- a/DependencyInjection/NelmioApiDocExtension.php +++ b/DependencyInjection/NelmioApiDocExtension.php @@ -75,6 +75,7 @@ public function load(array $configs, ContainerBuilder $container): void ->addMethodCall('setAlternativeNames', [$nameAliases]) ->addMethodCall('setMediaTypes', [$config['media_types']]) ->addMethodCall('setLogger', [new Reference('logger')]) + ->addMethodCall('setOpenApiVersion', [$config['documentation']['openapi'] ?? null]) ->addTag('monolog.logger', ['channel' => 'nelmio_api_doc']) ->setArguments([ new TaggedIteratorArgument(sprintf('nelmio_api_doc.describer.%s', $area)),