Skip to content

Commit

Permalink
fix: pass configured openapi version to swagger-php (#2159)
Browse files Browse the repository at this point in the history
  • Loading branch information
DjordyKoert committed Dec 31, 2023
1 parent d8a9b66 commit b415300
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
13 changes: 13 additions & 0 deletions ApiDocGenerator.php
Expand Up @@ -47,6 +47,10 @@ final class ApiDocGenerator

/** @var string[] */
private $mediaTypes = ['json'];
/**
* @var ?string
*/
private $openApiVersion = null;

/**
* @param DescriberInterface[]|iterable $describers
Expand All @@ -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) {
Expand All @@ -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
Expand Down
1 change: 1 addition & 0 deletions DependencyInjection/NelmioApiDocExtension.php
Expand Up @@ -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)),
Expand Down

0 comments on commit b415300

Please sign in to comment.