|
1 | 1 | package handlers |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "github.com/android-sms-gateway/server/internal/version" |
5 | | - apidoc "github.com/android-sms-gateway/server/pkg/swagger" |
| 4 | + "github.com/android-sms-gateway/server/internal/sms-gateway/openapi" |
6 | 5 | "github.com/gofiber/fiber/v2" |
7 | | - "github.com/gofiber/fiber/v2/middleware/etag" |
8 | | - "github.com/gofiber/swagger" |
9 | 6 | ) |
10 | 7 |
|
11 | 8 | type rootHandler struct { |
12 | | - healthHandler *healthHandler |
| 9 | + healthHandler *healthHandler |
| 10 | + openapiHandler *openapi.Handler |
13 | 11 | } |
14 | 12 |
|
15 | 13 | func (h *rootHandler) Register(app *fiber.App) { |
16 | 14 | app.Use(func(c *fiber.Ctx) error { |
17 | | - if c.Path() == "/api" { |
18 | | - return c.Redirect("/docs/", fiber.StatusMovedPermanently) |
| 15 | + if c.Path() == "/api" || c.Path() == "/api/" { |
| 16 | + return c.Redirect("/api/docs/", fiber.StatusMovedPermanently) |
19 | 17 | } |
20 | 18 |
|
21 | 19 | return c.Next() |
22 | 20 | }) |
23 | 21 |
|
24 | 22 | h.healthHandler.Register(app) |
25 | | - h.registerDocs(app) |
| 23 | + h.openapiHandler.Register(app.Group("/api/docs")) |
26 | 24 | } |
27 | 25 |
|
28 | | -func (h *rootHandler) registerDocs(router fiber.Router) error { |
29 | | - apidoc.SwaggerInfo.Version = version.AppVersion |
30 | | - router.Use("/docs/*", |
31 | | - etag.New(etag.Config{ |
32 | | - Weak: true, |
33 | | - }), |
34 | | - swagger.New(swagger.Config{ |
35 | | - Layout: "BaseLayout", |
36 | | - }), |
37 | | - ) |
38 | | - |
39 | | - return nil |
40 | | -} |
41 | | - |
42 | | -func newRootHandler(healthHandler *healthHandler) *rootHandler { |
| 26 | +func newRootHandler(healthHandler *healthHandler, openapiHandler *openapi.Handler) *rootHandler { |
43 | 27 | return &rootHandler{ |
44 | | - healthHandler: healthHandler, |
| 28 | + healthHandler: healthHandler, |
| 29 | + openapiHandler: openapiHandler, |
45 | 30 | } |
46 | 31 | } |
0 commit comments