# go-apispec: Generate OpenAPI from Go code

A command-line tool that statically analyzes Go source code and generates an OpenAPI 3.1 spec, auto-detecting the web framework in use and following the call graph from routes to handlers to infer request and response types.

go-apispec points at a Go module, detects which web framework it uses, and follows the call graph from each route to its handler to infer the request body, parameters and response types, without needing annotations in the source. It generates the spec as YAML or JSON.

It supports Chi, Gin, Echo, Fiber, Gorilla Mux and net/http, including their route parameter styles, request-body binding calls and response-writing calls, and correctly normalizes each router's own path-template syntax, such as gorilla/mux's regex constraints or Go 1.22's `ServeMux` method-prefix patterns, into OpenAPI path placeholders. Projects using more than one framework at once are supported, with routes from every detected framework appearing together in one spec.

It also infers a response's content type from explicit header-setting calls, with a fallback for dynamic content types, and detects response writes made through `fmt.Fprintf`, `io.Copy` and `io.WriteString` in every supported framework.

Website: https://github.com/antst/go-apispec
