You are here

public function OpenApiGeneratorBase::getSpecification in OpenAPI 8

Same name and namespace in other branches
  1. 8.2 src/Plugin/openapi/OpenApiGeneratorBase.php \Drupal\openapi\Plugin\openapi\OpenApiGeneratorBase::getSpecification()

Generates OpenAPI specification.

Return value

array The specification output.

Overrides OpenApiGeneratorInterface::getSpecification

1 call to OpenApiGeneratorBase::getSpecification()
RestGenerator::nonBundleResourcesJson in src/Plugin/openapi/OpenApiGenerator/RestGenerator.php
Return resources for non-entity resources.

File

src/Plugin/openapi/OpenApiGeneratorBase.php, line 199

Class

OpenApiGeneratorBase
Defines base class for OpenApi Generator plugins.

Namespace

Drupal\openapi\Plugin\openapi

Code

public function getSpecification() {
  $basePath = $this
    ->getBasePath();
  $spec = [
    'swagger' => "2.0",
    'schemes' => [
      $this->request
        ->getScheme(),
    ],
    'info' => $this
      ->getInfo(),
    'host' => $this->request
      ->getHttpHost(),
    'basePath' => empty($basePath) ? '/' : $basePath,
    'securityDefinitions' => $this
      ->getSecurityDefinitions(),
    'security' => $this
      ->getSecurity(),
    'tags' => $this
      ->getTags(),
    'definitions' => $this
      ->getDefinitions(),
    'consumes' => $this
      ->getConsumes(),
    'produces' => $this
      ->getProduces(),
    'paths' => $this
      ->getPaths(),
  ];

  // Strip any empty arrays which aren't required.
  $required = [
    'swagger',
    'info',
    'paths',
  ];
  foreach ($spec as $key => $item) {
    if (!in_array($key, $required) && is_array($item) && !count($item)) {
      unset($spec[$key]);
    }
  }
  return $spec;
}