5

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

img_error

Mir Rahed Uddin
  • 1,208
  • 2
  • 12
  • 25
  • Did you server configuration change? The `net::ERR_INCOMPLETE_CHUNKED_ENCODING` error is not from Swagger UI. See if this helps: [Chrome net::ERR_INCOMPLETE_CHUNKED_ENCODING error](https://stackoverflow.com/q/29894154/113116) – Helen Sep 18 '20 at 12:23

3 Answers3

2

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();
0

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

  1. Changed the url part to point to my api-docs url. (e.g. /v3/api-docs)
  2. Added "swagger-ui" to the src references, so that the swagger bundles/js will be called successfully from my index.html
<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>
  1. When I accessed index.html - http://{server}:{port}/index.html- I could access my local Open API doc.
BigHeadNelson
  • 73
  • 1
  • 4
0

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");  
     });  
}