swagger-api/swagger-ui library installation difficulty

Created on 4 February 2022, almost 3 years ago
Updated 12 April 2024, 7 months ago

Problem/Motivation

Instructions for dependency library installation no longer appear to work properly. One possibility is the issue of dynamic package path issues in composer/installers.

Steps to reproduce

From the homepage:

Installation with Composer

To install the library via composer, you will need to configure composer to put the library in the correct location for Drupal. This requests the composer/installers and mnsami/composer-custom-directory-installer packages. You can run the following command to ensure they are installed.

composer require composer/installers mnsami/composer-custom-directory-installer

Then modify your project's composer.json to include the following configuration.

"extra": {
  "installer-paths": {
    ...
    "web/libraries/{$name}": ["swagger-api/swagger-ui", "type:drupal-library"],
    ...
  }
}

I did both of those things, and then

composer require 'drupal/openapi_ui_swagger:1.x-dev@dev'

When I visit the openapi page view with swagger at /admin/config/services/openapi/swagger/jsonapi I get an empty page. I think I am missing the actual swagger library but I want to do it withe composer. Is there a composer command missing from the above instructions to install the library from github in the "do it with composer" section?

Proposed resolution

Because swagger-api/swagger-ui is not published as "type": "drupal-module", it is being installed in the /vendor directory. Following an example from drupal/telephone_international_widget propose the inclusion of new file composer.libraries.json to define a custom drupal library repository to pull the library and install where needed as expected when installing the module.

Steps to complete

This requires Composer Merge Plugin plugin available on GitHub.
composer require wikimedia/composer-merge-plugin

Edit the composer.json file of your website and under the "extra": {} section add:

// *Note: the web/ directory represents the Drupal root

"merge-plugin": {
  "include": [
    "web/modules/contrib/openapi_ui_swagger/composer.libraries.json"
  ]
},

From now on, every time the composer.json file is updated, it will also read the content of composer.libraries.json file located at web/modules/contrib/openapi_ui_swagger/ and update accordingly.

Remaining tasks

- Create fork to implement changes (pending)
- Update documentation page

πŸ’¬ Support request
Status

Postponed: needs info

Version

1.0

Component

User interface

Created by

πŸ‡¬πŸ‡§United Kingdom Syntapse

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡³πŸ‡±Netherlands ricovandevin

    I thought I stumbled upon this issue too. But after trying some other options I finally discovered that I made a mistake in composer.json. After fixing that mistake it works as designed. According to the instructions in the docs. So this seems a "works as designed" to me. But setting the issue status to "maintainer needs more info" to allow for providing more information on specific cases in which it does not work.

  • πŸ‡ΊπŸ‡ΈUnited States afinnarn

    I just deleted the `swagger_ui` library in my libraries directory and re-ran `composer install` which correctly placed the library again. I will post what I have in my composer.json.

            "installer-paths": {
                "docroot/core": [
                    "type:drupal-core"
                ],
                "docroot/libraries/{$name}": [
                    "swagger-api/swagger-ui",
                    "type:drupal-library",
                    "type:bower-asset",
                    "type:npm-asset"
                ],
    

    Here you can see "swagger-api/swagger-ui" added before the other installer path entries for "docroot/libraries". I'm not sure if that helps or not, but I had no problems with following the directions as they are written now in the documentation.

Production build 0.71.5 2024