Reputation: 183
I use swashbuckle in my ASP.Net Core 3.1 with swagger UI. When I click on a model, the whole webpage crashes/freezes. I use a lot (100 approx) Entity Framework Core entities (7000 lines of JSON).
I switched to Nswag to see if it would be better. No more crashes but still quite slow (10 seconds when you click on a model, 20 on a method)
Should I make DTOs or is there a solution for my problem?
I also tried adding this to my startup but it does not help at all.
services.AddControllers().AddNewtonsoftJson(x =>
{
x.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
});
Upvotes: 2
Views: 3966
Reputation: 29
I came across this issue today in a more modern version (ASP.NET Core 8.0).
So it was an easy fix, I just forgot to await a service call.
Before:
[HttpGet]
public ActionResult Get()
{
return Ok(profileService.GetMyProfilesAsync());
}
After:
[HttpGet]
public async Task<ActionResult> Get()
{
return Ok(await profileService.GetMyProfilesAsync());
}
Hope this helps anyone who makes the same tiny mistake :)
Upvotes: 0
Reputation: 183
I ended up switching to NSwag and using DTOs. The lag/crash is gone.
Upvotes: 0
Reputation: 17594
From what you are reporting it seems that your swashbuckle is using an old version of the swagger-ui, there should not be any significant difference from Nswag and swashbuckle if they have the same version of swagger-ui.
But this issue has been discussed on the project, complex nested models when fully expanded are huge, here is some data I collected a while back:
https://github.com/swagger-api/swagger-ui/issues/4411#issuecomment-380168870
| Schema | SchemaSize | ExampleSize | ModelSize |
|------------------------------------------------------------|------------|-------------|------------|
| http://swagger-net-test.azurewebsites.net/api/NestedSwag/2 | 1,368 | 10,578 | 262,519 |
| http://swagger-net-test.azurewebsites.net/api/NestedSwag/3 | 1,662 | 59,703 | 1,321,999 |
| http://swagger-net-test.azurewebsites.net/api/NestedSwag/4 | 1,956 | 332,828 | 6,640,079 |
| http://swagger-net-test.azurewebsites.net/api/NestedSwag/5 | 2,250 | 1,835,953 | 33,305,772 |
As you can see expanding those complex models can be a costly task on the browser.
Upvotes: 1