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:
@@ -2,7 +2,8 @@ package controller
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-andiamo/chioas"
|
||||
"github.com/swaggest/openapi-go"
|
||||
"github.com/swaggest/openapi-go/openapi3"
|
||||
)
|
||||
|
||||
// SecuredController - means, controller has middlewares
|
||||
@@ -12,7 +13,7 @@ type SecuredController interface {
|
||||
}
|
||||
|
||||
type DocumentateController interface {
|
||||
Documentate() (*chioas.Paths, *chioas.Components)
|
||||
Documentate(r *openapi3.Reflector) openapi.OperationContext
|
||||
}
|
||||
|
||||
type Controller interface {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user