Fix OpenAPI endpoint to serve swagger.json directly
This commit is contained in:
@@ -2,7 +2,6 @@ package server
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"music-server/cmd/docs"
|
||||
"music-server/cmd/web"
|
||||
"net/http"
|
||||
"sort"
|
||||
@@ -31,11 +30,10 @@ func (s *Server) RegisterRoutes() http.Handler {
|
||||
e := echo.New()
|
||||
|
||||
// Serve OpenAPI spec at /openapi
|
||||
e.GET("/openapi", func(c echo.Context) error {
|
||||
c.Response().Header().Set("Content-Type", "application/json")
|
||||
_, err := c.Response().Write([]byte(docs.GetSwaggerJSON()))
|
||||
return err
|
||||
})
|
||||
e.GET("/openapi", echo.WrapHandler(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
http.ServeFile(w, r, "cmd/docs/swagger.json")
|
||||
})))
|
||||
e.Use(middleware.Logger())
|
||||
e.Use(middleware.Recover())
|
||||
|
||||
|
||||
Reference in New Issue
Block a user