Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to enable or disable swagger endpoints #3502

Merged
merged 1 commit into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions custom/conf/app.ini.sample
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,8 @@ DEFAULT_INTERVAL = 8h
MIN_INTERVAL = 10m

[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_RESPONSE_ITEMS = 50

Expand Down
1 change: 1 addition & 0 deletions modules/context/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@ func Contexter() macaron.Handler {
ctx.Data["ShowRegistrationButton"] = setting.Service.ShowRegistrationButton
ctx.Data["ShowFooterBranding"] = setting.ShowFooterBranding
ctx.Data["ShowFooterVersion"] = setting.ShowFooterVersion
ctx.Data["EnableSwaggerEndpoint"] = setting.API.EnableSwaggerEndpoint
ctx.Data["EnableOpenIDSignIn"] = setting.Service.EnableOpenIDSignIn

c.Map(ctx)
Expand Down
6 changes: 4 additions & 2 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -515,9 +515,11 @@ var (

// API settings
API = struct {
MaxResponseItems int
EnableSwaggerEndpoint bool
MaxResponseItems int
}{
MaxResponseItems: 50,
EnableSwaggerEndpoint: true,
MaxResponseItems: 50,
}

// I18n settings
Expand Down
9 changes: 7 additions & 2 deletions routers/api/v1/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth"
"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/misc"
"code.gitea.io/gitea/routers/api/v1/org"
Expand Down Expand Up @@ -277,11 +278,15 @@ func mustAllowPulls(ctx *context.Context) {
func RegisterRoutes(m *macaron.Macaron) {
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() {
// Miscellaneous
m.Get("/swagger", misc.Swagger)
if setting.API.EnableSwaggerEndpoint {
m.Get("/swagger", misc.Swagger)
}
m.Get("/version", misc.Version)
m.Post("/markdown", bind(api.MarkdownOption{}), misc.Markdown)
m.Post("/markdown/raw", misc.MarkdownRaw)
Expand Down
2 changes: 1 addition & 1 deletion templates/base/footer.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
</div>
</div>
<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>
{{if (or .ShowFooterVersion .PageIsAdmin)}}<span class="version">{{GoVer}}</span>{{end}}
</div>
Expand Down