Skip to content

Commit f4cfeaa

Browse files
author
abluchet
committed
Fix null title/description configuration (#1563 followup)
1 parent 81770d5 commit f4cfeaa

File tree

2 files changed

+44
-2
lines changed

2 files changed

+44
-2
lines changed

src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,19 @@ public function getConfigTreeBuilder()
4242
->children()
4343
->scalarNode('title')
4444
->info('The title of the API.')
45-
->cannotBeEmpty()
4645
->defaultValue('')
46+
->beforeNormalization()
47+
->ifNull()
48+
->then(function ($v) { return ''; })
49+
->end()
4750
->end()
4851
->scalarNode('description')
4952
->info('The description of the API.')
50-
->cannotBeEmpty()
5153
->defaultValue('')
54+
->beforeNormalization()
55+
->ifNull()
56+
->then(function ($v) { return ''; })
57+
->end()
5258
->end()
5359
->scalarNode('version')
5460
->info('The version of the API.')

tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,4 +234,40 @@ public function testApiKeysConfig()
234234
$this->assertTrue(isset($config['swagger']['api_keys']));
235235
$this->assertSame($exampleConfig, $config['swagger']['api_keys'][0]);
236236
}
237+
238+
/**
239+
* Test config for empty title and description.
240+
*/
241+
public function testEmptyTitleDescriptionConfig()
242+
{
243+
$testConfig = [
244+
'title' => '',
245+
'description' => '',
246+
];
247+
248+
$config = $this->processor->processConfiguration($this->configuration, [
249+
'api_platform' => $testConfig,
250+
]);
251+
252+
$this->assertSame($config['title'], '');
253+
$this->assertSame($config['description'], '');
254+
}
255+
256+
/**
257+
* Test config for null title and description.
258+
*/
259+
public function testNullTitleDescriptionConfig()
260+
{
261+
$testConfig = [
262+
'title' => null,
263+
'description' => null,
264+
];
265+
266+
$config = $this->processor->processConfiguration($this->configuration, [
267+
'api_platform' => $testConfig,
268+
]);
269+
270+
$this->assertSame($config['title'], '');
271+
$this->assertSame($config['description'], '');
272+
}
237273
}

0 commit comments

Comments
 (0)