lab 3 done
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
package chat
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
|
||||
"gitflic.ru/akselbant/mtusi2026lab1-fork/contracts"
|
||||
)
|
||||
|
||||
var swaggerOpenAPI = makeSwaggerOpenAPI()
|
||||
|
||||
func (h *Chat) swagger(c echo.Context) error {
|
||||
return c.Redirect(http.StatusTemporaryRedirect, "/swagger/")
|
||||
}
|
||||
|
||||
func (h *Chat) swaggerSpec(c echo.Context) error {
|
||||
return c.Blob(http.StatusOK, echo.MIMEApplicationJSON, swaggerOpenAPI)
|
||||
}
|
||||
|
||||
func makeSwaggerOpenAPI() []byte {
|
||||
var document map[string]any
|
||||
if err := json.Unmarshal(contracts.OpenAPI, &document); err != nil {
|
||||
panic("cannot decode embedded OpenAPI contract: " + err.Error())
|
||||
}
|
||||
// A relative URL keeps Swagger requests on the same scheme, host and port
|
||||
// as the UI. This also works behind a reverse proxy and on a custom PORT.
|
||||
document["servers"] = []map[string]string{{
|
||||
"url": "/",
|
||||
"description": "Текущий адрес Swagger UI",
|
||||
}}
|
||||
encoded, err := json.Marshal(document)
|
||||
if err != nil {
|
||||
panic("cannot encode Swagger OpenAPI contract: " + err.Error())
|
||||
}
|
||||
return encoded
|
||||
}
|
||||
Reference in New Issue
Block a user