package huma
import (
"fmt"
"net/http"
"strings"
)
// splitDocs will split a single string out into a title/description combo.
func splitDocs(docs string) (title, desc string) {
title = docs
desc = ""
if strings.Contains(docs, "\n") {
parts := strings.SplitN(docs, "\n", 2)
title = parts[0]
desc = parts[1]
}
return
}
// RapiDocHandler renders documentation using RapiDoc.
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(`
%s
`, router.GetTitle(), router.OpenAPIPath())))
})
}
// ReDocHandler renders documentation using ReDoc.
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(`
%s
`, router.GetTitle(), router.OpenAPIPath())))
})
}
// SwaggerUIHandler renders documentation using Swagger UI.
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(`
%s
`, router.GetTitle(), router.OpenAPIPath())))
})
}