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,39 +103,45 @@ func (g *App) init() {
if g.Swagger == nil {
return
}
g.App.Get(g.fullPath(g.Swagger.OpenAPIUrl), func(c *fiber.Ctx) error {
return c.JSON(g.Swagger)
})
g.App.Get(g.fullPath(g.Swagger.DocsUrl), func(c *fiber.Ctx) error {
options := `{}`
if g.Swagger.SwaggerOptions != nil {
data, err := json.Marshal(g.Swagger.SwaggerOptions)
if err != nil {
log.Panic(err)
}
options = string(data)
}
return c.Render("templates/swagger", fiber.Map{
"openapi_url": g.fullPath(g.Swagger.OpenAPIUrl),
"title": g.Swagger.Title,
"swagger_options": options,
if g.Swagger.SwaggerEnable || g.Swagger.RedocEnable {
g.App.Get(g.fullPath(g.Swagger.OpenAPIUrl), func(c *fiber.Ctx) error {
return c.JSON(g.Swagger)
})
})
g.App.Get(g.fullPath(g.Swagger.RedocUrl), func(c *fiber.Ctx) error {
options := `{}`
if g.Swagger.RedocOptions != nil {
data, err := json.Marshal(g.Swagger.RedocOptions)
if err != nil {
log.Panic(err)
}
if g.Swagger.SwaggerEnable {
g.App.Get(g.fullPath(g.Swagger.DocsUrl), func(c *fiber.Ctx) error {
options := `{}`
if g.Swagger.SwaggerOptions != nil {
data, err := json.Marshal(g.Swagger.SwaggerOptions)
if err != nil {
log.Panic(err)
}
options = string(data)
}
options = string(data)
}
return c.Render("templates/redoc", fiber.Map{
"openapi_url": g.fullPath(g.Swagger.OpenAPIUrl),
"title": g.Swagger.Title,
"redoc_options": options,
return c.Render("templates/swagger", fiber.Map{
"openapi_url": g.fullPath(g.Swagger.OpenAPIUrl),
"title": g.Swagger.Title,
"swagger_options": options,
})
})
})
}
if g.Swagger.RedocEnable {
g.App.Get(g.fullPath(g.Swagger.RedocUrl), func(c *fiber.Ctx) error {
options := `{}`
if g.Swagger.RedocOptions != nil {
data, err := json.Marshal(g.Swagger.RedocOptions)
if err != nil {
log.Panic(err)
}
options = string(data)
}
return c.Render("templates/redoc", fiber.Map{
"openapi_url": g.fullPath(g.Swagger.OpenAPIUrl),
"title": g.Swagger.Title,
"redoc_options": options,
})
})
}
g.initRouters()
g.Swagger.BuildOpenAPI()
}

View File

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