1
0
mirror of https://github.com/go-gitea/gitea.git synced 2024-11-04 08:17:24 -05:00

Add option to enable or disable swagger endpoints (#3502)

This commit is contained in:
Piotr Orzechowski 2018-02-14 05:46:00 +01:00 committed by Lauris BH
parent 4c9d9c221a
commit b104ab3ca1
5 changed files with 15 additions and 5 deletions

View File

@ -553,6 +553,8 @@ DEFAULT_INTERVAL = 8h
MIN_INTERVAL = 10m MIN_INTERVAL = 10m
[api] [api]
; Enables /api/swagger, /api/v1/swagger etc. endpoints. True or false; default is true.
ENABLE_SWAGGER_ENDPOINT = true
; Max number of items will response in a page ; Max number of items will response in a page
MAX_RESPONSE_ITEMS = 50 MAX_RESPONSE_ITEMS = 50

View File

@ -243,6 +243,7 @@ func Contexter() macaron.Handler {
ctx.Data["ShowRegistrationButton"] = setting.Service.ShowRegistrationButton ctx.Data["ShowRegistrationButton"] = setting.Service.ShowRegistrationButton
ctx.Data["ShowFooterBranding"] = setting.ShowFooterBranding ctx.Data["ShowFooterBranding"] = setting.ShowFooterBranding
ctx.Data["ShowFooterVersion"] = setting.ShowFooterVersion ctx.Data["ShowFooterVersion"] = setting.ShowFooterVersion
ctx.Data["EnableSwaggerEndpoint"] = setting.API.EnableSwaggerEndpoint
ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn
c.Map(ctx) c.Map(ctx)

View File

@ -515,9 +515,11 @@ var (
// API settings // API settings
API = struct { API = struct {
MaxResponseItems int EnableSwaggerEndpoint bool
MaxResponseItems int
}{ }{
MaxResponseItems: 50, EnableSwaggerEndpoint: true,
MaxResponseItems: 50,
} }
// I18n settings // I18n settings

View File

@ -50,6 +50,7 @@ import (
"code.gitea.io/gitea/models" "code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth" "code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/context" "code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/routers/api/v1/admin" "code.gitea.io/gitea/routers/api/v1/admin"
"code.gitea.io/gitea/routers/api/v1/misc" "code.gitea.io/gitea/routers/api/v1/misc"
"code.gitea.io/gitea/routers/api/v1/org" "code.gitea.io/gitea/routers/api/v1/org"
@ -277,11 +278,15 @@ func mustAllowPulls(ctx *context.Context) {
func RegisterRoutes(m *macaron.Macaron) { func RegisterRoutes(m *macaron.Macaron) {
bind := binding.Bind bind := binding.Bind
m.Get("/swagger", misc.Swagger) //Render V1 by default if setting.API.EnableSwaggerEndpoint {
m.Get("/swagger", misc.Swagger) //Render V1 by default
}
m.Group("/v1", func() { m.Group("/v1", func() {
// Miscellaneous // Miscellaneous
m.Get("/swagger", misc.Swagger) if setting.API.EnableSwaggerEndpoint {
m.Get("/swagger", misc.Swagger)
}
m.Get("/version", misc.Version) m.Get("/version", misc.Version)
m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown) m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown)
m.Post("/markdown/raw", misc.MarkdownRaw) m.Post("/markdown/raw", misc.MarkdownRaw)

View File

@ -29,7 +29,7 @@
</div> </div>
</div> </div>
<a href="{{AppSubUrl}}/vendor/librejs.html" data-jslicense="1">JavaScript licenses</a> <a href="{{AppSubUrl}}/vendor/librejs.html" data-jslicense="1">JavaScript licenses</a>
<a href="{{AppSubUrl}}/api/swagger">API</a> {{if .EnableSwaggerEndpoint}}<a href="{{AppSubUrl}}/api/swagger">API</a>{{end}}
<a target="_blank" rel="noopener" href="https://gitea.io">{{.i18n.Tr "website"}}</a> <a target="_blank" rel="noopener" href="https://gitea.io">{{.i18n.Tr "website"}}</a>
{{if (or .ShowFooterVersion .PageIsAdmin)}}<span class="version">{{GoVer}}</span>{{end}} {{if (or .ShowFooterVersion .PageIsAdmin)}}<span class="version">{{GoVer}}</span>{{end}}
</div> </div>