Swagger UI shows empty page - How to fix?
See original GitHub issueStranded here after unsuccessfully publishing this issue at StackOverflow and swagger-api/swagger-ui:
I added Swashbuckle.AspNet.Core to my repository and initialized everything using defaults.
Although I can see JSON output from /swagger/v1/swagger.json opening /swagger/index.html just yields an empty page.
Why?
Here’s my code
public void ConfigureServices(IServiceCollection services)
{
services
.AddSwaggerGen()
.AddControllers()
;
}
// This method gets called by the runtime once. Use this method to configure the HTTP request pipeline.
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, Options options)
{
if (env.IsDevelopment()) app.UseDeveloperExceptionPage();
app
.UseHttpsRedirection()
.UseRouting()
.UseAuthorization()
.UseEndpoints(endpoints => endpoints.MapControllers())
.UseSwagger()
;
if (env.IsDevelopment()) app.UseSwaggerUI();
}
Issue Analytics
- State:
- Created 3 years ago
- Comments:8
Top Results From Across the Web
Swagger-ui.html is giving blank page
When I am trying to enable swagger in my spring boot application, it is showing blank page. I am using url https://localhost:8080/context-path/ ...
Read more >Swagger UI page is blank on localhost IISExpress SSL URL
I can access the WebApi from any of the other URLs and the SwaggerUI page is displayed as it should be. It is...
Read more >Swagger UI: Preview only shows a blank page : IDEA-291069
After replacing, the path there should be npmLibraries/swagger-ui-dist/package . Then reopen this swagger file and you should able to use it now ...
Read more >[Solved]-Swagger-ui.html is giving blank page-Springboot
After a lot of time it is got worked for me,In my application I am using spring security so configurations were mismatched. That's...
Read more >[FastAPI - Swagger UI] Blank Page
Hi, I am a newbie. I follow instructions of FastAPI and when I input 127.0.0.1:8000/docs on the webrowser, I get INFO: 200 OK...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

Update 2:
It appears that the “c.SwaggerEndpoint” call is NOT OPTIONAL and MUST BE SPECIFIED
None of the documentation I’ve read tells the user this, and so it’s quite feasible that like myself and @SetTrend that we would leave this out.
As for the reason I had that call commented out in my screen shots above, I was actually trying to solve A 404 error with “/swagger” not being found when I landed here.
I’ve since figured out that the cause of my problem was bogus advice from the MS-Docs site which suggests setting “c.RoutePrefix” to String.Empty.
@SetTrend for now you can resolve your problem, simply by specifying your “c.SwaggerEndpoint” call in the same manner I do in the above image. This add’s a single swagger JSON document object to the UI for you to use.
@SetTrend I’ve not looked deep enough into the code to be honest, it only bit me because I was trying to solve a micro-services rest boundary problem on one of my clients projects 😃 but I guess it wouldn’t be a huge ache, my best guess without looking at the code would be to copy the default generated URL into the config object in .NET at some appropriate point.
PS: I’ve answered your Stack Overflow post too 😃