timetracker update
This commit is contained in:
60
app/delivery/web/general/swagger.go
Normal file
60
app/delivery/web/general/swagger.go
Normal file
@@ -0,0 +1,60 @@
|
||||
package general
|
||||
|
||||
import (
|
||||
"git.ma-al.com/goc_marek/timetracker/app/api"
|
||||
"github.com/gofiber/fiber/v3"
|
||||
"github.com/gofiber/fiber/v3/middleware/static"
|
||||
)
|
||||
|
||||
func InitSwagger(app *fiber.App) {
|
||||
// Swagger - serve OpenAPI JSON
|
||||
app.Get("/openapi.json", func(c fiber.Ctx) error {
|
||||
c.Set("Content-Type", "application/json")
|
||||
return c.SendString(api.ApenapiJson)
|
||||
})
|
||||
|
||||
// Swagger UI HTML
|
||||
app.Get("/swagger", func(c fiber.Ctx) error {
|
||||
return c.Redirect().Status(fiber.StatusFound).To("/swagger/index.html")
|
||||
})
|
||||
|
||||
app.Get("/swagger/index.html", func(c fiber.Ctx) error {
|
||||
c.Set("Content-Type", "text/html")
|
||||
return c.SendString(swaggerHTML)
|
||||
})
|
||||
|
||||
// Serve Swagger assets
|
||||
app.Get("/swagger/assets", static.New("app/api/swagger/assets"))
|
||||
}
|
||||
|
||||
// Embedded Swagger UI HTML (minimal version)
|
||||
var swaggerHTML = `
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>API Documentation</title>
|
||||
<link rel="stylesheet" href="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="swagger-ui"></div>
|
||||
<script src="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui-bundle.js" charset="UTF-8"></script>
|
||||
<script src="https://unpkg.com/swagger-ui-dist@5.11.0/swagger-ui-standalone-preset.js" charset="UTF-8"></script>
|
||||
<script>
|
||||
window.onload = function() {
|
||||
window.ui = SwaggerUIBundle({
|
||||
url: "/openapi.json",
|
||||
dom_id: '#swagger-ui',
|
||||
deepLinking: true,
|
||||
presets: [
|
||||
SwaggerUIBundle.presets.apis,
|
||||
SwaggerUIStandalonePreset
|
||||
],
|
||||
layout: "StandaloneLayout"
|
||||
});
|
||||
};
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
`
|
||||
Reference in New Issue
Block a user