-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathroutes.go
More file actions
63 lines (55 loc) · 2.03 KB
/
Copy pathroutes.go
File metadata and controls
63 lines (55 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"gateway/routes" // Import the routes package for model handlers
"github.com/gin-gonic/gin"
)
// swaggerUIPage is the HTML served at GET /docs.
const swaggerUIPage = `
<!DOCTYPE html>
<html>
<head>
<title>MicroAI Paygate Docs</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"></script>
<script>
SwaggerUIBundle({
url: '/openapi.yaml',
dom_id: '#swagger-ui'
});
</script>
</body>
</html>
`
// registerDocRoutes wires the documentation-meta routes. These serve the raw
// OpenAPI spec and the Swagger UI; they are deliberately NOT part of the
// public API contract documented in openapi.yaml, which is why the OpenAPI
// coverage test only inspects registerAPIRoutes.
func registerDocRoutes(r *gin.Engine) {
r.StaticFile("/openapi.yaml", "openapi.yaml")
r.GET("/docs", func(c *gin.Context) {
c.Header("Content-Type", "text/html")
c.String(200, swaggerUIPage)
})
}
// registerAPIRoutes wires every public API route that must be documented in
// gateway/openapi.yaml. openapi_test.go iterates this surface and fails if
// any registered route is missing from the spec, or vice versa.
func registerAPIRoutes(r *gin.Engine) {
r.GET("/healthz", handleHealthz)
r.GET("/readyz", handleReadyz)
// ── Model routes ──────────────────────────────────────────────────────────
// These must be registered BEFORE the /api/ai group to avoid path conflicts
r.GET("/api/models", routes.GetAvailableModels)
r.POST("/api/models/switch", routes.SwitchModel)
aiGroup := r.Group("/api/ai")
aiGroup.Use(RequestTimeoutMiddleware(getAITimeout()))
if getCacheEnabled() {
aiGroup.POST("/summarize", CacheMiddleware(), handleSummarize)
} else {
aiGroup.POST("/summarize", handleSummarize)
}
r.GET("/api/receipts/:id", handleGetReceipt)
}