Documentation
¶
Overview ¶
Package swaggerui serves Swagger UI, embedded in the binary, for the openapi package:
openapi.New(openapi.Options{UI: swaggerui.New()})
Importing it adds about 1.5 MB to the binary, which is why it is a package of its own: an app that only wants the document does not import it. Nothing is fetched from the network, so the page works offline. Under a strict Content-Security-Policy the page needs three relaxations: 'unsafe-inline' in style-src, data: in img-src, and 'self' in connect-src so it can fetch the document. WithContentSecurityPolicy grants them on the page's route only.
Index ¶
Constants ¶
const Version = "5.17.14"
Version is the swagger-ui-dist release the assets come from.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Option ¶ added in v0.8.0
type Option func(*UI)
Option configures New.
func WithContentSecurityPolicy ¶ added in v0.8.0
WithContentSecurityPolicy serves the UI page under app with three changes: style-src is 'self' and 'unsafe-inline', because Swagger UI writes inline styles at runtime; img-src is app's effective img-src with data: added, because its styles reference data: images; and connect-src is app's effective connect-src with 'self' added, so the page can fetch its own document. An absent directive falls back to default-src, and a directive that restricts nothing is left unrestricted. Every other directive of app is kept, so the relaxation is confined to the page's route. The middleware sets the page's header in place of the application's. The document, the assets and the rest of the application keep app's policy.