OPEN SWAG GO
Features

Try-It Console

The interactive console that sends real requests from the docs page is part of the Scalar API reference UI that docs.Mount (or docs.Handler()) serves. It is available on every operation automatically; there is nothing to enable or configure in Go. Request history, environments and the other console features behave as in Scalar, and depend on the Scalar version you load.

What open-swag-go controls

The console is built from the generated openapi.json, so the spec is what you shape:

You setEffect in the console
Endpoint.Parameters, QueryParams, PathParamsParameter inputs, with descriptions, examples, enums and required markers from struct tags
Endpoint.RequestBodyThe request body editor; field examples come from example:"..." tags
Config.ServersThe base URLs listed in the spec, which the console sends requests to
Endpoint.Security and Config.AuthThe authentication inputs; see Auth Playground
UIConfig.ScalarVersionWhich Scalar release, and therefore which console behaviour, is loaded (v1.3.0+)
servers.go
docs := openswag.New(openswag.Config{
	Info: openswag.Info{Title: "My API", Version: "1.0.0"},
	Servers: []openswag.Server{
		{URL: "http://localhost:8080", Description: "Local"},
		{URL: "https://api.example.com", Description: "Production"},
	},
})

CORS

The console runs in the browser, so its requests go straight from the docs page to your API.

  • UIConfig.SpecCORSOrigin (v1.3.0+) only sets the Access-Control-Allow-Origin header on the spec endpoint (openapi.json): "" sends *, "-" omits the header, any other value is sent as-is. It matters when another origin loads the spec.
  • open-swag-go does not add CORS headers to your API routes. If the docs are served from a different origin than a server in Config.Servers, that API has to allow the docs origin itself, or the browser blocks the console's requests.

Earlier versions of this page documented a Go package for console settings, environments and request history. It was never connected to the docs UI, so its settings had no effect, and it was removed in v1.3.0. See the Changelog.