c# - Swagger 响应格式示例异常
问题描述
当我尝试在 swagger 帮助部分查看我的 api 时收到此错误消息。我需要添加什么来阻止此错误吗?
Response Formats
application/json
Sample:
An exception has occurred while using the formatter 'JsonMediaTypeFormatter' to generate sample for media type 'application/json'. Exception message: Self referencing loop detected with type 'Model.Disease'. Path '[0].Types[0].List'.
text/json
Sample:
An exception has occurred while using the formatter 'JsonMediaTypeFormatter' to generate sample for media type 'text/json'. Exception message: Self referencing loop detected with type 'Disease'. Path '[0].Types[0].List'.
application/xml
Sample:
An exception has occurred while using the formatter 'XmlMediaTypeFormatter' to generate sample for media type 'application/xml'. Exception message: There was an error generating the XML document.
text/xml
Sample:
An exception has occurred while using the formatter 'XmlMediaTypeFormatter' to generate sample for media type 'text/xml'. Exception message: There was an error generating the XML document.
解决方案
GuidelineDataLayer.Model.Disease 是你自己的代码吗?您的对象中有一个循环引用,它阻止了模型序列化。再次检查您的代码,并确保您没有 2 个类相互指向。
推荐阅读
- laravel - 在 Laravel 8 火线中显示图像
- postgresql - 为每一行运行存储函数,然后导出到 CSV 文件
- reactjs - 单击 Formik Field 单选按钮并更新值,但未显示选中的单选按钮
- excel - 在 Excel 中搜索文本框文本
- html - HTML 多选中的选项突出显示
- dictionary - 我如何在python中创建一个嵌套字典的字符串(无循环)作为其相应树的一系列分支
- python - 熊猫 groupby 和 sum if 条件
- c++ - unique_ptr 用于具有 C++20 破坏运算符删除的非多态派生类
- visual-studio-code - 是否有任何 vscode 扩展可以找到错误大小写的变量名?
- html - 在 Linux 中链接文本文件