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, notdrupal-library. composer/installershas no rule for a plainlibrary, so it installs tovendor/swagger-api/swagger-ui, where nothing can serve it.- The Varbase project worked around that by also fetching
swagger-ui-distfrom npm and copying it intoweb/librarieswith adrupal-libraries-sync.jsscript, so the same library was downloaded twice, once uselessly.
Two workarounds were tried and rejected:
oomphinc/composer-installers-extendercannot place it: addinglibrarytoinstaller-typesmakescomposer/installersclaim every library-type package in the tree and abort withPackage type "library" is not supported(measured).mnsami/composer-custom-directory-installerplus a per-packageinstaller-pathsentry does work, but puts an extra Composer plugin and a named path in every consuming project'scomposer.json. That has been rejected: a front-end library must arrive correctly out of the box.
Steps to reproduce
- On a Drupal 11 project whose only library installer path is the generic
"web/libraries/{$name}": ["type:drupal-library"], apply this recipe or requiredrupal/openapi_ui_swagger. - Look for
web/libraries/swagger-ui/dist/swagger-ui-bundle.js. It is absent. - Look in
vendor/swagger-api/swagger-ui. The distribution is there, unreachable by the browser. - 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-apiis absent: thereplacesatisfiesdrupal/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_uiresolves all 3 of its assets.vendor/swagger-apidoes 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-uiso the recipe brings the Swagger UI front-end library itself, intoweb/libraries/swagger-ui, with no extra Composer plugin or per-package installer path. Itsreplaceofswagger-api/swagger-uialso removes the duplicate download.
Issue fork varbase_api_base-3620376
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
Comment #2
rajab natshahComment #4
rajab natshahComment #5
rajab natshah