Changing the default API specification URL in the Swagger interface

I am using the Docker image of the Swagger Editor to define my API specification and create a nodejs server to run as an api stub and provide documentation for the API specification.

I would like to know if it is possible to change the default url for my own to present my spec when opening the page and how I will do it.

enter image description here

For example, I would like to change the default address to http://localhost:8080/spec

+1
source share
1 answer

, Swagger Codegen Node.js. , npm start Swagger, , (URL- ) http://localhost:8080/ spec http://localhost/ api-docs.

, .yaml, index.js :

// 1 - add swaggerUi options
var uiOptions = {
  apiDocs: '/spec'  // <-- override the default /api-docs
};

swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
  ...

  // 2 - pass these options to swaggerUi
  app.use(middleware.swaggerUi(uiOptions));

serverPort index.js:

var serverPort = 8080;
+1

Source: https://habr.com/ru/post/1691914/


All Articles