You are here

private function SwaggerUiLibraryDiscovery::validateLibraryDirectory in Swagger UI Field Formatter 8.3

Validates a given Swagger UI library directory.

Parameters

string $library_dir: The directory path which contains the Swagger UI library.

Throws

\Drupal\swagger_ui_formatter\Exception\SwaggerUiLibraryDiscoveryException

1 call to SwaggerUiLibraryDiscovery::validateLibraryDirectory()
SwaggerUiLibraryDiscovery::libraryDirectory in src/Service/SwaggerUiLibraryDiscovery.php
Gets the Swagger UI library directory.

File

src/Service/SwaggerUiLibraryDiscovery.php, line 153

Class

SwaggerUiLibraryDiscovery
Default Swagger UI library discovery service implementation.

Namespace

Drupal\swagger_ui_formatter\Service

Code

private function validateLibraryDirectory(string $library_dir) : void {
  if (!file_exists($library_dir)) {
    throw SwaggerUiLibraryDiscoveryException::becauseLibraryDirectoryIsInvalid($library_dir);
  }
  $files_to_check = [
    'package.json',
    'dist/swagger-ui.css',
    'dist/swagger-ui-bundle.js',
    'dist/swagger-ui-standalone-preset.js',
    'dist/oauth2-redirect.html',
  ];
  foreach ($files_to_check as $file) {
    $file_path = $library_dir . '/' . $file;
    if (!file_exists($file_path)) {
      throw SwaggerUiLibraryDiscoveryException::becauseRequiredLibraryFileIsNotFound($file_path);
    }
  }
}