Search code examples
c#.netswagger-uiswashbuckle.net-7.0

Swagger UI Endless Spinner On Load


I am trying to implement Swashbuckle Swagger to a .NET 7 project. However, when I load the Swagger UI, I get an endless spinner. It appears to be going into some endless loop, presumably trying to create the swagger.json, as if i leave it for long enough and can watch my machine's memory get filled and then crash.

enter image description here

And when reviewing the call to the swagger.json file it just shows it is being fetched.

enter image description here

Here is the code in the Configure method of Startup.cs. I have tried altering the json path to swagger/v1/swagger.json, /v1/swagger.json, v1/swagger.json and event ../swagger/v1/swagger.json, all exhibit the same behaviour.

app.UseSwagger();
app.UseSwaggerUI(c =>
     {
     c.SwaggerEndpoint("/swagger/v1/swagger.json", "RackEmApp API V1");
     });

And this is taken from the ConfigureServices method in Startup.cs

services.AddSwaggerGen(c =>
     {
          var xmlFilename = $"{Assembly.GetExecutingAssembly().GetName().Name}.xml";
          c.IncludeXmlComments(Path.Combine(AppContext.BaseDirectory, xmlFilename));

          c.SwaggerDoc("v1", new OpenApiInfo
          {
               Version = "v1",
               Title = "RackEmApp API",
               Description = "A Web API for developers to interact with the RackEmApp dataset for a given league/organization. This is in development and has limited support.",
                    
           });

                
       });

Solution

  • Through a trial and error of deleting my controllers I identified that the issue was that I had this annotation on the Controller

    [ApiExplorerSettings(IgnoreApi = true)]
    

    And in an action within that same controller I had this

    [ApiExplorerSettings(IgnoreApi = false)]
    

    This obviously sent swagger into an endless loop. Removing it from the action fixed it.