-
-
Notifications
You must be signed in to change notification settings - Fork 966
OpenApi v3 refactor #3407
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
OpenApi v3 refactor #3407
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
78bc6af
Open API v3 refactor
soyuka 2271b57
Fix external properties
soyuka aa50519
Fix paths api
soyuka 41c9f21
Opti
soyuka 7e7969b
@flug's review
soyuka e17f701
Fix tests
soyuka ffe3ef0
Fix tests
soyuka 4e4af91
fix tests
soyuka e1a826e
Bump serializer min version
soyuka 856c843
Fix some comments
soyuka 77f152a
Fix some comments
soyuka 6d00d9f
Fix some comments
soyuka 76084cf
Fix some tests
soyuka 953be4b
Remove operationRef
soyuka c710407
openapi: add subresource support
soyuka 9dbca67
openapi: fix multiple formats
soyuka 7a22189
Fix tests
soyuka File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the API Platform project. | ||
| * | ||
| * (c) Kévin Dunglas <dunglas@gmail.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ApiPlatform\Core\Bridge\Symfony\Bundle\Command; | ||
|
|
||
| use ApiPlatform\Core\OpenApi\Factory\OpenApiFactoryInterface; | ||
| use Symfony\Component\Console\Command\Command; | ||
| use Symfony\Component\Console\Input\ArrayInput; | ||
| use Symfony\Component\Console\Input\InputInterface; | ||
| use Symfony\Component\Console\Input\InputOption; | ||
| use Symfony\Component\Console\Output\OutputInterface; | ||
| use Symfony\Component\Console\Style\SymfonyStyle; | ||
| use Symfony\Component\Filesystem\Filesystem; | ||
| use Symfony\Component\Serializer\Normalizer\NormalizerInterface; | ||
| use Symfony\Component\Yaml\Yaml; | ||
|
|
||
| /** | ||
| * Dumps Open API documentation. | ||
| */ | ||
| final class OpenApiCommand extends Command | ||
| { | ||
| private $openApiFactory; | ||
| private $normalizer; | ||
|
|
||
| public function __construct(OpenApiFactoryInterface $openApiFactory, NormalizerInterface $normalizer) | ||
| { | ||
| parent::__construct(); | ||
| $this->openApiFactory = $openApiFactory; | ||
| $this->normalizer = $normalizer; | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| protected function configure() | ||
| { | ||
| $this | ||
| ->setName('api:openapi:export') | ||
| ->setDescription('Dump the Open API documentation') | ||
| ->addOption('yaml', 'y', InputOption::VALUE_NONE, 'Dump the documentation in YAML') | ||
| ->addOption('output', 'o', InputOption::VALUE_OPTIONAL, 'Write output to file') | ||
| ->addOption('spec-version', null, InputOption::VALUE_OPTIONAL, 'Open API version to use (2 or 3) (2 is deprecated)', 3) | ||
| ->addOption('api-gateway', null, InputOption::VALUE_NONE, 'Enable the Amazon API Gateway compatibility mode'); | ||
| } | ||
|
|
||
| /** | ||
| * {@inheritdoc} | ||
| */ | ||
| protected function execute(InputInterface $input, OutputInterface $output) | ||
| { | ||
| // Backwards compatibility | ||
| if (2 === $specVersion = (int) $input->getOption('spec-version')) { | ||
| $command = $this->getApplication()->find('api:swagger:export'); | ||
|
|
||
| return $command->run(new ArrayInput([ | ||
| 'command' => 'api:swagger:export', | ||
| '--spec-version' => $specVersion, | ||
| '--yaml' => $input->getOption('yaml'), | ||
| '--output' => $input->getOption('output'), | ||
| '--api-gateway' => $input->getOption('api-gateway'), | ||
| ]), $output); | ||
| } | ||
|
|
||
| $filesystem = new Filesystem(); | ||
| $io = new SymfonyStyle($input, $output); | ||
| $data = $this->normalizer->normalize($this->openApiFactory->__invoke(), 'json'); | ||
| $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 | JSON_UNESCAPED_SLASHES) ?: ''); | ||
|
|
||
| $filename = $input->getOption('output'); | ||
| if ($filename && \is_string($filename)) { | ||
| $filesystem->dumpFile($filename, $content); | ||
| $io->success(sprintf('Data written to %s.', $filename)); | ||
|
soyuka marked this conversation as resolved.
|
||
|
|
||
| return 0; | ||
| } | ||
|
|
||
| $output->writeln($content); | ||
|
|
||
| return 0; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| <?xml version="1.0" ?> | ||
|
|
||
| <container xmlns="http://symfony.com/schema/dic/services" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd"> | ||
|
|
||
| <services> | ||
| <service id="api_platform.openapi.normalizer" class="ApiPlatform\Core\OpenApi\Serializer\OpenApiNormalizer" public="false"> | ||
| <argument type="service" id="serializer.normalizer.object" /> | ||
| <tag name="serializer.normalizer" priority="-785" /> | ||
| </service> | ||
| <service id="ApiPlatform\Core\OpenApi\Serializer\OpenApiNormalizer" alias="api_platform.openapi.normalizer" /> | ||
|
|
||
| <service id="api_platform.openapi.options" class="ApiPlatform\Core\OpenApi\Options"> | ||
| <argument>%api_platform.title%</argument> | ||
| <argument>%api_platform.description%</argument> | ||
| <argument>%api_platform.version%</argument> | ||
| <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.refreshUrl%</argument> | ||
| <argument>%api_platform.oauth.scopes%</argument> | ||
| <argument>%api_platform.swagger.api_keys%</argument> | ||
| </service> | ||
| <service id="ApiPlatform\Core\OpenApi\Options" alias="api_platform.openapi.options" /> | ||
|
|
||
| <service id="api_platform.openapi.factory" class="ApiPlatform\Core\OpenApi\Factory\OpenApiFactory" public="false"> | ||
| <argument type="service" id="api_platform.metadata.resource.name_collection_factory" /> | ||
| <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.json_schema.schema_factory" /> | ||
| <argument type="service" id="api_platform.json_schema.type_factory" /> | ||
| <argument type="service" id="api_platform.operation_path_resolver" /> | ||
| <argument type="service" id="api_platform.filter_locator" /> | ||
| <argument type="service" id="api_platform.subresource_operation_factory" /> | ||
| <argument>%api_platform.formats%</argument> | ||
| <argument type="service" id="api_platform.openapi.options" /> | ||
| <argument type="service" id="api_platform.pagination_options" /> | ||
| </service> | ||
| <service id="ApiPlatform\Core\OpenApi\Factory\OpenApiFactoryInterface" alias="api_platform.openapi.factory" /> | ||
|
|
||
| <service id="api_platform.openapi.command" class="ApiPlatform\Core\Bridge\Symfony\Bundle\Command\OpenApiCommand"> | ||
| <argument type="service" id="api_platform.openapi.factory" /> | ||
| <argument type="service" id="api_platform.serializer" /> | ||
| <tag name="console.command" /> | ||
| </service> | ||
|
|
||
| <service id="api_platform.openapi.normalizer.api_gateway" class="ApiPlatform\Core\Swagger\Serializer\ApiGatewayNormalizer" public="false" decorates="api_platform.openapi.normalizer" decoration-priority="-1"> | ||
| <argument type="service" id="api_platform.openapi.normalizer.api_gateway.inner" /> | ||
| <tag name="serializer.normalizer" priority="-780" /> | ||
| </service> | ||
| </services> | ||
|
|
||
| </container> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * This file is part of the API Platform project. | ||
| * | ||
| * (c) Kévin Dunglas <dunglas@gmail.com> | ||
| * | ||
| * For the full copyright and license information, please view the LICENSE | ||
| * file that was distributed with this source code. | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace ApiPlatform\Core\DataProvider; | ||
|
|
||
| final class PaginationOptions | ||
| { | ||
| private $paginationEnabled; | ||
| private $paginationPageParameterName; | ||
| private $clientItemsPerPage; | ||
| private $itemsPerPageParameterName; | ||
| private $paginationClientEnabled; | ||
| private $paginationClientEnabledParameterName; | ||
|
|
||
| public function __construct(bool $paginationEnabled = true, string $paginationPageParameterName = 'page', bool $clientItemsPerPage = false, string $itemsPerPageParameterName = 'itemsPerPage', bool $paginationClientEnabled = false, string $paginationClientEnabledParameterName = 'pagination') | ||
| { | ||
| $this->paginationEnabled = $paginationEnabled; | ||
| $this->paginationPageParameterName = $paginationPageParameterName; | ||
| $this->clientItemsPerPage = $clientItemsPerPage; | ||
| $this->itemsPerPageParameterName = $itemsPerPageParameterName; | ||
| $this->paginationClientEnabled = $paginationClientEnabled; | ||
| $this->paginationClientEnabledParameterName = $paginationClientEnabledParameterName; | ||
| } | ||
|
|
||
| public function isPaginationEnabled(): bool | ||
| { | ||
| return $this->paginationEnabled; | ||
| } | ||
|
|
||
| public function getPaginationPageParameterName(): string | ||
| { | ||
| return $this->paginationPageParameterName; | ||
| } | ||
|
|
||
| public function getClientItemsPerPage(): bool | ||
| { | ||
| return $this->clientItemsPerPage; | ||
| } | ||
|
|
||
| public function getItemsPerPageParameterName(): string | ||
| { | ||
| return $this->itemsPerPageParameterName; | ||
| } | ||
|
|
||
| public function getPaginationClientEnabled(): bool | ||
| { | ||
| return $this->paginationClientEnabled; | ||
| } | ||
|
|
||
| public function getPaginationClientEnabledParameterName(): string | ||
| { | ||
| return $this->paginationClientEnabledParameterName; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.