1
0
mirror of https://github.com/woodpecker-ci/woodpecker.git synced 2025-06-24 22:06:51 +02:00

Update swagger API specification (#1782)

# Summary

This PR drops the outdated former swagger.yaml/json and introduced
automatic API document generation from Go code.
The generated code is also used to generate documentation/markdown for
the community page,
as well as enable the Woodpecker server to serve a Swagger Web UI for
manual tinkering.

I did opt-in for gin-swagger, a middleware for the Gin framework, to
ease implementation and have a sophisticated output.
This middleware only produces Swagger v2 specs. AFAIK the newer OpenApi
3x tooling is not yet that mature,
so I guess that's fine for now.

## Implemenation notes

- former swagger.json files removed
- former // swagger godocs removed
- introduced new dependency gin-swagger, which uses godoc annotations on
top of Gin Handler functions.
- reworked Makefile to automatically generate Go code for the server
- introduce new dependency go-swagger, to generate Markdown for
documentation purposes
- add a Swagger Web UI, incl. capabilities for manual API exploration
- consider relative root paths in the implementation
- write documentation for all exposed API endpoints
- incl. API docs in the community website (auto-generated)
- provide developer documentation, for the Woodpecker authors
- no other existing logic/code was intentionally changed

---------

close #292

---------

Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
Co-authored-by: 6543 <6543@obermui.de>
This commit is contained in:
Martin W. Kirst
2023-06-03 21:38:36 +02:00
committed by GitHub
parent b9731d8da9
commit 14177635b6
49 changed files with 6047 additions and 1153 deletions

View File

@ -20,63 +20,146 @@ import (
"github.com/gin-gonic/gin"
)
// IndexHandler will pass the call from /debug/pprof to pprof
// IndexHandler
//
// @Summary List available pprof profiles (HTML)
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Router /debug/pprof [get]
// @Produce html
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
func IndexHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Index(c.Writer, c.Request)
}
}
// HeapHandler will pass the call from /debug/pprof/heap to pprof
// HeapHandler
//
// @Summary Get pprof heap dump, a sampling of memory allocations of live objects
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Router /debug/pprof/heap [get]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
// @Param gc query string false "You can specify gc=heap to run GC before taking the heap sample" default()
func HeapHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Handler("heap").ServeHTTP(c.Writer, c.Request)
}
}
// GoroutineHandler will pass the call from /debug/pprof/goroutine to pprof
// GoroutineHandler
//
// @Summary Get pprof stack traces of all current goroutines
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Router /debug/pprof/goroutine [get]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
// @Param debug query int false "Use debug=2 as a query parameter to export in the same format as an un-recovered panic" default(1)
func GoroutineHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Handler("goroutine").ServeHTTP(c.Writer, c.Request)
}
}
// BlockHandler will pass the call from /debug/pprof/block to pprof
// BlockHandler
//
// @Summary Get pprof stack traces that led to blocking on synchronization primitives
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Router /debug/pprof/block [get]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
func BlockHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Handler("block").ServeHTTP(c.Writer, c.Request)
}
}
// ThreadCreateHandler will pass the call from /debug/pprof/threadcreate to pprof
// ThreadCreateHandler
//
// @Summary Get pprof stack traces that led to the creation of new OS threads
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Router /debug/pprof/threadcreate [get]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
func ThreadCreateHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Handler("threadcreate").ServeHTTP(c.Writer, c.Request)
}
}
// CmdlineHandler will pass the call from /debug/pprof/cmdline to pprof
// CmdlineHandler
//
// @Summary Get the command line invocation of the current program
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Router /debug/pprof/cmdline [get]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
func CmdlineHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Cmdline(c.Writer, c.Request)
}
}
// ProfileHandler will pass the call from /debug/pprof/profile to pprof
// ProfileHandler
//
// @Summary Get pprof CPU profile
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Description After you get the profile file, use the go tool pprof command to investigate the profile.
// @Router /debug/pprof/profile [get]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
// @Param seconds query int true "You can specify the duration in the seconds GET parameter." default (30)
func ProfileHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Profile(c.Writer, c.Request)
}
}
// SymbolHandler will pass the call from /debug/pprof/symbol to pprof
// SymbolHandler
//
// @Summary Get pprof program counters mapping to function names
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Description Looks up the program counters listed in the request,
// @Description responding with a table mapping program counters to function names.
// @Description The requested program counters can be provided via GET + query parameters,
// @Description or POST + body parameters. Program counters shall be space delimited.
// @Router /debug/pprof/symbol [get]
// @Router /debug/pprof/symbol [post]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
func SymbolHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Symbol(c.Writer, c.Request)
}
}
// TraceHandler will pass the call from /debug/pprof/trace to pprof
// TraceHandler
//
// @Summary Get a trace of execution of the current program
// @Description Only available, when server was started with WOODPECKER_LOG_LEVEL=debug
// @Description After you get the profile file, use the go tool pprof command to investigate the profile.
// @Router /debug/pprof/trace [get]
// @Produce plain
// @Success 200
// @Tags Process profiling and debugging
// @Param Authorization header string true "Insert your personal access token" default(Bearer <personal access token>)
// @Param seconds query int true "You can specify the duration in the seconds GET parameter." default (30)
func TraceHandler() gin.HandlerFunc {
return func(c *gin.Context) {
pprof.Trace(c.Writer, c.Request)