mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-17 11:59:30 +00:00
Swagger.v1.json template (#3572)
* Turn swagger.v1.json into template * Rename ENABLE_SWAGGER_ENDPOINT option to ENABLE_SWAGGER
This commit is contained in:
parent
412583a3f2
commit
a74426d631
14 changed files with 74 additions and 21 deletions
|
@ -278,13 +278,13 @@ func mustAllowPulls(ctx *context.Context) {
|
|||
func RegisterRoutes(m *macaron.Macaron) {
|
||||
bind := binding.Bind
|
||||
|
||||
if setting.API.EnableSwaggerEndpoint {
|
||||
if setting.API.EnableSwagger {
|
||||
m.Get("/swagger", misc.Swagger) //Render V1 by default
|
||||
}
|
||||
|
||||
m.Group("/v1", func() {
|
||||
// Miscellaneous
|
||||
if setting.API.EnableSwaggerEndpoint {
|
||||
if setting.API.EnableSwagger {
|
||||
m.Get("/swagger", misc.Swagger)
|
||||
}
|
||||
m.Get("/version", misc.Version)
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
// tplSwagger swagger page template
|
||||
const tplSwagger base.TplName = "swagger"
|
||||
const tplSwagger base.TplName = "swagger/ui"
|
||||
|
||||
// Swagger render swagger-ui page with v1 json
|
||||
func Swagger(ctx *context.Context) {
|
||||
|
|
|
@ -79,7 +79,7 @@ func NewMacaron() *macaron.Macaron {
|
|||
},
|
||||
))
|
||||
|
||||
m.Use(templates.Renderer())
|
||||
m.Use(templates.HTMLRenderer())
|
||||
models.InitMailRender(templates.Mailer())
|
||||
|
||||
localeNames, err := options.Dir("locale")
|
||||
|
@ -755,6 +755,10 @@ func RegisterRoutes(m *macaron.Macaron) {
|
|||
m.Post("/purge", user.NotificationPurgePost)
|
||||
}, reqSignIn)
|
||||
|
||||
if setting.API.EnableSwagger {
|
||||
m.Get("/swagger.v1.json", templates.JSONRenderer(), routers.SwaggerV1Json)
|
||||
}
|
||||
|
||||
m.Group("/api", func() {
|
||||
apiv1.RegisterRoutes(m)
|
||||
}, ignSignIn)
|
||||
|
|
14
routers/swagger_json.go
Normal file
14
routers/swagger_json.go
Normal file
|
@ -0,0 +1,14 @@
|
|||
package routers
|
||||
|
||||
import (
|
||||
"code.gitea.io/gitea/modules/base"
|
||||
"code.gitea.io/gitea/modules/context"
|
||||
)
|
||||
|
||||
// tplSwaggerV1Json swagger v1 json template
|
||||
const tplSwaggerV1Json base.TplName = "swagger/v1_json"
|
||||
|
||||
// SwaggerV1Json render swagger v1 json
|
||||
func SwaggerV1Json(ctx *context.Context) {
|
||||
ctx.HTML(200, tplSwaggerV1Json)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue