Swagger UI freezes after API fetch and browser crashes

后端 未结 5 844
臣服心动
臣服心动 2021-01-12 20:41

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

相关标签:
5条回答
  • 2021-01-12 20:58

    Check your ResponseType attribute for your api methods. In my case while i was modifying an api method i forgot to delete reponsetype since i removed returning an object.

    0 讨论(0)
  • 2021-01-12 21:02

    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

    0 讨论(0)
  • 2021-01-12 21:02

    I had the same issue. Finally I could leave my [ResponseType()] as is with an ORM entity as I wanted to, but I managed to make swagger not freeze by adding another model in [SwaggerResponse()]

    Here is more info in that: https://mattfrear.com/2015/04/21/generating-swagger-example-responses-with-swashbuckle/

    0 讨论(0)
  • 2021-01-12 21:20

    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.

    0 讨论(0)
  • 2021-01-12 21:24

    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("")].

    0 讨论(0)
提交回复
热议问题