In my localhost, my swagger UI working well. localhost:3030/documentation This UI was working on the server also but from today on the server it is not working https://digitalpathshalabd.com/documentation
Errors
In my localhost, my swagger UI working well. localhost:3030/documentation This UI was working on the server also but from today on the server it is not working https://digitalpathshalabd.com/documentation
Errors
I faced the same "SwaggerUIBundle is not defined" with a blank page. Also the problem only on server and not local. And it also had worked in the past. Then when I ctrl+f5 the local swagger page, it then also appeared local.
For us it appeared the Configuration order was swapped. For me the fix was moving app.UseRouting() after the swagger init
public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerFactory loggerFactory)
{
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Procedure Service V1");
c.RoutePrefix = "";
});
app.UseRouting();
I am using org.springdoc:springdoc-openapi-ui:1.6.9 version and was facing this problem.
I checked https://www.npmjs.com/package/swagger-ui and added maven dependency for a lower swagger-ui version 3.0.21
<dependency>
<groupId>org.webjars</groupId>
<artifactId>swagger-ui</artifactId>
<version>3.0.21</version>
</dependency>
I found that the "swagger-ui/index.html" does not reference "swagger-initializer.js" , instead its source code is present in index.html itself (this the boiler-plate referring to pet store)
So in my Spring boot classpath resources/public folder, I copied the older swagger dist index.html file (which has the initializer code) and did the following changes
<script charset="UTF-8" src="./swagger-ui/swagger-ui-bundle.js"></script>
<script charset="UTF-8" src="./swagger-ui/swagger-ui-standalone-preset.js"> </script>
Check your swagger middleware configured correctly?
public void ConfigureServices(IServiceCollection services)
{
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
});
services.AddControllers();
}
This adds the Swagger generator to the services collection. In the Configure() method, let’s enable the middleware for serving the generated JSON document and the Swagger UI:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
app.UseSwagger();
// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});
}