DEXPRO-Solutions-GmbH / swaggerui

Gin handler to expose an OpenAPI spec via Swagger UI
Apache License 2.0
0 stars 0 forks source link

Path `swaggerui` does not serve openapi.yml #10

Open fabiante opened 1 year ago

fabiante commented 1 year ago

Oops, the change in #3 wasn't properly tested. While the swagger ui correctly loads all assets under the new swaggerui path, it does not properly load the openAPI spec:

grafik

The issue is with https://github.com/DEXPRO-Solutions-GmbH/swaggerui/blob/5230764fa6007093f2e3e4d44aeeac5cf7526a71/dist/swagger-initializer.js#L6

Swagger UI expects to run under the swagger-ui path.

fabiante commented 1 year ago

One fix would be to support both path, which requires changing swagger-initializer.js:

  let basePrefixIndex = document.URL.indexOf("swagger-ui/");
  if (basePrefixIndex == -1) {
    basePrefixIndex = document.URL.indexOf("swaggerui/");
  }

  var openApiUrl = document.URL.substr(0, basePrefixIndex) + "openapi.yml";
fabiante commented 1 year ago

The other option is to use an HTTP redirect from swaggerui to swagger-ui. That has the benefit of not having to modify the dist directory which is better for maintenance.