mirror of
https://github.com/argoproj/argo-cd.git
synced 2026-02-20 01:28:45 +01:00
* chore: enable unused-parameter from revive Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> * apply recommandations Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com> --------- Signed-off-by: Matthieu MOREL <matthieu.morel35@gmail.com>
31 lines
869 B
Go
31 lines
869 B
Go
package swagger
|
|
|
|
import (
|
|
"fmt"
|
|
"net/http"
|
|
"path"
|
|
|
|
"github.com/go-openapi/runtime/middleware"
|
|
)
|
|
|
|
// filename of ReDoc script in UI's assets/scripts path
|
|
const redocScriptName = "redoc.standalone.js"
|
|
|
|
// ServeSwaggerUI serves the Swagger UI and JSON spec.
|
|
func ServeSwaggerUI(mux *http.ServeMux, swaggerJSON string, uiPath string, rootPath string) {
|
|
prefix := path.Dir(uiPath)
|
|
swaggerPath := path.Join(prefix, "swagger.json")
|
|
mux.HandleFunc(swaggerPath, func(w http.ResponseWriter, _ *http.Request) {
|
|
_, _ = fmt.Fprint(w, swaggerJSON)
|
|
})
|
|
|
|
specURL := path.Join(prefix, rootPath, "swagger.json")
|
|
scriptURL := path.Join(prefix, rootPath, "assets", "scripts", redocScriptName)
|
|
mux.Handle(uiPath, middleware.Redoc(middleware.RedocOpts{
|
|
BasePath: prefix,
|
|
SpecURL: specURL,
|
|
Path: path.Base(uiPath),
|
|
RedocURL: scriptURL,
|
|
}, http.NotFoundHandler()))
|
|
}
|