Skip to content

Commit

Permalink
Improve the OpenAPI normalizer (api-platform#2404)
Browse files Browse the repository at this point in the history
* Improve the OpenAPI normalizer

* Fix tests

* Fix API Gateway normalizer

* Fix ApiGatewayNormalizerTest
  • Loading branch information
dunglas authored Dec 20, 2018
1 parent 680a87c commit 20590a0
Show file tree
Hide file tree
Showing 12 changed files with 910 additions and 1,065 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@
/tests/Fixtures/app/var/*
/tests/Fixtures/app/cache/*
/tests/Fixtures/app/logs/*
/swagger.json
/swagger.yaml
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,6 @@ script:
vendor/bin/behat --suite=default --format=progress;
fi
- tests/Fixtures/app/console api:swagger:export --spec-version 2 > swagger.json && npx swagger-cli validate swagger.json && rm swagger.json
- tests/Fixtures/app/console api:swagger:export --spec-version 3 --yaml > swagger.yaml && npx swagger-cli validate swagger.yaml && rm swagger.yaml
- tests/Fixtures/app/console api:swagger:export --spec-version 2 --yaml > swagger.yaml && npx swagger-cli validate swagger.yaml && rm swagger.yaml
- tests/Fixtures/app/console api:openapi:export > swagger.json && npx swagger-cli validate swagger.json && rm swagger.json
- tests/Fixtures/app/console api:openapi:export --yaml > swagger.yaml && npx swagger-cli validate swagger.yaml && rm swagger.yaml
4 changes: 2 additions & 2 deletions src/Bridge/Symfony/Bundle/Command/SwaggerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

use ApiPlatform\Core\Documentation\Documentation;
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceNameCollectionFactoryInterface;
use ApiPlatform\Core\OpenApi\Serializer\AbstractDocumentationNormalizer;
use ApiPlatform\Core\Swagger\Serializer\DocumentationNormalizer;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidOptionException;
use Symfony\Component\Console\Input\InputInterface;
Expand Down Expand Up @@ -79,7 +79,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
}

$documentation = new Documentation($this->resourceNameCollectionFactory->create(), $this->apiTitle, $this->apiDescription, $this->apiVersion, $this->apiFormats);
$data = $this->normalizer->normalize($documentation, AbstractDocumentationNormalizer::FORMAT, ['spec_version' => (int) $version]);
$data = $this->normalizer->normalize($documentation, DocumentationNormalizer::FORMAT, ['spec_version' => (int) $version]);
$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) ?: '');

if (!empty($filename = $input->getOption('output')) && \is_string($filename)) {
Expand Down
28 changes: 0 additions & 28 deletions src/Bridge/Symfony/Bundle/Resources/config/swagger.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,34 +39,6 @@
<tag name="serializer.normalizer" priority="17" />
</service>

<service id="api_platform.openapi.normalizer.documentation" class="ApiPlatform\Core\OpenApi\Serializer\DocumentationNormalizer" public="false">
<argument type="service" id="api_platform.metadata.resource.metadata_factory" />
<argument type="service" id="api_platform.metadata.property.name_collection_factory" />
<argument type="service" id="api_platform.metadata.property.metadata_factory" />
<argument type="service" id="api_platform.resource_class_resolver" />
<argument type="service" id="api_platform.operation_method_resolver" />
<argument type="service" id="api_platform.operation_path_resolver" />
<argument type="service" id="api_platform.filter_locator" />
<argument type="service" id="api_platform.name_converter" on-invalid="ignore" />
<argument>%api_platform.oauth.enabled%</argument>
<argument>%api_platform.oauth.type%</argument>
<argument>%api_platform.oauth.flow%</argument>
<argument>%api_platform.oauth.tokenUrl%</argument>
<argument>%api_platform.oauth.authorizationUrl%</argument>
<argument>%api_platform.oauth.scopes%</argument>
<argument>%api_platform.swagger.api_keys%</argument>
<argument type="service" id="api_platform.subresource_operation_factory" />
<argument>%api_platform.collection.pagination.enabled%</argument>
<argument>%api_platform.collection.pagination.page_parameter_name%</argument>
<argument>%api_platform.collection.pagination.client_items_per_page%</argument>
<argument>%api_platform.collection.pagination.items_per_page_parameter_name%</argument>
<argument type="service" id="api_platform.formats_provider" />
<argument>%api_platform.collection.pagination.client_enabled%</argument>
<argument>%api_platform.collection.pagination.enabled_parameter_name%</argument>
<argument type="service" id="api_platform.swagger.normalizer.api_gateway" />
<tag name="serializer.normalizer" priority="18" />
</service>

<service id="api_platform.swagger.command.swagger_command" class="ApiPlatform\Core\Bridge\Symfony\Bundle\Command\SwaggerCommand">
<argument type="service" id="api_platform.serializer" />
<argument type="service" id="api_platform.metadata.resource.name_collection_factory" />
Expand Down
Loading

0 comments on commit 20590a0

Please sign in to comment.