Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
43 changed files
with
4,299 additions
and
27 deletions.
There are no files selected for viewing
This file contains 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 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,92 @@ | ||
<?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->create(), '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) ?: ''); | ||
|
||
if (!($filename = $input->getOption('output')) && \is_string($filename)) { | ||
$filesystem->dumpFile($filename, $content); | ||
$io->success(sprintf('Data written to %s.', $filename)); | ||
|
||
return 0; | ||
} | ||
|
||
$output->writeln($content); | ||
|
||
return 0; | ||
} | ||
} |
This file contains 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 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 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 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 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 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,67 @@ | ||
<?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; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
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 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 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.