Skip to content

Commit a7eb382

Browse files
Add non-regression test
1 parent 2b2460f commit a7eb382

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

features/swagger/docs.feature

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ Feature: Documentation support
99
Then the response status code should be 200
1010
And the response should be in JSON
1111
And the header "Content-Type" should be equal to "application/json; charset=utf-8"
12+
# OverrideDocumentationNormalizer
13+
And the JSON node "definitions.RamseyUuidDummy.properties.id.description" should be equal to "The dummy id"
14+
And the JSON node "definitions.RelatedDummy-barcelona" should exist
15+
And the JSON node "definitions.RelatedDummybarcelona" should not exist
1216
# Context
1317
And the JSON node "swagger" should be equal to "2.0"
1418
# Root properties
@@ -110,4 +114,6 @@ Feature: Documentation support
110114
And the response should be in JSON
111115
And the header "Content-Type" should be equal to "application/json; charset=utf-8"
112116
And the JSON node "basePath" should be equal to "/"
113-
And the JSON node "info.version" should be equal to "1.0.0"
117+
And the JSON node "definitions.RamseyUuidDummy.properties.id.description" should be equal to "The dummy id"
118+
And the JSON node "definitions.RelatedDummy-barcelona" should not exist
119+
And the JSON node "definitions.RelatedDummybarcelona" should exist

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ApiPlatform\Core\Documentation\Documentation;
1717
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
18+
use ApiPlatform\Core\Swagger\Serializer\ApiGatewayNormalizer;
1819
use ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer;
1920
use Symfony\Component\Console\Command\Command;
2021
use Symfony\Component\Console\Exception\InvalidOptionException;
@@ -62,7 +63,8 @@ protected function configure()
6263
->setDescription('Dump the OpenAPI documentation')
6364
->addOption('yaml', 'y', InputOption::VALUE_NONE, 'Dump the documentation in YAML')
6465
->addOption('spec-version', null, InputOption::VALUE_OPTIONAL, 'OpenAPI version to use ("2" or "3")', '2')
65-
->addOption('output', 'o', InputOption::VALUE_OPTIONAL, 'Write output to file');
66+
->addOption('output', 'o', InputOption::VALUE_OPTIONAL, 'Write output to file')
67+
->addOption('api-gateway', null, InputOption::VALUE_NONE, 'API Gateway compatibility');
6668
}
6769

6870
/**
@@ -79,7 +81,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7981
}
8082

8183
$documentation = new Documentation($this->resourceNameCollectionFactory->create(), $this->apiTitle, $this->apiDescription, $this->apiVersion, $this->apiFormats);
82-
$data = $this->normalizer->normalize($documentation, DocumentationNormalizer::FORMAT, ['spec_version' => (int) $version]);
84+
$data = $this->normalizer->normalize($documentation, DocumentationNormalizer::FORMAT, ['spec_version' => (int) $version, ApiGatewayNormalizer::API_GATEWAY => $input->getOption('api-gateway')]);
8385
$content = $input->getOption('yaml') ? Yaml::dump($data, 10, 2, Yaml::DUMP_OBJECT_AS_MAP | Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE | Yaml::DUMP_MULTI_LINE_LITERAL_BLOCK) : (json_encode($data, JSON_PRETTY_PRINT) ?: '');
8486

8587
if (!empty($filename = $input->getOption('output')) && \is_string($filename)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public function testExecuteWithYamlVersion3()
8585
$expected = <<<YAML
8686
info:
8787
title: 'My Dummy API'
88-
version: 1.0.0
88+
version: 0.0.0
8989
description: |
9090
This is a test API.
9191
Made with love

tests/Fixtures/TestBundle/Serializer/Normalizer/OverrideDocumentationNormalizer.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,11 @@ public function __construct(NormalizerInterface $documentationNormalizer)
3030
public function normalize($object, $format = null, array $context = [])
3131
{
3232
$data = $this->documentationNormalizer->normalize($object, $format, $context);
33-
$data['info']['version'] = '1.0.0';
33+
if (isset($data['definitions'])) {
34+
$data['definitions']['RamseyUuidDummy']['properties']['id']['description'] = 'The dummy id';
35+
} else {
36+
$data['components']['schemas']['RamseyUuidDummy']['properties']['id']['description'] = 'The dummy id';
37+
}
3438

3539
return $data;
3640
}

0 commit comments

Comments
 (0)