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 set | Effect in the console |
|---|---|
Endpoint.Parameters, QueryParams, PathParams | Parameter inputs, with descriptions, examples, enums and required markers from struct tags |
Endpoint.RequestBody | The request body editor; field examples come from example:"..." tags |
Config.Servers | The base URLs listed in the spec, which the console sends requests to |
Endpoint.Security and Config.Auth | The authentication inputs; see Auth Playground |
UIConfig.ScalarVersion | Which Scalar release, and therefore which console behaviour, is loaded (v1.3.0+) |
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 theAccess-Control-Allow-Originheader 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.