github.com/argoproj/argo-cd@v1.8.7/util/swagger/swagger.go (about) 1 package swagger 2 3 import ( 4 "fmt" 5 "net/http" 6 "path" 7 8 "github.com/go-openapi/runtime/middleware" 9 ) 10 11 // filename of ReDoc script in UI's assets/scripts path 12 const redocScriptName = "redoc.standalone.js" 13 14 // ServeSwaggerUI serves the Swagger UI and JSON spec. 15 func ServeSwaggerUI(mux *http.ServeMux, swaggerJSON string, uiPath string, rootPath string) { 16 prefix := path.Dir(uiPath) 17 swaggerPath := path.Join(prefix, "swagger.json") 18 mux.HandleFunc(swaggerPath, func(w http.ResponseWriter, r *http.Request) { 19 _, _ = fmt.Fprint(w, swaggerJSON) 20 }) 21 22 specURL := path.Join(prefix, rootPath, "swagger.json") 23 scriptURL := path.Join(prefix, rootPath, "assets", "scripts", redocScriptName) 24 mux.Handle(uiPath, middleware.Redoc(middleware.RedocOpts{ 25 BasePath: prefix, 26 SpecURL: specURL, 27 Path: path.Base(uiPath), 28 RedocURL: scriptURL, 29 }, http.NotFoundHandler())) 30 }