This repository has been archived by the owner on Nov 29, 2022. It is now read-only.
forked from api-platform/core
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add
swagger_ui_extra_configuration
to Swagger configuration (api-pl…
…atform#3731) (cherry picked from commit 930c930)
- Loading branch information
Showing
6 changed files
with
84 additions
and
5 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
namespace ApiPlatform\Core\Bridge\Symfony\Bundle\Action; | ||
|
||
use ApiPlatform\Core\Api\FormatsProviderInterface; | ||
use ApiPlatform\Core\Bridge\Symfony\Bundle\SwaggerUi\SwaggerUiAction as OpenApiSwaggerUiAction; | ||
use ApiPlatform\Core\Documentation\Documentation; | ||
use ApiPlatform\Core\Exception\RuntimeException; | ||
use ApiPlatform\Core\Metadata\Resource\Factory\ResourceMetadataFactoryInterface; | ||
|
@@ -28,6 +29,8 @@ | |
/** | ||
* Displays the documentation. | ||
* | ||
* @deprecated please refer to ApiPlatform\Core\Bridge\Symfony\Bundle\SwaggerUi\SwaggerUiAction for further changes | ||
* | ||
* @author Kévin Dunglas <[email protected]> | ||
*/ | ||
final class SwaggerUiAction | ||
|
@@ -57,11 +60,15 @@ final class SwaggerUiAction | |
private $graphiQlEnabled; | ||
private $graphQlPlaygroundEnabled; | ||
private $swaggerVersions; | ||
private $swaggerUiAction; | ||
private $assetPackage; | ||
private $swaggerUiExtraConfiguration; | ||
|
||
/** | ||
* @param int[] $swaggerVersions | ||
* @param int[] $swaggerVersions | ||
* @param mixed|null $assetPackage | ||
*/ | ||
public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, NormalizerInterface $normalizer, TwigEnvironment $twig, UrlGeneratorInterface $urlGenerator, string $title = '', string $description = '', string $version = '', $formats = [], $oauthEnabled = false, $oauthClientId = '', $oauthClientSecret = '', $oauthType = '', $oauthFlow = '', $oauthTokenUrl = '', $oauthAuthorizationUrl = '', $oauthScopes = [], bool $showWebby = true, bool $swaggerUiEnabled = false, bool $reDocEnabled = false, bool $graphqlEnabled = false, bool $graphiQlEnabled = false, bool $graphQlPlaygroundEnabled = false, array $swaggerVersions = [2, 3]) | ||
public function __construct(ResourceNameCollectionFactoryInterface $resourceNameCollectionFactory, ResourceMetadataFactoryInterface $resourceMetadataFactory, NormalizerInterface $normalizer, TwigEnvironment $twig, UrlGeneratorInterface $urlGenerator, string $title = '', string $description = '', string $version = '', $formats = [], $oauthEnabled = false, $oauthClientId = '', $oauthClientSecret = '', $oauthType = '', $oauthFlow = '', $oauthTokenUrl = '', $oauthAuthorizationUrl = '', $oauthScopes = [], bool $showWebby = true, bool $swaggerUiEnabled = false, bool $reDocEnabled = false, bool $graphqlEnabled = false, bool $graphiQlEnabled = false, bool $graphQlPlaygroundEnabled = false, array $swaggerVersions = [2, 3], OpenApiSwaggerUiAction $swaggerUiAction = null, $assetPackage = null, array $swaggerUiExtraConfiguration = []) | ||
{ | ||
$this->resourceNameCollectionFactory = $resourceNameCollectionFactory; | ||
$this->resourceMetadataFactory = $resourceMetadataFactory; | ||
|
@@ -86,19 +93,30 @@ public function __construct(ResourceNameCollectionFactoryInterface $resourceName | |
$this->graphiQlEnabled = $graphiQlEnabled; | ||
$this->graphQlPlaygroundEnabled = $graphQlPlaygroundEnabled; | ||
$this->swaggerVersions = $swaggerVersions; | ||
$this->swaggerUiAction = $swaggerUiAction; | ||
$this->swaggerUiExtraConfiguration = $swaggerUiExtraConfiguration; | ||
$this->assetPackage = $assetPackage; | ||
|
||
if (null === $this->swaggerUiAction) { | ||
@trigger_error(sprintf('The use of "%s" is deprecated since API Platform 2.6, use "%s" instead.', __CLASS__, OpenApiSwaggerUiAction::class), \E_USER_DEPRECATED); | ||
} | ||
|
||
if (\is_array($formats)) { | ||
$this->formats = $formats; | ||
|
||
return; | ||
} | ||
|
||
@trigger_error(sprintf('Passing an array or an instance of "%s" as 5th parameter of the constructor of "%s" is deprecated since API Platform 2.5, pass an array instead', FormatsProviderInterface::class, __CLASS__), E_USER_DEPRECATED); | ||
@trigger_error(sprintf('Passing an array or an instance of "%s" as 5th parameter of the constructor of "%s" is deprecated since API Platform 2.5, pass an array instead', FormatsProviderInterface::class, __CLASS__), \E_USER_DEPRECATED); | ||
$this->formatsProvider = $formats; | ||
} | ||
|
||
public function __invoke(Request $request) | ||
{ | ||
if ($this->swaggerUiAction) { | ||
return $this->swaggerUiAction->__invoke($request); | ||
} | ||
|
||
$attributes = RequestAttributesExtractor::extractAttributes($request); | ||
|
||
// BC check to be removed in 3.0 | ||
|
@@ -130,6 +148,7 @@ private function getContext(Request $request, Documentation $documentation): arr | |
'graphqlEnabled' => $this->graphqlEnabled, | ||
'graphiQlEnabled' => $this->graphiQlEnabled, | ||
'graphQlPlaygroundEnabled' => $this->graphQlPlaygroundEnabled, | ||
'assetPackage' => $this->assetPackage, | ||
]; | ||
|
||
$swaggerContext = ['spec_version' => $request->query->getInt('spec_version', $this->swaggerVersions[0] ?? 2)]; | ||
|
@@ -140,6 +159,7 @@ private function getContext(Request $request, Documentation $documentation): arr | |
$swaggerData = [ | ||
'url' => $this->urlGenerator->generate('api_doc', ['format' => 'json']), | ||
'spec' => $this->normalizer->normalize($documentation, 'json', $swaggerContext), | ||
'extraConfiguration' => $this->swaggerUiExtraConfiguration, | ||
]; | ||
|
||
$swaggerData['oauth'] = [ | ||
|
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