package httpapi
import (
_ "embed"
"net/http"
)
//go:embed openapi.json
var openAPIDocument []byte
const swaggerUI = `
Card to IBAN API documentation
`
// RegisterDocumentation registers the OpenAPI document and its Swagger UI.
func RegisterDocumentation(mux *http.ServeMux) {
mux.HandleFunc("GET /openapi.json", serveOpenAPI)
mux.HandleFunc("GET /swagger/", serveSwaggerUI)
mux.HandleFunc("GET /docs", redirectToSwaggerUI)
}
func serveOpenAPI(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "application/json")
_, _ = w.Write(openAPIDocument)
}
func serveSwaggerUI(w http.ResponseWriter, _ *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
_, _ = w.Write([]byte(swaggerUI))
}
func redirectToSwaggerUI(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/swagger/", http.StatusTemporaryRedirect)
}