|
13 | 13 |
|
14 | 14 | namespace ApiPlatform\Laravel;
|
15 | 15 |
|
16 |
| -use ApiPlatform\Documentation\Action\DocumentationAction; |
17 |
| -use ApiPlatform\Documentation\Action\EntrypointAction; |
18 | 16 | use ApiPlatform\GraphQl\Error\ErrorHandler as GraphQlErrorHandler;
|
19 | 17 | use ApiPlatform\GraphQl\Error\ErrorHandlerInterface;
|
20 | 18 | use ApiPlatform\GraphQl\Executor;
|
|
72 | 70 | use ApiPlatform\JsonSchema\SchemaFactoryInterface;
|
73 | 71 | use ApiPlatform\Laravel\ApiResource\Error;
|
74 | 72 | use ApiPlatform\Laravel\Controller\ApiPlatformController;
|
| 73 | +use ApiPlatform\Laravel\Controller\DocumentationController; |
| 74 | +use ApiPlatform\Laravel\Controller\EntrypointController; |
75 | 75 | use ApiPlatform\Laravel\Eloquent\Extension\FilterQueryExtension;
|
76 | 76 | use ApiPlatform\Laravel\Eloquent\Extension\QueryExtensionInterface;
|
77 | 77 | use ApiPlatform\Laravel\Eloquent\Filter\DateFilter;
|
@@ -321,6 +321,11 @@ public function register(): void
|
321 | 321 | $this->app->singleton(ResourceMetadataCollectionFactoryInterface::class, function (Application $app) {
|
322 | 322 | /** @var ConfigRepository */
|
323 | 323 | $config = $app['config'];
|
| 324 | + $formats = $config->get('api-platform.formats'); |
| 325 | + |
| 326 | + if ($config->get('api-platform.swagger_ui.enabled', false) && !isset($formats['html'])) { |
| 327 | + $formats['html'] = ['text/html']; |
| 328 | + } |
324 | 329 |
|
325 | 330 | return new CacheResourceCollectionMetadataFactory(
|
326 | 331 | new EloquentResourceCollectionMetadataFactory(
|
@@ -361,7 +366,7 @@ public function register(): void
|
361 | 366 | )
|
362 | 367 | )
|
363 | 368 | ),
|
364 |
| - $config->get('api-platform.formats'), |
| 369 | + $formats, |
365 | 370 | $config->get('api-platform.patch_formats'),
|
366 | 371 | )
|
367 | 372 | )
|
@@ -417,7 +422,10 @@ public function register(): void
|
417 | 422 | });
|
418 | 423 |
|
419 | 424 | $this->app->singleton(SwaggerUiProvider::class, function (Application $app) {
|
420 |
| - return new SwaggerUiProvider($app->make(ReadProvider::class), $app->make(OpenApiFactoryInterface::class)); |
| 425 | + /** @var ConfigRepository */ |
| 426 | + $config = $app['config']; |
| 427 | + |
| 428 | + return new SwaggerUiProvider($app->make(ReadProvider::class), $app->make(OpenApiFactoryInterface::class), $config->get('api-platform.swagger_ui.enabled', false)); |
421 | 429 | });
|
422 | 430 |
|
423 | 431 | $this->app->singleton(ValidateProvider::class, function (Application $app) {
|
@@ -476,9 +484,14 @@ public function register(): void
|
476 | 484 |
|
477 | 485 | $this->app->tag([RemoveProcessor::class, PersistProcessor::class], ProcessorInterface::class);
|
478 | 486 | $this->app->singleton(CallableProcessor::class, function (Application $app) {
|
| 487 | + /** @var ConfigRepository */ |
| 488 | + $config = $app['config']; |
479 | 489 | $tagged = iterator_to_array($app->tagged(ProcessorInterface::class));
|
480 |
| - // TODO: tag SwaggerUiProcessor instead? |
481 |
| - $tagged['api_platform.swagger_ui.processor'] = $app->make(SwaggerUiProcessor::class); |
| 490 | + |
| 491 | + if ($config->get('api-platform.swagger_ui.enabled', false)) { |
| 492 | + // TODO: tag SwaggerUiProcessor instead? |
| 493 | + $tagged['api_platform.swagger_ui.processor'] = $app->make(SwaggerUiProcessor::class); |
| 494 | + } |
482 | 495 |
|
483 | 496 | return new CallableProcessor(new ServiceLocator($tagged));
|
484 | 497 | });
|
@@ -628,18 +641,18 @@ public function register(): void
|
628 | 641 | return new Options(title: $config->get('api-platform.title') ?? '');
|
629 | 642 | });
|
630 | 643 |
|
631 |
| - $this->app->singleton(DocumentationAction::class, function (Application $app) { |
| 644 | + $this->app->singleton(DocumentationController::class, function (Application $app) { |
632 | 645 | /** @var ConfigRepository */
|
633 | 646 | $config = $app['config'];
|
634 | 647 |
|
635 |
| - return new DocumentationAction($app->make(ResourceNameCollectionFactoryInterface::class), $config->get('api-platform.title') ?? '', $config->get('api-platform.description') ?? '', $config->get('api-platform.version') ?? '', $app->make(OpenApiFactoryInterface::class), $app->make(ProviderInterface::class), $app->make(ProcessorInterface::class), $app->make(Negotiator::class), $config->get('api-platform.docs_formats')); |
| 648 | + return new DocumentationController($app->make(ResourceNameCollectionFactoryInterface::class), $config->get('api-platform.title') ?? '', $config->get('api-platform.description') ?? '', $config->get('api-platform.version') ?? '', $app->make(OpenApiFactoryInterface::class), $app->make(ProviderInterface::class), $app->make(ProcessorInterface::class), $app->make(Negotiator::class), $config->get('api-platform.docs_formats'), $config->get('api-platform.swagger_ui.enabled', false)); |
636 | 649 | });
|
637 | 650 |
|
638 |
| - $this->app->singleton(EntrypointAction::class, function (Application $app) { |
| 651 | + $this->app->singleton(EntrypointController::class, function (Application $app) { |
639 | 652 | /** @var ConfigRepository */
|
640 | 653 | $config = $app['config'];
|
641 | 654 |
|
642 |
| - return new EntrypointAction($app->make(ResourceNameCollectionFactoryInterface::class), $app->make(ProviderInterface::class), $app->make(ProcessorInterface::class), $config->get('api-platform.docs_formats')); |
| 655 | + return new EntrypointController($app->make(ResourceNameCollectionFactoryInterface::class), $app->make(ProviderInterface::class), $app->make(ProcessorInterface::class), $config->get('api-platform.docs_formats')); |
643 | 656 | });
|
644 | 657 |
|
645 | 658 | $this->app->singleton(Pagination::class, function (Application $app) {
|
@@ -1144,17 +1157,16 @@ public function boot(ResourceNameCollectionFactoryInterface $resourceNameCollect
|
1144 | 1157 | $route = new Route(['GET'], $prefix.'/contexts/{shortName?}{_format?}', [ContextAction::class, '__invoke']);
|
1145 | 1158 | $route->name('api_jsonld_context')->middleware(ApiPlatformMiddleware::class);
|
1146 | 1159 | $routeCollection->add($route);
|
1147 |
| - // Maybe that we can alias Symfony Request to Laravel Request within the provider ? |
1148 | 1160 | $route = new Route(['GET'], $prefix.'/docs{_format?}', function (Request $request, Application $app) {
|
1149 |
| - $documentationAction = $app->make(DocumentationAction::class); |
| 1161 | + $documentationAction = $app->make(DocumentationController::class); |
1150 | 1162 |
|
1151 | 1163 | return $documentationAction->__invoke($request);
|
1152 | 1164 | });
|
1153 | 1165 | $route->name('api_doc')->middleware(ApiPlatformMiddleware::class);
|
1154 | 1166 | $routeCollection->add($route);
|
1155 | 1167 |
|
1156 | 1168 | $route = new Route(['GET'], $prefix.'/{index?}{_format?}', function (Request $request, Application $app) {
|
1157 |
| - $entrypointAction = $app->make(EntrypointAction::class); |
| 1169 | + $entrypointAction = $app->make(EntrypointController::class); |
1158 | 1170 |
|
1159 | 1171 | return $entrypointAction->__invoke($request);
|
1160 | 1172 | });
|
|
0 commit comments