Repository navigation
feat(doc): customize the docs page tab title and icon - #77
Merged
Merged
Conversation
SwaggerUIHandler takes variadic SwaggerUIOption values: WithTitle sets
the page title and WithFavicon sets the tab icon (URL or data: URI).
Both are HTML-escaped; empty values keep the defaults. The page now
ships a generic inline "{ }" SVG icon by default, so the tab never shows
the browser globe. The Exporter interface is unchanged; services pass
options through the registry by registering their own exporter.
Fixes #73
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #73 (API-17).
Scope
doc.SwaggerUIHandler(openAPIURL string, opts ...SwaggerUIOption),doc.WithTitle,doc.WithFavicon, a generic default favicon, tests, Examples, README anddocs/openapi.md.Exporterinterface and the built-inswaggerexporter (unchanged, changing them would be breaking).Changes
SwaggerUIOption func(*swaggerUIConfig)(unexported config). Options are applied once when the handler is built; nil options are skipped.WithTitle(title): page<title>; defaultAPI Docs; empty keeps the default.WithFavicon(href): URL ordata:URI (PNG, SVG, ICO), written as<link rel="icon">; empty keeps the default.html.EscapeString. Nothtml/template: its URL filter rewritesdata:URIs to#ZgotmplZ. The JSON-encoded OpenAPI URL and the swagger-ui-dist 5.34.1 SRI pins are unchanged.<link rel="icon">with an original, single-color (#808080){ }SVG, URL-encoded as adata:image/svg+xml,...URI (no external fetch, no third-party logo).WithFaviconreplaces it.doc.ExporterByNameregister their own exporter that callsSwaggerUIHandlerwith options (ExampleRegisterExporter,docs/openapi.md). Using a distinct name keeps the built-inswaggeruntouched.Release notes (v1.1.0)
doc.SwaggerUIHandleraccepts options:doc.WithTitle("Orders API"),doc.WithFavicon("/static/icon.png")(URL ordata:URI). Values are HTML-escaped. Existing calls compile unchanged.{ }SVG), so the browser tab no longer shows the generic globe. The default page differs from v1.0.0 only by that one<link rel="icon">line; the title is stillAPI Docs.data:URIs passed toWithFavicon(a raw#starts a URL fragment).Verification
Test-first: a golden file (
doc/testdata/swagger-ui-default.html, the v1.0.0 page plus the icon line) and table-driven tests for title/favicon values, escaping/injection, empty values, nil option and the default icon's encoding (decodes to well-formed SVG).gofmt -l .: no outputgo vet ./...: okgo test -race ./...: ok (all packages,ExampleSwaggerUIHandler,ExampleRegisterExporter)govulncheck ./...: no vulnerabilities found🤖 Generated with Claude Code