You are here

ApiSpecificationController.php in OpenAPI 8

Same filename and directory in other branches
  1. 8.2 src/Controller/ApiSpecificationController.php

File

src/Controller/ApiSpecificationController.php
View source
<?php

namespace Drupal\openapi\Controller;

use Drupal\Core\Controller\ControllerBase;
use Drupal\openapi\Plugin\openapi\OpenApiGeneratorInterface;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;

/**
 * API Specification controller base.
 */
class ApiSpecificationController extends ControllerBase {

  /**
   * Gets the OpenAPI output in JSON format.
   *
   * @return string
   *   The page title.
   */
  public function title(OpenApiGeneratorInterface $generator, Request $request) {
    return $this
      ->t('%label OpenApi Schema Download', [
      '%label' => $generator
        ->getLabel(),
    ]);
  }

  /**
   * Gets the OpenAPI output in JSON format.
   *
   * @return \Symfony\Component\HttpFoundation\JsonResponse
   *   The JSON response.
   */
  public function getSpecification(OpenApiGeneratorInterface $openapi_generator, Request $request) {
    $options = $request
      ->get('options', []);
    $openapi_generator
      ->setOptions($options);
    $spec = $openapi_generator
      ->getSpecification();
    return new JsonResponse($spec);
  }

}

Classes

Namesort descending Description
ApiSpecificationController API Specification controller base.