Files
drive/apps/backend/cmd/docs/main.go
Kenneth 528aa943fa feat: migrate to OpenAPI 3.0 with oneOf unions
- Add swagger2openapi conversion step to generate OpenAPI 3.0
- Add patch-openapi.ts script to inject oneOf discriminated unions
- Update docs server to embed static openapi.json
- Update moveItemsToDirectory response to use oneOf for items
- Add docs/README.md documenting the pipeline
- Use bun instead of node for scripts
2025-12-14 16:43:05 +00:00

86 lines
2.1 KiB
Go

package main
import (
"embed"
"flag"
"fmt"
"log"
"os"
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/cors"
"github.com/gofiber/fiber/v2/middleware/logger"
)
//go:embed openapi.json
var openapiSpec embed.FS
func main() {
port := flag.Int("port", 8081, "port to listen on")
apiURL := flag.String("api-url", "http://localhost:8080", "base URL of the API server")
flag.Parse()
app := fiber.New(fiber.Config{
AppName: "Drexa API Documentation",
})
app.Use(logger.New())
app.Use(cors.New())
// Serve Scalar UI
app.Get("/", func(c *fiber.Ctx) error {
html := fmt.Sprintf(`<!DOCTYPE html>
<html>
<head>
<title>Drexa API Documentation</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/svg+xml" href="data:image/svg+xml,%%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%%3E%%3Ctext y='.9em' font-size='90'%%3E📚%%3C/text%%3E%%3C/svg%%3E" />
</head>
<body>
<script
id="api-reference"
data-url="/openapi.json"
data-configuration='{
"theme": "kepler",
"darkMode": true,
"authentication": {
"preferredSecurityScheme": "BearerAuth"
},
"servers": [
{
"url": "%s",
"description": "API Server"
}
]
}'
></script>
<script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
</body>
</html>`, *apiURL)
c.Set("Content-Type", "text/html; charset=utf-8")
return c.SendString(html)
})
// Serve OpenAPI spec
app.Get("/openapi.json", func(c *fiber.Ctx) error {
c.Set("Content-Type", "application/json")
c.Set("Access-Control-Allow-Origin", "*")
doc, err := openapiSpec.ReadFile("openapi.json")
if err != nil {
return c.Status(fiber.StatusInternalServerError).SendString(err.Error())
}
return c.Send(doc)
})
// Health check
app.Get("/health", func(c *fiber.Ctx) error {
return c.JSON(fiber.Map{"status": "ok"})
})
fmt.Fprintf(os.Stderr, "📚 Drexa API Documentation server starting on http://localhost:%d\n", *port)
fmt.Fprintf(os.Stderr, " API server configured at: %s\n", *apiURL)
log.Fatal(app.Listen(fmt.Sprintf(":%d", *port)))
}