src/Platform/Controller/ApiDocsController.php line 19

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace App\Platform\Controller;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Response;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
  8. class ApiDocsController extends AbstractController
  9. {
  10.     public function __construct(private UrlGeneratorInterface $urlGenerator)
  11.     {
  12.     }
  13.     #[Route(path'/api-docs/swagger'name'api-docs.swagger')]
  14.     public function swagger(): Response
  15.     {
  16.         return $this->render('@base/api-docs/swagger.html.twig', [
  17.             'yamlUrl' => $this->generateUrl('api-docs.yaml', [
  18.                 'major' => 0,
  19.                 'minor' => 1,
  20.                 'fix'   => 0,
  21.             ]),
  22.         ]);
  23.     }
  24.     #[Route(path'/api-docs/redoc'name'api-docs.redoc')]
  25.     public function redoc(): Response
  26.     {
  27.         return $this->render('@base/api-docs/redoc.html.twig', [
  28.             'yamlUrl' => $this->generateUrl('api-docs.yaml', [
  29.                 'major' => 0,
  30.                 'minor' => 1,
  31.                 'fix'   => 0,
  32.             ]),
  33.         ]);
  34.     }
  35.     #[Route(path'/api-docs/elements'name'api-docs.elements')]
  36.     public function elements(): Response
  37.     {
  38.         return $this->render('@base/api-docs/elements.html.twig', [
  39.             'yamlUrl' => $this->generateUrl('api-docs.yaml', [
  40.                 'major' => 0,
  41.                 'minor' => 1,
  42.                 'fix'   => 0,
  43.             ]),
  44.         ]);
  45.     }
  46.     #[Route(path'/api-docs/yaml/{major}/{minor}/{fix}'name'api-docs.yaml')]
  47.     public function yaml(int $majorint $minorint $fix): Response
  48.     {
  49.         return $this->render(sprintf("@base/api-docs/yaml/v%s.%s.%s.openapi.yaml"$major$minor$fix), [
  50.             'baseUrl' => $this->urlGenerator->generate('index', [], 0) . 'api/v1',
  51.         ]);
  52.     }
  53. }