feat: Add documentation generation and serve functionality

- Implement documentation generation
- Replace chi router with gin for documentation server
- Fix issues with docs command execution
This commit is contained in:
2025-11-04 19:15:28 +03:00
parent 3fc545f067
commit 5a8b53b49d
10 changed files with 206 additions and 100 deletions

View File

@@ -6,7 +6,8 @@ import (
"git.ostiwe.com/ostiwe-com/status/modules/log"
"git.ostiwe.com/ostiwe-com/status/router/controller"
"github.com/gin-gonic/gin"
"github.com/go-andiamo/chioas"
"github.com/swaggest/openapi-go"
"github.com/swaggest/openapi-go/openapi3"
)
type Controller struct {
@@ -34,29 +35,19 @@ func (c *Controller) Handler() gin.HandlerFunc {
}
}
func (c *Controller) Documentate() (*chioas.Paths, *chioas.Components) {
return &chioas.Paths{
"/ping": chioas.Path{
Methods: map[string]chioas.Method{
http.MethodGet: {
Handler: c.Handler(),
Responses: chioas.Responses{
http.StatusOK: {
ContentType: "plain/text",
Schema: chioas.Schema{Type: "string"},
Examples: chioas.Examples{
{
func (c *Controller) Documentate(r *openapi3.Reflector) openapi.OperationContext {
op, err := r.NewOperationContext(c.Method(), c.Path())
if err != nil {
return nil
}
Name: "200 OK",
Value: "pong",
},
},
},
},
},
},
Tag: "service",
Comment: "Route for check service is alive",
},
}, nil
op.SetDescription("Route for check service is alive")
op.SetSummary("Server ping")
op.AddRespStructure("pong", func(cu *openapi.ContentUnit) {
cu.ContentType = "plain/text"
cu.HTTPStatus = http.StatusOK
})
return op
}