Skip to content

Commit 7a272e8

Browse files
committed
Merge branch 'master' into 2.4
2 parents 1510368 + 32e6c07 commit 7a272e8

File tree

7 files changed

+88
-16
lines changed

7 files changed

+88
-16
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103
},
104104
"extra": {
105105
"branch-alias": {
106-
"dev-master": "2.4.x-dev"
106+
"dev-master": "2.5.x-dev"
107107
}
108108
},
109109
"config": {

features/swagger/docs.feature

Lines changed: 14 additions & 0 deletions
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
@@ -103,3 +107,13 @@ Feature: Documentation support
103107
And I should see text matching "My Dummy API"
104108
And I should see text matching "swagger"
105109
And I should see text matching "2.0"
110+
111+
Scenario: Retrieve the Swagger/OpenAPI documentation with API Gateway compatibility
112+
Given I send a "GET" request to "/docs.json?api_gateway=true"
113+
Then the response status code should be 200
114+
And the response should be in JSON
115+
And the header "Content-Type" should be equal to "application/json; charset=utf-8"
116+
And the JSON node "basePath" should be equal to "/"
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)) {

src/Bridge/Symfony/Bundle/Resources/config/swagger.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
<tag name="serializer.normalizer" priority="16" />
3535
</service>
3636

37-
<service id="api_platform.swagger.normalizer.api_gateway" class="ApiPlatform\Core\Swagger\Serializer\ApiGatewayNormalizer" public="false" decorates="api_platform.swagger.normalizer.documentation">
37+
<service id="api_platform.swagger.normalizer.api_gateway" class="ApiPlatform\Core\Swagger\Serializer\ApiGatewayNormalizer" public="false" decorates="api_platform.swagger.normalizer.documentation" decoration-priority="-1">
3838
<argument type="service" id="api_platform.swagger.normalizer.api_gateway.inner" />
3939
<tag name="serializer.normalizer" priority="17" />
4040
</service>

src/Bridge/Symfony/Bundle/Resources/views/SwaggerUi/index.html.twig

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@
44
<meta charset="UTF-8">
55
<title>{% if title %}{{ title }} - {% endif %}API Platform</title>
66

7-
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700">
8-
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/swagger-ui/swagger-ui.css') }}">
9-
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/style.css') }}">
10-
7+
{% block stylesheet %}
8+
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,700|Source+Code+Pro:300,600|Titillium+Web:400,600,700">
9+
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/swagger-ui/swagger-ui.css') }}">
10+
<link rel="stylesheet" href="{{ asset('bundles/apiplatform/style.css') }}">
11+
{% endblock %}
12+
1113
{# json_encode(65) is for JSON_UNESCAPED_SLASHES|JSON_HEX_TAG to avoid JS XSS #}
1214
<script id="swagger-data" type="application/json">{{ swagger_data|json_encode(65)|raw }}</script>
1315
</head>
@@ -74,14 +76,16 @@
7476
</div>
7577
</div>
7678

77-
{% if (reDocEnabled and not swaggerUiEnabled) or (reDocEnabled and 're_doc' == active_ui) %}
78-
<script src="{{ asset('bundles/apiplatform/redoc/redoc.standalone.js') }}"></script>
79-
<script src="{{ asset('bundles/apiplatform/init-redoc-ui.js') }}"></script>
80-
{% elseif (swaggerUiEnabled) %}
81-
<script src="{{ asset('bundles/apiplatform/swagger-ui/swagger-ui-bundle.js') }}"></script>
82-
<script src="{{ asset('bundles/apiplatform/swagger-ui/swagger-ui-standalone-preset.js') }}"></script>
83-
<script src="{{ asset('bundles/apiplatform/init-swagger-ui.js') }}"></script>
84-
{% endif %}
79+
{% block javascript %}
80+
{% if (reDocEnabled and not swaggerUiEnabled) or (reDocEnabled and 're_doc' == active_ui) %}
81+
<script src="{{ asset('bundles/apiplatform/redoc/redoc.standalone.js') }}"></script>
82+
<script src="{{ asset('bundles/apiplatform/init-redoc-ui.js') }}"></script>
83+
{% elseif (swaggerUiEnabled) %}
84+
<script src="{{ asset('bundles/apiplatform/swagger-ui/swagger-ui-bundle.js') }}"></script>
85+
<script src="{{ asset('bundles/apiplatform/swagger-ui/swagger-ui-standalone-preset.js') }}"></script>
86+
<script src="{{ asset('bundles/apiplatform/init-swagger-ui.js') }}"></script>
87+
{% endif %}
88+
{% endblock %}
8589

8690
</body>
8791
</html>
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the API Platform project.
5+
*
6+
* (c) Kévin Dunglas <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
declare(strict_types=1);
13+
14+
namespace ApiPlatform\Core\Tests\Fixtures\TestBundle\Serializer\Normalizer;
15+
16+
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
17+
18+
/**
19+
* @author Vincent Chalamon <[email protected]>
20+
*/
21+
final class OverrideDocumentationNormalizer implements NormalizerInterface
22+
{
23+
private $documentationNormalizer;
24+
25+
public function __construct(NormalizerInterface $documentationNormalizer)
26+
{
27+
$this->documentationNormalizer = $documentationNormalizer;
28+
}
29+
30+
public function normalize($object, $format = null, array $context = [])
31+
{
32+
$data = $this->documentationNormalizer->normalize($object, $format, $context);
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+
}
38+
39+
return $data;
40+
}
41+
42+
public function supportsNormalization($data, $format = null)
43+
{
44+
return $this->documentationNormalizer->supportsNormalization($data, $format);
45+
}
46+
}

tests/Fixtures/app/config/config_common.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,9 @@ services:
197197

198198
mercure.hub.default.publisher:
199199
class: ApiPlatform\Core\Tests\Fixtures\DummyMercurePublisher
200+
201+
app.serializer.normalizer.override_documentation:
202+
class: ApiPlatform\Core\Tests\Fixtures\TestBundle\Serializer\Normalizer\OverrideDocumentationNormalizer
203+
decorates: api_platform.swagger.normalizer.documentation
204+
public: false
205+
arguments: ['@app.serializer.normalizer.override_documentation.inner']

0 commit comments

Comments
 (0)