'Fail to load swagger-ui assets with rswag gem on Rails 5.2.4, a routing issue?

I recently added Swagger gem (rswag) to my application, but I face a strange behaviour:

  • When I type '/api-docs' after the server url (http://s721108907b.adresse.ch/api-docs) , Swagger shows up without any issue
Started GET "/api-docs/swagger-ui-standalone-preset.js" for 10.222.14.33 at 2022-02-17 08:42:27 +0100
Started GET "/api-docs/swagger-ui-bundle.js" for 10.222.14.33 at 2022-02-17 08:42:27 +0100
Started GET "/api-docs/v1/swagger.yaml" for 10.222.14.33 at 2022-02-17 08:42:27 +0100
  • When I add a link to rswag_ui_path in the administration page, Swagger does not show up and raises assets loading errors, eventhough the link generates the same URL.

    <%= link_to t('Swagger API'), rswag_ui_path, class: "nav-link" %> generates the href="/api-docs" html link.

ActionController::RoutingError (No route matches [GET] "/swagger-ui.css") 
ActionController::RoutingError (No route matches [GET] "/swagger-ui-standalone-preset.js") 
ActionController::RoutingError (No route matches [GET] "/swagger-ui-bundle.js")

Here are the routes defined by default at install:

route.rb

DataQualityManager::Application.routes.draw do

  mount Rswag::Ui::Engine => '/api-docs'
  mount Rswag::Api::Engine => '/api-docs'

Clicking the link generated by rswag_ui_path produces a blank page. When refreshing this page, Swagger shows up correctly.

I don't understand what's going on, your help would be welcome!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source