Problem/Motivation

drupal/openapi_ui_swagger loads /libraries/swagger-ui/dist/swagger-ui-bundle.js, /libraries/swagger-ui/dist/swagger-ui-standalone-preset.js and /libraries/swagger-ui/dist/swagger-ui.css, and it requires swagger-api/swagger-ui: ^3.0.17 || ^5.0.

  • Upstream publishes that package as Composer type: library, not drupal-library.
  • composer/installers has no rule for a plain library, so it installs to vendor/swagger-api/swagger-ui, where nothing can serve it.
  • The Varbase project worked around that by also fetching swagger-ui-dist from npm and copying it into web/libraries with a drupal-libraries-sync.js script, so the same library was downloaded twice, once uselessly.

Two workarounds were tried and rejected:

  • oomphinc/composer-installers-extender cannot place it: adding library to installer-types makes composer/installers claim every library-type package in the tree and abort with Package type "library" is not supported (measured).
  • mnsami/composer-custom-directory-installer plus a per-package installer-paths entry does work, but puts an extra Composer plugin and a named path in every consuming project's composer.json. That has been rejected: a front-end library must arrive correctly out of the box.

Steps to reproduce

  1. On a Drupal 11 project whose only library installer path is the generic "web/libraries/{$name}": ["type:drupal-library"], apply this recipe or require drupal/openapi_ui_swagger.
  2. Look for web/libraries/swagger-ui/dist/swagger-ui-bundle.js. It is absent.
  3. Look in vendor/swagger-api/swagger-ui. The distribution is there, unreachable by the browser.
  4. Visit the Swagger UI page provided by openapi_ui_swagger. Its 3 declared assets do not resolve.

Proposed resolution

Require vardot/swagger-ui (github.com/Vardot/swagger-ui), a dist-only repackage of the same Swagger UI 5.32.14 distribution that declares type: drupal-library and:

"replace": { "swagger-api/swagger-ui": "self.version" }

Two consequences, both measured in a scratch project whose only installer path was the generic "web/libraries/{$name}": ["type:drupal-library"]:

  • The files land at web/libraries/swagger-ui/dist/…, exactly where the module looks, with no plugin and no per-package path.
  • vendor/swagger-api is absent: the replace satisfies drupal/openapi_ui_swagger's requirement, so the upstream package is never downloaded and the duplicate is gone.

The require belongs in this recipe rather than in the project template, because the replace only takes effect if something actually requires vardot/swagger-ui. A project that merely requires drupal/openapi_ui_swagger still resolves the upstream package into vendor/. This recipe is what installs the module, so it is what must require the library.

That also matches the pattern the sibling recipes now follow, each recipe bringing the library its modules load:

  • Varbase Admin Base requires vardot/jquery.fancytree
  • Varbase Content Base requires vardot/aos
  • Varbase Media Base requires vardot/dropzone
  • Varbase Editor Base requires vardot/ckeditor5-media-embed-drupal

Wider context: this is part of moving Varbase 11 off the drupal-libraries-sync.js npm-copy script onto Composer drupal-library packages. Related issues: #3620350 (Varbase Project), #3620357 (Varbase Starter), #3620360 (Varbase Admin Base), #3620361 (Varbase Content Base), #3620362 (Varbase Editor Base), #3620363 (Varbase Media Base).

Verification

On a freshly installed Varbase 11.4.5 site in DDEV with all six libraries resolved from Packagist and no plugin and no per-package installer paths in the root composer.json:

  • 14 of 14 declared library files are present.
  • openapi_ui_swagger/swagger_ui resolves all 3 of its assets.
  • vendor/swagger-api does not exist.

Remaining tasks

  • ✅ File an issue
  • ✅ Addition/Change/Update/Fix
  • ✅ Testing to ensure no regression
  • ➖ Automated unit/functional testing coverage
  • ➖ Developer Documentation support
  • ➖ User Guide Documentation support
  • ➖ UX/UI designer responsibilities
  • ➖ Accessibility and Readability
  • ❌ Reviewed by a human
  • ❌ Code review by maintainers
  • ❌ Full testing and approval
  • ❌ Credit contributors
  • ❌ Review with the product owner
  • ❌ Update Release Notes
  • ❌ Release

User interface changes

  • N/A

API changes

  • N/A

Data model changes

  • N/A

Release notes snippet

  • Require vardot/swagger-ui so the recipe brings the Swagger UI front-end library itself, into web/libraries/swagger-ui, with no extra Composer plugin or per-package installer path. Its replace of swagger-api/swagger-ui also removes the duplicate download.
Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rajab natshah created an issue. See original summary.

rajab natshah’s picture

Title: feat: Require the vardot/swagger-ui library, so the recipe brings its own front-end library » feat: #3620376 Require the vardot/swagger-ui library, so the recipe brings its own front-end library

rajab natshah’s picture

Assigned: Unassigned » rajab natshah
Status: Active » Needs review
rajab natshah’s picture

Title: feat: #3620376 Require the vardot/swagger-ui library, so the recipe brings its own front-end library » Require the vardot/swagger-ui library, so the recipe brings its own front-end library

  • rajab natshah committed 2cdeed94 on 1.0.x
    feat: #3620376 Require the vardot/swagger-ui library, so the recipe...