Swagger UI freezes after API fetch and browser crashes

11,485

Solution 1

I was able to comment out each of my API controllers, load the swagger page, and then turn them back on until the page crashed again. Once I figured out which controller was the issue, I repeated the process with all of the endpoints in the controller.

It turned out that one of our very old methods was taking an ORM entity as a body parameter (very bad), which was causing swagger to try to parse our entire ORM object graph and running out of memory. Changing this method to accept a DTO instead of data layer entity solved the problem.

Solution 2

I think this is a known bug when you use non standard serializer or configuration of your web api is non standard.

It is a a circular reference problem.

see the issue in git hub repository : https://github.com/domaindrivendev/Swashbuckle/issues/486

Solution 3

If anyone else runs into this issue and nothing seems to be helping you, here is what I found with our code.

We had a guy contracted to write our API, and he must have automatically imported a bunch of classes based on the DB Schema, but what it did was create a ton of partial classes with references to other partial classes, who in turn had references back to the original class.

So this ended up being a circular reference issue, as mentioned above, but not exactly the same. It took me a while to figure out what what different but as soon as I commented out the references to the other partial classes, everything worked great.

My suggestion would be a combination of the 2 answers above, use your own DTOs and make sure you don't have circular references.

Another important hang-up was in our [Route()] tags, the guy had put [Route("{model}"] and in the parameters of the POST/PUT method, he was using the [Route("{model}")] tag to parse the JSON body for the model, so having it in the Route tag was unnecessary and causing issues. It should have just been [Route("")].

Share:
11,485
jbabey
Author by

jbabey

javascript/jquery lover!

Updated on June 13, 2022

Comments

  • jbabey
    jbabey almost 2 years

    I have an ASP.NET WebAPI project where I am attempting to replace our old XmlDocumentationProvider page with Swagger UI. I am using the swashbuckle swagger for webAPI 5.3.1 nuget package.

    I am able to navigate to localhost/MyApp/swagger, and I can see in fiddler that it makes a call to localhost/MyApp/swagger/docs/v1 to retrieve the JSON string representing my API. The call succeeds, the JSON is about 240KB, and the JSON is valid. At this point, the chrome tab freezes for about 30 seconds before crashing with the "Aw snap" page. There are no errors in the console.

    Attempting to validate the api JSON in this online validator works and says the spec/schema is valid IF AND ONLY IF I uncheck all three of the "Follow ___ $refs" checkboxes. If any of those boxes are ticked, it takes about 30 seconds and then that tool crashes.

    Unfortunately I can't paste my entire webAPI spec somewhere, but I will say that it is for a very large and very complicated internal business application. Some of our DTOs have circular references (properties of the same type as the DTO itself) which I suspect may be causing a problem, but without any logging or debugging I cannot be sure, and with over 1000 DTO classes I don't want to comb through them all to check.

    Is there any way to turn on any sort of logging or debugging for swashbuckle (on the server) or swagger UI (on the client)? Has anyone ran into this issue with the browser crashing and know what is causing it? Thanks ahead of time.