Skip to content

Commit effbaac

Browse files
committed
Preserve multiline formatting in Swagger export
1 parent 5dcfe2e commit effbaac

File tree

5 files changed

+19
-4
lines changed

5 files changed

+19
-4
lines changed

features/hydra/docs.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ Feature: Documentation support
3232
# Root properties
3333
And the JSON node "@id" should be equal to "/docs.jsonld"
3434
And the JSON node "hydra:title" should be equal to "My Dummy API"
35-
And the JSON node "hydra:description" should be equal to "This is a test API."
35+
And the JSON node "hydra:description" should contain "This is a test API."
36+
And the JSON node "hydra:description" should contain "Made with love"
3637
And the JSON node "hydra:entrypoint" should be equal to "/"
3738
# Supported classes
3839
And the Hydra class "The API entrypoint" exists

features/swagger/docs.feature

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ Feature: Documentation support
1313
And the JSON node "swagger" should be equal to "2.0"
1414
# Root properties
1515
And the JSON node "info.title" should be equal to "My Dummy API"
16-
And the JSON node "info.description" should be equal to "This is a test API."
16+
And the JSON node "info.description" should contain "This is a test API."
17+
And the JSON node "info.description" should contain "Made with love"
1718
# Supported classes
1819
And the Swagger class "AbstractDummy" exists
1920
And the Swagger class "CircularReference" exists

src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
6767
{
6868
$documentation = new Documentation($this->resourceNameCollectionFactory->create(), $this->apiTitle, $this->apiDescription, $this->apiVersion, $this->apiFormats);
6969
$data = $this->documentationNormalizer->normalize($documentation);
70-
$content = $input->getOption('yaml') ? Yaml::dump($data, 6, 4, Yaml::DUMP_OBJECT_AS_MAP | Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE) : (json_encode($data, JSON_PRETTY_PRINT) ?: '');
70+
$content = $input->getOption('yaml') ? Yaml::dump($data, 6, 4, Yaml::DUMP_OBJECT_AS_MAP | Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK) : (json_encode($data, JSON_PRETTY_PRINT) ?: '');
7171
if (!empty($filename = $input->getOption('output')) && \is_string($filename)) {
7272
file_put_contents($filename, $content);
7373
$output->writeln(

tests/Bridge/Symfony/Bundle/Command/SwaggerCommandTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,17 @@ public function testExecuteWithYaml()
7272
YAML;
7373

7474
$this->assertContains($expected, $result, 'arrays should be correctly formatted.');
75+
76+
$expected = <<<YAML
77+
info:
78+
title: 'My Dummy API'
79+
version: 0.0.0
80+
description: |
81+
This is a test API.
82+
Made with love
83+
YAML;
84+
85+
$this->assertContains($expected, $result, 'multiline formatting must be preserved (using literal style).');
7586
}
7687

7788
public function testWriteToFile()

tests/Fixtures/app/config/config_test.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@ twig:
2828

2929
api_platform:
3030
title: 'My Dummy API'
31-
description: 'This is a test API.'
31+
description: |
32+
This is a test API.
33+
Made with love
3234
allow_plain_identifiers: true
3335
formats:
3436
jsonld: ['application/ld+json']

0 commit comments

Comments
 (0)