Swagger UI freezes after API fetch and browser crashes

拜拜、爱过 提交于 2019-12-05 08:24:24

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.

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

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!