Skip to content

Instantly share code, notes, and snippets.

@stormwild
Forked from dj-nitehawk/Program.cs
Created October 1, 2024 09:01
Show Gist options
  • Save stormwild/62b5172f2093f0b69bc2f780d8a6eee3 to your computer and use it in GitHub Desktop.
Save stormwild/62b5172f2093f0b69bc2f780d8a6eee3 to your computer and use it in GitHub Desktop.
Customizing Swagger Middleware & UI Paths
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