Files
vikunja/pkg/routes/api/v1/docs.go
kolaente 111090d12c refactor: use embed fs for redoc UI and update to latest version
Move the redoc HTML template and JavaScript bundle out of the Go const
in docs.go into separate files under pkg/routes/api/v1/redoc/, using
Go's embed directive. Update redoc.standalone.js to the latest version.
The JS is now served on a separate route (/api/v1/docs/redoc.standalone.js)
to keep the HTML and JS cleanly separated.
2026-03-30 15:09:54 +00:00

57 lines
1.7 KiB
Go

// Vikunja is a to-do list application to facilitate your life.
// Copyright 2018-present Vikunja and contributors. All rights reserved.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
package v1
import (
_ "embed"
"net/http"
"code.vikunja.io/api/pkg/log"
_ "code.vikunja.io/api/pkg/swagger" // To make sure the swag files are properly registered
"github.com/labstack/echo/v5"
"github.com/swaggo/swag"
)
//go:embed redoc/redoc.html
var redocHTML string
//go:embed redoc/redoc.standalone.js
var redocJS []byte
// DocsJSON serves swagger doc json specs
func DocsJSON(c *echo.Context) error {
doc, err := swag.ReadDoc()
if err != nil {
log.Error(err.Error())
return echo.NewHTTPError(http.StatusInternalServerError, "Internal server error").Wrap(err)
}
return c.Blob(http.StatusOK, echo.MIMEApplicationJSON, []byte(doc))
}
// RedocUI serves everything needed to provide the redoc ui
func RedocUI(c *echo.Context) error {
return c.HTML(http.StatusOK, redocHTML)
}
// RedocJS serves the embedded redoc standalone JavaScript bundle
func RedocJS(c *echo.Context) error {
return c.Blob(http.StatusOK, echo.MIMEApplicationJavaScript, redocJS)
}