C
C#3y ago
Pokey

❔ Disable Swagger index.html Routing

I have just added and configured Swagger on my project with a custom rote, however, when launching my app on Debug, Swagger has taken over the root route / and redirects it to /index.html which is 404 because of my custom setup. How can I tell swagger to quit redirecting this and to leave it alone, and let my other routes take over (as I have a controller mapped to /)?
18 Replies
V0FBU1VM
V0FBU1VM3y ago
Show us the config. It's going to be hard, helping you like this.
Pokey
PokeyOP3y ago
Sure, I just assumed that it was a default function in Swagger One second
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("Developers", new OpenApiInfo
{
Title = "Open Radio Suite Orchestrator API",
Version = "API"
});

options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"));
});
builder.Services.AddSwaggerGen(options =>
{
options.SwaggerDoc("Developers", new OpenApiInfo
{
Title = "Open Radio Suite Orchestrator API",
Version = "API"
});

options.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml"));
});
Then
app
.UseSwagger(options =>
{
options.RouteTemplate = "Api/{documentName}/api.json";
})
.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/Api/Developers/api.json", "Open Radio Suite Orchestrator API");
options.RoutePrefix = "Api";
});
app
.UseSwagger(options =>
{
options.RouteTemplate = "Api/{documentName}/api.json";
})
.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("/Api/Developers/api.json", "Open Radio Suite Orchestrator API");
options.RoutePrefix = "Api";
});
When I access /Api I get swagger as desired. When I access / however, I get redirected to /index.html which is absolutely not what I want Ultimately, what I have works fine, just it insists on overriding my routing for /
V0FBU1VM
V0FBU1VM3y ago
Comment out route prefix and see what happens.
Pokey
PokeyOP3y ago
Well it's certainly stopped it from redirecting, however it has broken Swagger now
V0FBU1VM
V0FBU1VM3y ago
try this
.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("Api/Developers/api.json", "Open Radio Suite Orchestrator API");
options.RoutePrefix = "Api/Developers/";
});
.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("Api/Developers/api.json", "Open Radio Suite Orchestrator API");
options.RoutePrefix = "Api/Developers/";
});
Pokey
PokeyOP3y ago
Threw, Request path must not end in a slash removed
V0FBU1VM
V0FBU1VM3y ago
remove the end / from prefix
Pokey
PokeyOP3y ago
Now /Api is 404, /Api/Developers returns a broken swagger, but this is not what I wanted to achieve particularly
Pokey
PokeyOP3y ago
Pokey
PokeyOP3y ago
I do not ever intend to have multiple documents, hence I just want /Api to map to swagger
V0FBU1VM
V0FBU1VM3y ago
After searching for some solutions it seems like you need to change launchSettings
Pokey
PokeyOP3y ago
Nope, unfortunately not I couldn't care less how it launches The routing itself is broken
V0FBU1VM
V0FBU1VM3y ago
you wanna give it a try? try changing the launchUrl in launchSettings from swagger to Api/Developers
.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("Api/Developers/api.json", "Open Radio Suite Orchestrator API");
options.RoutePrefix = "Api/Developers";
});
.UseSwaggerUI(options =>
{
options.SwaggerEndpoint("Api/Developers/api.json", "Open Radio Suite Orchestrator API");
options.RoutePrefix = "Api/Developers";
});
Pokey
PokeyOP3y ago
I have no launchUrl at all The project was not created with Swagger It launches at / Swagger is mapping / to a redirect to /index.html and that overrides my controller mapped at /
V0FBU1VM
V0FBU1VM3y ago
Hm, then I'm not sure what's the issue mate. Sorry if I wasn't of help
Pokey
PokeyOP3y ago
Pokey
PokeyOP3y ago
No worries. What I had originally works fine Just Swagger being an arse Thank you
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server