Swagger UI Options
3 minute read
Complete reference for all Swagger UI configuration options (functions passed to WithSwaggerUI()).
Display Options
WithUIExpansion
func WithUIExpansion(expansion DocExpansion) UIOption
Controls initial document expansion.
Parameters:
expansion-DocExpansionList,DocExpansionFull, orDocExpansionNone
Values:
DocExpansionList- Show endpoints, hide details (default)DocExpansionFull- Show endpoints and detailsDocExpansionNone- Hide everything
Example:
openapi.WithUIExpansion(openapi.DocExpansionFull)
WithUIDefaultModelRendering
func WithUIDefaultModelRendering(rendering ModelRendering) UIOption
Controls how models/schemas are rendered.
Parameters:
rendering-ModelRenderingExampleorModelRenderingModel
Example:
openapi.WithUIDefaultModelRendering(openapi.ModelRenderingExample)
WithUIModelExpandDepth
func WithUIModelExpandDepth(depth int) UIOption
Controls how deeply a single model is expanded.
Parameters:
depth- Expansion depth (-1 to disable, 1 for shallow, higher for deeper)
Example:
openapi.WithUIModelExpandDepth(2)
WithUIModelsExpandDepth
func WithUIModelsExpandDepth(depth int) UIOption
Controls how deeply the models section is expanded.
Example:
openapi.WithUIModelsExpandDepth(1)
WithUIDisplayOperationID
func WithUIDisplayOperationID(display bool) UIOption
Shows operation IDs alongside summaries.
Example:
openapi.WithUIDisplayOperationID(true)
Try It Out Options
WithUITryItOut
func WithUITryItOut(enabled bool) UIOption
Enables “Try it out” functionality.
Example:
openapi.WithUITryItOut(true)
WithUIRequestSnippets
func WithUIRequestSnippets(enabled bool, languages ...RequestSnippetLanguage) UIOption
Shows code snippets for making requests.
Parameters:
enabled- Whether to show snippetslanguages- Snippet languages to show
Languages:
SnippetCurlBash- curl for bash/sh shellsSnippetCurlPowerShell- curl for PowerShellSnippetCurlCmd- curl for Windows CMD
Example:
openapi.WithUIRequestSnippets(true,
openapi.SnippetCurlBash,
openapi.SnippetCurlPowerShell,
openapi.SnippetCurlCmd,
)
WithUIRequestSnippetsExpanded
func WithUIRequestSnippetsExpanded(expanded bool) UIOption
Expands request snippets by default.
Example:
openapi.WithUIRequestSnippetsExpanded(true)
WithUIDisplayRequestDuration
func WithUIDisplayRequestDuration(display bool) UIOption
Shows how long requests take.
Example:
openapi.WithUIDisplayRequestDuration(true)
Filtering and Sorting Options
WithUIFilter
func WithUIFilter(enabled bool) UIOption
Enables filter/search box.
Example:
openapi.WithUIFilter(true)
WithUIMaxDisplayedTags
func WithUIMaxDisplayedTags(max int) UIOption
Limits the number of tags displayed.
Example:
openapi.WithUIMaxDisplayedTags(10)
WithUIOperationsSorter
func WithUIOperationsSorter(sorter OperationsSorter) UIOption
Sets operation sorting method.
Parameters:
sorter-OperationsSorterAlphaorOperationsSorterMethod
Example:
openapi.WithUIOperationsSorter(openapi.OperationsSorterAlpha)
WithUITagsSorter
func WithUITagsSorter(sorter TagsSorter) UIOption
Sets tag sorting method.
Parameters:
sorter-TagsSorterAlpha
Example:
openapi.WithUITagsSorter(openapi.TagsSorterAlpha)
Syntax Highlighting Options
WithUISyntaxHighlight
func WithUISyntaxHighlight(enabled bool) UIOption
Enables syntax highlighting.
Example:
openapi.WithUISyntaxHighlight(true)
WithUISyntaxTheme
func WithUISyntaxTheme(theme SyntaxTheme) UIOption
Sets syntax highlighting theme.
Available Themes:
SyntaxThemeAgate- Dark theme with blue accentsSyntaxThemeArta- Dark theme with orange accentsSyntaxThemeMonokai- Dark theme with vibrant colorsSyntaxThemeNord- Dark theme with cool blue tonesSyntaxThemeObsidian- Dark theme with green accentsSyntaxThemeTomorrowNight- Dark theme with muted colorsSyntaxThemeIdea- Light theme similar to IntelliJ IDEA
Example:
openapi.WithUISyntaxTheme(openapi.SyntaxThemeMonokai)
Authentication Options
WithUIPersistAuth
func WithUIPersistAuth(persist bool) UIOption
Persists authentication across browser refreshes.
Example:
openapi.WithUIPersistAuth(true)
WithUIWithCredentials
func WithUIWithCredentials(withCredentials bool) UIOption
Includes credentials in requests.
Example:
openapi.WithUIWithCredentials(true)
Additional Options
WithUIDeepLinking
func WithUIDeepLinking(enabled bool) UIOption
Enables deep linking for tags and operations.
Example:
openapi.WithUIDeepLinking(true)
WithUIShowExtensions
func WithUIShowExtensions(show bool) UIOption
Shows vendor extensions (x-*) in the UI.
Example:
openapi.WithUIShowExtensions(true)
WithUIShowCommonExtensions
func WithUIShowCommonExtensions(show bool) UIOption
Shows common extensions in the UI.
Example:
openapi.WithUIShowCommonExtensions(true)
WithUISupportedMethods
func WithUISupportedMethods(methods ...HTTPMethod) UIOption
Configures which HTTP methods are supported for “Try it out”.
Parameters:
methods- HTTP method constants (MethodGet,MethodPost,MethodPut, etc.)
Example:
openapi.WithUISupportedMethods(
openapi.MethodGet,
openapi.MethodPost,
openapi.MethodPut,
openapi.MethodDelete,
)
Validation Options
WithUIValidator
func WithUIValidator(url string) UIOption
Sets specification validator.
Parameters:
url-ValidatorLocal,ValidatorNone, or custom validator URL
Example:
openapi.WithUIValidator(openapi.ValidatorLocal)
openapi.WithUIValidator("https://validator.swagger.io/validator")
openapi.WithUIValidator(openapi.ValidatorNone)
Complete Example
openapi.WithSwaggerUI("/docs",
// Display
openapi.WithUIExpansion(openapi.DocExpansionList),
openapi.WithUIModelExpandDepth(1),
openapi.WithUIDisplayOperationID(true),
// Try it out
openapi.WithUITryItOut(true),
openapi.WithUIRequestSnippets(true,
openapi.SnippetCurlBash,
openapi.SnippetCurlPowerShell,
openapi.SnippetCurlCmd,
),
openapi.WithUIDisplayRequestDuration(true),
// Filtering/Sorting
openapi.WithUIFilter(true),
openapi.WithUIOperationsSorter(openapi.OperationsSorterAlpha),
// Syntax
openapi.WithUISyntaxHighlight(true),
openapi.WithUISyntaxTheme(openapi.SyntaxThemeMonokai),
// Auth
openapi.WithUIPersistAuth(true),
// Validation
openapi.WithUIValidator(openapi.ValidatorLocal),
)
Next Steps
- See Options for API-level configuration
- Check Swagger UI Guide for detailed usage
- Review Examples for complete patterns
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.