Last active
October 1, 2024 09:01
-
-
Save dj-nitehawk/ba223a3dd415407a3e664a4a2b61dbc7 to your computer and use it in GitHub Desktop.
Customizing Swagger Middleware & UI Paths
This file contains 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
app.UseSwaggerGen( | |
s => | |
{ | |
//where to serve swagger.json files from | |
s.Path = "/PREFIX/swagger/{documentName}/swagger.json"; | |
//api endpoint server base path customization | |
s.PostProcess = (document, request) => | |
{ | |
document.Servers.Clear(); | |
document.Servers.Add( | |
new() | |
{ | |
Url = $"{request.Scheme}://{request.Host}/PREFIX" | |
}); | |
}; | |
}, | |
ui => | |
{ | |
//where to serve swagger ui from | |
ui.Path = "/PREFIX/swagger"; | |
//where the ui looks for swagger.json files | |
ui.DocumentPath = "/PREFIX/swagger/{documentName}/swagger.json"; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment