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,9 +2,9 @@ package router
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"maps"
|
||||
"time"
|
||||
|
||||
"git.ostiwe.com/ostiwe-com/status/modules/jwt"
|
||||
"git.ostiwe.com/ostiwe-com/status/modules/log"
|
||||
"git.ostiwe.com/ostiwe-com/status/router/controller"
|
||||
"git.ostiwe.com/ostiwe-com/status/router/controller/auth"
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
"git.ostiwe.com/ostiwe-com/status/router/controller/service"
|
||||
"git.ostiwe.com/ostiwe-com/status/version"
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/go-andiamo/chioas"
|
||||
"github.com/swaggest/openapi-go/openapi3"
|
||||
)
|
||||
|
||||
func getControllers() []controller.Controller {
|
||||
@@ -27,6 +27,8 @@ func InitRoutes() *gin.Engine {
|
||||
log.Global.Get(log.SERVER).Info("Setting up routers")
|
||||
startTime := time.Now()
|
||||
|
||||
jwt.Init()
|
||||
|
||||
r := gin.New()
|
||||
r.Use(
|
||||
gin.Recovery(),
|
||||
@@ -61,27 +63,16 @@ func InitRoutes() *gin.Engine {
|
||||
return r
|
||||
}
|
||||
|
||||
func Documentate() chioas.Definition {
|
||||
func Documentate() (*openapi3.Spec, error) {
|
||||
ctrlList := getControllers()
|
||||
apiDoc := chioas.Definition{
|
||||
AutoHeadMethods: true,
|
||||
DocOptions: chioas.DocOptions{
|
||||
ServeDocs: true,
|
||||
HideHeadMethods: true,
|
||||
},
|
||||
Info: chioas.Info{
|
||||
Version: version.AppVersion(),
|
||||
Title: "Status page API Documentation",
|
||||
},
|
||||
Paths: make(chioas.Paths),
|
||||
Components: &chioas.Components{
|
||||
Schemas: make(chioas.Schemas, 0),
|
||||
Requests: make(chioas.CommonRequests),
|
||||
Responses: make(chioas.CommonResponses),
|
||||
Examples: make(chioas.Examples, 0),
|
||||
Parameters: make(chioas.CommonParameters),
|
||||
SecuritySchemes: make(chioas.SecuritySchemes, 0),
|
||||
Extensions: make(chioas.Extensions),
|
||||
|
||||
reflector := &openapi3.Reflector{
|
||||
Spec: &openapi3.Spec{
|
||||
Openapi: "3.0.3",
|
||||
Info: openapi3.Info{
|
||||
Title: "OstiweStatus API",
|
||||
Version: version.AppVersion(),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -91,25 +82,12 @@ func Documentate() chioas.Definition {
|
||||
continue
|
||||
}
|
||||
|
||||
documentatePaths, components := documentated.Documentate()
|
||||
|
||||
if documentatePaths != nil {
|
||||
for path, pathDoc := range *documentatePaths {
|
||||
apiDoc.Paths[path] = pathDoc
|
||||
}
|
||||
err := reflector.AddOperation(documentated.Documentate(reflector))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if components != nil {
|
||||
apiDoc.Components.Schemas = append(apiDoc.Components.Schemas, components.Schemas...)
|
||||
apiDoc.Components.Examples = append(apiDoc.Components.Examples, components.Examples...)
|
||||
apiDoc.Components.SecuritySchemes = append(apiDoc.Components.SecuritySchemes, components.SecuritySchemes...)
|
||||
|
||||
maps.Copy(apiDoc.Components.Requests, components.Requests)
|
||||
maps.Copy(apiDoc.Components.Responses, components.Responses)
|
||||
maps.Copy(apiDoc.Components.Parameters, components.Parameters)
|
||||
maps.Copy(apiDoc.Components.Extensions, components.Extensions)
|
||||
}
|
||||
}
|
||||
|
||||
return apiDoc
|
||||
return reflector.Spec, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user