enable or disable swagger

This commit is contained in:
Marek Goc 2023-04-11 23:33:33 +02:00
parent 46a1d9f4f0
commit ca242a55f8
2 changed files with 38 additions and 30 deletions

View File

@ -103,9 +103,12 @@ func (g *App) init() {
if g.Swagger == nil { if g.Swagger == nil {
return return
} }
if g.Swagger.SwaggerEnable || g.Swagger.RedocEnable {
g.App.Get(g.fullPath(g.Swagger.OpenAPIUrl), func(c *fiber.Ctx) error { g.App.Get(g.fullPath(g.Swagger.OpenAPIUrl), func(c *fiber.Ctx) error {
return c.JSON(g.Swagger) return c.JSON(g.Swagger)
}) })
}
if g.Swagger.SwaggerEnable {
g.App.Get(g.fullPath(g.Swagger.DocsUrl), func(c *fiber.Ctx) error { g.App.Get(g.fullPath(g.Swagger.DocsUrl), func(c *fiber.Ctx) error {
options := `{}` options := `{}`
if g.Swagger.SwaggerOptions != nil { if g.Swagger.SwaggerOptions != nil {
@ -121,6 +124,8 @@ func (g *App) init() {
"swagger_options": options, "swagger_options": options,
}) })
}) })
}
if g.Swagger.RedocEnable {
g.App.Get(g.fullPath(g.Swagger.RedocUrl), func(c *fiber.Ctx) error { g.App.Get(g.fullPath(g.Swagger.RedocUrl), func(c *fiber.Ctx) error {
options := `{}` options := `{}`
if g.Swagger.RedocOptions != nil { if g.Swagger.RedocOptions != nil {
@ -136,6 +141,7 @@ func (g *App) init() {
"redoc_options": options, "redoc_options": options,
}) })
}) })
}
g.initRouters() g.initRouters()
g.Swagger.BuildOpenAPI() g.Swagger.BuildOpenAPI()
} }

View File

@ -33,6 +33,8 @@ type Swagger struct {
Contact *openapi3.Contact Contact *openapi3.Contact
License *openapi3.License License *openapi3.License
OpenAPI *openapi3.T OpenAPI *openapi3.T
SwaggerEnable bool
RedocEnable bool
SwaggerOptions map[string]interface{} SwaggerOptions map[string]interface{}
RedocOptions map[string]interface{} RedocOptions map[string]interface{}
} }