Skip to content

Commit 20590a0

Browse files
authored
Improve the OpenAPI normalizer (#2404)
* Improve the OpenAPI normalizer * Fix tests * Fix API Gateway normalizer * Fix ApiGatewayNormalizerTest
1 parent 680a87c commit 20590a0

File tree

12 files changed

+910
-1065
lines changed

12 files changed

+910
-1065
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,5 @@
77
/tests/Fixtures/app/var/*
88
/tests/Fixtures/app/cache/*
99
/tests/Fixtures/app/logs/*
10+
/swagger.json
11+
/swagger.yaml

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ script:
5252
vendor/bin/behat --suite=default --format=progress;
5353
fi
5454
- tests/Fixtures/app/console api:swagger:export --spec-version 2 > swagger.json && npx swagger-cli validate swagger.json && rm swagger.json
55-
- tests/Fixtures/app/console api:swagger:export --spec-version 3 --yaml > swagger.yaml && npx swagger-cli validate swagger.yaml && rm swagger.yaml
55+
- tests/Fixtures/app/console api:swagger:export --spec-version 2 --yaml > swagger.yaml && npx swagger-cli validate swagger.yaml && rm swagger.yaml
5656
- tests/Fixtures/app/console api:openapi:export > swagger.json && npx swagger-cli validate swagger.json && rm swagger.json
5757
- tests/Fixtures/app/console api:openapi:export --yaml > swagger.yaml && npx swagger-cli validate swagger.yaml && rm swagger.yaml

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

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

1616
use ApiPlatform\Core\Documentation\Documentation;
1717
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
18-
use ApiPlatform\Core\OpenApi\Serializer\AbstractDocumentationNormalizer;
18+
use ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer;
1919
use Symfony\Component\Console\Command\Command;
2020
use Symfony\Component\Console\Exception\InvalidOptionException;
2121
use Symfony\Component\Console\Input\InputInterface;
@@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
7979
}
8080

8181
$documentation = new Documentation($this->resourceNameCollectionFactory->create(), $this->apiTitle, $this->apiDescription, $this->apiVersion, $this->apiFormats);
82-
$data = $this->normalizer->normalize($documentation, AbstractDocumentationNormalizer::FORMAT, ['spec_version' => (int) $version]);
82+
$data = $this->normalizer->normalize($documentation, DocumentationNormalizer::FORMAT, ['spec_version' => (int) $version]);
8383
$content = $input->getOption('yaml') ? Yaml::dump($data, 10, 2, Yaml::DUMP_OBJECT_AS_MAP | Yaml::DUMP_EMPTY_ARRAY_AS_SEQUENCE) : (json_encode($data, JSON_PRETTY_PRINT) ?: '');
8484

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

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

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -39,34 +39,6 @@
3939
<tag name="serializer.normalizer" priority="17" />
4040
</service>
4141

42-
<service id="api_platform.openapi.normalizer.documentation" class="ApiPlatform\Core\OpenApi\Serializer\DocumentationNormalizer" public="false">
43-
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
44-
<argument type="service" id="api_platform.metadata.property.name_collection_factory" />
45-
<argument type="service" id="api_platform.metadata.property.metadata_factory" />
46-
<argument type="service" id="api_platform.resource_class_resolver" />
47-
<argument type="service" id="api_platform.operation_method_resolver" />
48-
<argument type="service" id="api_platform.operation_path_resolver" />
49-
<argument type="service" id="api_platform.filter_locator" />
50-
<argument type="service" id="api_platform.name_converter" on-invalid="ignore" />
51-
<argument>%api_platform.oauth.enabled%</argument>
52-
<argument>%api_platform.oauth.type%</argument>
53-
<argument>%api_platform.oauth.flow%</argument>
54-
<argument>%api_platform.oauth.tokenUrl%</argument>
55-
<argument>%api_platform.oauth.authorizationUrl%</argument>
56-
<argument>%api_platform.oauth.scopes%</argument>
57-
<argument>%api_platform.swagger.api_keys%</argument>
58-
<argument type="service" id="api_platform.subresource_operation_factory" />
59-
<argument>%api_platform.collection.pagination.enabled%</argument>
60-
<argument>%api_platform.collection.pagination.page_parameter_name%</argument>
61-
<argument>%api_platform.collection.pagination.client_items_per_page%</argument>
62-
<argument>%api_platform.collection.pagination.items_per_page_parameter_name%</argument>
63-
<argument type="service" id="api_platform.formats_provider" />
64-
<argument>%api_platform.collection.pagination.client_enabled%</argument>
65-
<argument>%api_platform.collection.pagination.enabled_parameter_name%</argument>
66-
<argument type="service" id="api_platform.swagger.normalizer.api_gateway" />
67-
<tag name="serializer.normalizer" priority="18" />
68-
</service>
69-
7042
<service id="api_platform.swagger.command.swagger_command" class="ApiPlatform\Core\Bridge\Symfony\Bundle\Command\SwaggerCommand">
7143
<argument type="service" id="api_platform.serializer" />
7244
<argument type="service" id="api_platform.metadata.resource.name_collection_factory" />

0 commit comments

Comments
 (0)