This Drupal module provides a field formatter for File and Link type fields which renders the referenced file using Swagger UI if the file is a valid Swagger file. Supported file types are JSON (.json) and/or YAML (.yml or .yaml).
This module can be used to show API Documentation created using Swagger or Open API Specification, on any Drupal Website.
Requirements
This module uses the Swagger UI JavaScript library.
Please note that the minimum supported Swagger UI library version is currently 4.15.0 as at the time of the latest module release that's the latest version which includes security fixes.
Module installation
Install the Swagger UI Field Formatter module as you would normally install a contributed Drupal module. Visit the official Installing Modules documentation for further information.
Swagger UI library installation
Manual installation
Download the appropriate Swagger UI library version extract the archive and rename the folder to "swagger-ui". Place the renamed folder into the [DRUPAL ROOT]/libraries directory so its path will be [DRUPAL ROOT]/libraries/swagger-ui.
Installation via Composer
If you would like to install the Swagger UI library with Composer, you probably used the Project template for Drupal 8 projects to set up your project. To install JavaScript libraries, it's recommended to use the asset-packagist repository. So you will need to add the following to your composer.json file in the "repositories" section:
{
"type": "composer",
"url": "https://asset-packagist.org"
}
It's also needed to extend the "extra/installer-paths" section with:
"web/libraries/{$name}": [
"type:drupal-library",
"type:bower-asset",
"type:npm-asset"
],
"web/libraries/swagger-ui": ["bower-asset/swagger-ui"],
And add a new "installer-types" section next to "extra/installer-paths":
"installer-types": ["bower-asset", "npm-asset"],
After this you can install the library with the following command:
composer require oomphinc/composer-installers-extender bower-asset/swagger-ui
The library will be downloaded into the [DRUPAL ROOT]/libraries directory.
Version information
4.x
For Drupal ^9.4.x and Drupal 10.x please use the 4.x releases which contain the latest features and bug fixes.
8.x-3.x
For Swagger UI >=3.32.x support please use the 8.x-3.x releases. This branch is minimally maintained and soon become unsupported.
7.x-2.x
The Drupal 7 compatible branch is not actively maintained and it does not contain all the features the Drupal 8 and 9 compatible releases have.
Development
Development is coordinated in our GitHub repository. The drupal.org issue queue is disabled, we use the GitHub issue queue to coordinate development.