Skip to content

Commit

Permalink
Review fixes 2
Browse files Browse the repository at this point in the history
  • Loading branch information
HypeMC committed Apr 18, 2024
1 parent 2813942 commit 9e84ef5
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/Command/DumpCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$options = [];
if (RenderOpenApi::HTML === $format) {
$rawHtmlConfig = json_decode($input->getOption('html-config'), true);
$options = is_array($rawHtmlConfig) ? $rawHtmlConfig : $this->defaultHtmlConfig;
$options = is_array($rawHtmlConfig) ? $rawHtmlConfig + $this->defaultHtmlConfig : $this->defaultHtmlConfig;
} elseif (RenderOpenApi::JSON === $format) {
$options = [
'no-pretty' => $input->hasParameterOption(['--no-pretty']),
Expand Down
3 changes: 3 additions & 0 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,17 @@ public function getConfigTreeBuilder(): TreeBuilder
->end()
->arrayNode('html_config')
->info('UI configuration options')
->addDefaultsIfNotSet()
->children()
->scalarNode('assets_mode')
->defaultValue(AssetsMode::CDN)
->end()
->arrayNode('swagger_ui_config')
->addDefaultsIfNotSet()
->ignoreExtraKeys(false)
->end()
->arrayNode('redocly_config')
->addDefaultsIfNotSet()
->ignoreExtraKeys(false)
->end()
->end()
Expand Down
6 changes: 1 addition & 5 deletions src/Render/Html/HtmlOpenApiRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,7 @@ public function getFormat(): string

public function render(OpenApi $spec, array $options = []): string
{
$options += $this->htmlConfig + [
'assets_mode' => AssetsMode::CDN,
'swagger_ui_config' => [],
'redocly_config' => [],
];
$options += $this->htmlConfig;

if (isset($options['ui_renderer']) && Renderer::REDOCLY === $options['ui_renderer']) {
return $this->twig->render(
Expand Down
59 changes: 50 additions & 9 deletions tests/DependencyInjection/NelmioApiDocExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,23 +301,64 @@ public static function provideCacheConfig(): \Generator
];
}

public function testHtmlOpenApiRendererWithHtmlConfig()
/**
* @dataProvider provideOpenApiRendererWithHtmlConfig
*/
public function testHtmlOpenApiRendererWithHtmlConfig(array $htmlConfig, array $expectedHtmlConfig): void

Check failure on line 307 in tests/DependencyInjection/NelmioApiDocExtensionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Nelmio\ApiDocBundle\Tests\DependencyInjection\NelmioApiDocExtensionTest::testHtmlOpenApiRendererWithHtmlConfig() has parameter $expectedHtmlConfig with no value type specified in iterable type array.

Check failure on line 307 in tests/DependencyInjection/NelmioApiDocExtensionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Nelmio\ApiDocBundle\Tests\DependencyInjection\NelmioApiDocExtensionTest::testHtmlOpenApiRendererWithHtmlConfig() has parameter $htmlConfig with no value type specified in iterable type array.
{
$container = new ContainerBuilder();
$container->setParameter('kernel.bundles', [
'TwigBundle' => TwigBundle::class,
]);

$extension = new NelmioApiDocExtension();
$extension->load([['html_config' => $htmlConfig = [
'assets_mode' => 'cdn',
'redocly_config' => [
'expandResponses' => '200,201',
'hideDownloadButton' => true,
],
]]], $container);
$extension->load([['html_config' => $htmlConfig]], $container);

$argument = $container->getDefinition('nelmio_api_doc.render_docs.html')->getArgument(1);
self::assertSame($htmlConfig, $argument);
self::assertSame($expectedHtmlConfig, $argument);
}

public static function provideOpenApiRendererWithHtmlConfig(): iterable

Check failure on line 321 in tests/DependencyInjection/NelmioApiDocExtensionTest.php

View workflow job for this annotation

GitHub Actions / PHPStan

Method Nelmio\ApiDocBundle\Tests\DependencyInjection\NelmioApiDocExtensionTest::provideOpenApiRendererWithHtmlConfig() return type has no value type specified in iterable type iterable.
{
yield 'default' => [
[],
[
'assets_mode' => 'cdn',
'swagger_ui_config' => [],
'redocly_config' => [],
],
];
yield 'swagger_ui' => [
[
'assets_mode' => 'bundle',
'swagger_ui_config' => [
'deepLinking' => true,
],
],
[
'assets_mode' => 'bundle',
'swagger_ui_config' => [
'deepLinking' => true,
],
'redocly_config' => [],
],
];
yield 'redocly' => [
[
'assets_mode' => 'cdn',
'redocly_config' => [
'expandResponses' => '200,201',
'hideDownloadButton' => true,
],
],
[
'assets_mode' => 'cdn',
'redocly_config' => [
'expandResponses' => '200,201',
'hideDownloadButton' => true,
],
'swagger_ui_config' => [],
],
];
}
}

0 comments on commit 9e84ef5

Please sign in to comment.