diff --git a/docs.go b/docs.go index 2715263..7dce351 100644 --- a/docs.go +++ b/docs.go @@ -19,7 +19,7 @@ func splitDocs(docs string) (title, desc string) { } // RapiDocHandler renders documentation using RapiDoc. -func RapiDocHandler(pageTitle string) http.Handler { +func RapiDocHandler(router *Router) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") w.Write([]byte(fmt.Sprintf(` @@ -31,19 +31,19 @@ func RapiDocHandler(pageTitle string) http.Handler { -`, pageTitle))) +`, router.GetTitle(), router.OpenAPIPath()))) }) } // ReDocHandler renders documentation using ReDoc. -func ReDocHandler(pageTitle string) http.Handler { +func ReDocHandler(router *Router) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") w.Write([]byte(fmt.Sprintf(` @@ -56,15 +56,15 @@ func ReDocHandler(pageTitle string) http.Handler { - + -`, pageTitle))) +`, router.GetTitle(), router.OpenAPIPath()))) }) } // SwaggerUIHandler renders documentation using Swagger UI. -func SwaggerUIHandler(pageTitle string) http.Handler { +func SwaggerUIHandler(router *Router) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html") w.Write([]byte(fmt.Sprintf(` @@ -106,7 +106,7 @@ func SwaggerUIHandler(pageTitle string) http.Handler { window.onload = function() { // Begin Swagger UI call region const ui = SwaggerUIBundle({ - url: "/openapi.json", + url: "%s", dom_id: '#swagger-ui', deepLinking: true, presets: [ @@ -124,6 +124,6 @@ func SwaggerUIHandler(pageTitle string) http.Handler { } -`, pageTitle))) +`, router.GetTitle(), router.OpenAPIPath()))) }) } diff --git a/docs_test.go b/docs_test.go index cb6ef21..fdc5a5b 100644 --- a/docs_test.go +++ b/docs_test.go @@ -12,9 +12,9 @@ var handlers = []struct { name string handler http.Handler }{ - {"RapiDoc", RapiDocHandler("Test API")}, - {"ReDoc", ReDocHandler("Test API")}, - {"SwaggerUI", SwaggerUIHandler("Test API")}, + {"RapiDoc", RapiDocHandler(New("Test API", "1.0.0"))}, + {"ReDoc", ReDocHandler(New("Test API", "1.0.0"))}, + {"SwaggerUI", SwaggerUIHandler(New("Test API", "1.0.0"))}, } func TestDocHandlers(outer *testing.T) { diff --git a/router.go b/router.go index a081cd2..4995f1d 100644 --- a/router.go +++ b/router.go @@ -255,9 +255,10 @@ func New(docs, version string) *Router { description: desc, version: version, servers: []oaServer{}, - docsHandler: RapiDocHandler(title), } + r.docsHandler = RapiDocHandler(r) + // Error handlers r.mux.NotFound(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ctx := ContextFromRequest(w, r)