diff --git a/cmd/server/flags.go b/cmd/server/flags.go index bb22fd6e9..4dbd49e08 100644 --- a/cmd/server/flags.go +++ b/cmd/server/flags.go @@ -272,6 +272,11 @@ var flags = []cli.Flag{ Name: "migrations-allow-long", Value: false, }, + &cli.BoolFlag{ + EnvVars: []string{"WOODPECKER_ENABLE_SWAGGER"}, + Name: "enable-swagger", + Value: true, + }, // // resource limit parameters // diff --git a/cmd/server/server.go b/cmd/server/server.go index 1822a3433..adfda1fa6 100644 --- a/cmd/server/server.go +++ b/cmd/server/server.go @@ -364,6 +364,7 @@ func setupEvilGlobals(c *cli.Context, v store.Store, f forge.Forge) { server.Config.Pipeline.Volumes = c.StringSlice("volume") server.Config.Pipeline.Privileged = c.StringSlice("escalate") server.Config.Server.Migrations.AllowLong = c.Bool("migrations-allow-long") + server.Config.Server.EnableSwagger = c.Bool("enable-swagger") // prometheus server.Config.Prometheus.AuthToken = c.String("prometheus-auth-token") diff --git a/docs/docs/30-administration/10-server-config.md b/docs/docs/30-administration/10-server-config.md index 519419efa..c46cbb9db 100644 --- a/docs/docs/30-administration/10-server-config.md +++ b/docs/docs/30-administration/10-server-config.md @@ -535,6 +535,11 @@ Server URL path prefix (used for statics loading when having a url path prefix), Example: `WOODPECKER_ROOT_URL=/woodpecker` +### `WOODPECKER_ENABLE_SWAGGER` +> Default: true + +Enable the Swagger UI for API documentation. + --- ### `WOODPECKER_GITHUB_...` diff --git a/server/config.go b/server/config.go index b3efd444a..a75d74479 100644 --- a/server/config.go +++ b/server/config.go @@ -73,6 +73,7 @@ var Config = struct { Migrations struct { AllowLong bool } + EnableSwagger bool // Open bool // Orgs map[string]struct{} // Admins map[string]struct{} diff --git a/server/router/router.go b/server/router/router.go index 94d03d994..2ce588b33 100644 --- a/server/router/router.go +++ b/server/router/router.go @@ -69,7 +69,9 @@ func Load(noRouteHandler http.HandlerFunc, middleware ...gin.HandlerFunc) http.H e.GET("/healthz", api.Health) apiRoutes(e) - setupSwaggerConfigAndRoutes(e) + if server.Config.Server.EnableSwagger { + setupSwaggerConfigAndRoutes(e) + } return e } diff --git a/server/web/config.go b/server/web/config.go index 535daa74f..8d41c9b35 100644 --- a/server/web/config.go +++ b/server/web/config.go @@ -40,12 +40,13 @@ func Config(c *gin.Context) { } configData := map[string]interface{}{ - "user": user, - "csrf": csrf, - "docs": server.Config.Server.Docs, - "version": version.String(), - "forge": server.Config.Services.Forge.Name(), - "root_url": server.Config.Server.RootURL, + "user": user, + "csrf": csrf, + "docs": server.Config.Server.Docs, + "version": version.String(), + "forge": server.Config.Services.Forge.Name(), + "root_url": server.Config.Server.RootURL, + "enable_swagger": server.Config.Server.EnableSwagger, } // default func map with json parser. @@ -75,4 +76,5 @@ window.WOODPECKER_VERSION = "{{ .version }}"; window.WOODPECKER_DOCS = "{{ .docs }}"; window.WOODPECKER_FORGE = "{{ .forge }}"; window.WOODPECKER_ROOT_URL = "{{ .root_url }}"; +window.WOODPECKER_ENABLE_SWAGGER = {{ .enable_swagger }}; ` diff --git a/web/src/components/layout/header/Navbar.vue b/web/src/components/layout/header/Navbar.vue index 08eb2e8ff..acd1a4275 100644 --- a/web/src/components/layout/header/Navbar.vue +++ b/web/src/components/layout/header/Navbar.vue @@ -18,7 +18,9 @@ - +
@@ -82,7 +84,15 @@ export default defineComponent({ const version = config.version?.startsWith('next') ? 'next' : config.version; - return { darkMode, user: authentication.user, doLogin, docsUrl, version, apiUrl }; + return { + darkMode, + user: authentication.user, + doLogin, + docsUrl, + version, + apiUrl, + enableSwagger: config.enableSwagger, + }; }, }); diff --git a/web/src/compositions/useConfig.ts b/web/src/compositions/useConfig.ts index aa5bb00a8..a6c6cd7f8 100644 --- a/web/src/compositions/useConfig.ts +++ b/web/src/compositions/useConfig.ts @@ -8,6 +8,7 @@ declare global { WOODPECKER_CSRF: string | undefined; WOODPECKER_FORGE: string | undefined; WOODPECKER_ROOT_URL: string | undefined; + WOODPECKER_ENABLE_SWAGGER: boolean | undefined; } } @@ -18,4 +19,5 @@ export default () => ({ csrf: window.WOODPECKER_CSRF || null, forge: window.WOODPECKER_FORGE || null, rootURL: window.WOODPECKER_ROOT_URL || null, + enableSwagger: window.WOODPECKER_ENABLE_SWAGGER || false, }); diff --git a/web/src/views/User.vue b/web/src/views/User.vue index 8658e626c..4f0d84b7c 100644 --- a/web/src/views/User.vue +++ b/web/src/views/User.vue @@ -22,6 +22,7 @@

{{ $t('user.api_usage') }}

();