swashbuckle生成内部C#类的模式
使用swashbuckle.aspnetcore
(版本6.3.1)与system.text.json时,该架构会从c#中生成一堆内部设备,例如incoper> assembly 的架构> constructorInfo
等。
我认为,当我创建一个返回接口(可能)的端点时,就会发生这种情况。不完全确定。如果我利用swashbuckle.aspnetcore.newtonsoft
软件包来生成宣传文档,那不是问题 - 这些模式未生成。但是,我希望不依赖纽顿夫妇,这是获得有效模式的唯一原因。
这不是一个大问题,但是我们的OpenAPI/Swagger文档有无关紧要的信息有点烦人。我很想解决这个问题。
这是一个已知的错误吗?有办法解决吗?任何帮助都将不胜感激。
我试图搜索问题的不同组合,但没有成功。我的查询技巧我很糟糕,所以如果已经问这个问题,那我真的很抱歉。
编辑: 该错误似乎是由于我们有一个具有自定义序列化器在API中公开的值类型。该对象具有type
属性,但是,由于序列化器,这实际上从未在API中曝光 - (我们也向Swashbuckle注册,因此实际上并未在Swashbuckle文档中曝光,但是,我认为Swashbuckle在我们注册“正确”序列化器之前已经将对象添加到模式中。)
When using Swashbuckle.AspNetCore
(version 6.3.1) with System.text.json, the schemas generate a bunch of internals from c#, like a schema for Assembly
, ConstructorInfo
, and others.
I think this happens when I've created an endpoint that returns an interface (possibly). Not entirely sure. If I utilize the Swashbuckle.AspNetCore.Newtonsoft
package for generating the swagger documentation it isn't a problem - these schemas are not generated. I'd however like to not have a dependency on newtonsoft for the sole reason of getting the valid schemas.
It's not a huge issue, however it is a bit annoying that our openapi/swagger docs have irrelevant information. I'd love to get around that.
Is this a known bug? Is there a way around it? Any help would be much appreciated.
I've tried to search for different combinations of the problem, but with no success. My querying skills my be bad, so if this question has already been asked, then I am truly sorry.
EDIT:
The bug seems to be due to the fact that we have a value type that we expose in the API with a custom serializer. that object has a Type
property, however, this is never actually exposed in the API due to the serializer - (which we also registered with Swashbuckle, so it isn't actually exposed in the Swashbuckle documentation, however, I assume Swashbuckle already added the objects to the schema prior to us registering the "correct" serializer.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
删除它的一种方法是通过
iDocumentFilter
这样:在您的di中,您注册Swagger只需添加此信息
One way to remove it is by an
IDocumentFilter
like this:in you DI where you register swagger just add this
我偶然发现了这个问题,因为我遇到了同样的问题。就我而言,该问题是通过指定
filenotfoundexception
为wessioneType
:在我创建自己的
filenotfoundresponse
class之后,并将其指定为<代码>响应类型,内部.NET类不再显示为架构:
这种行为可能在其他内部类型中也发生。但是,我尚未对此进行测试。
因此,我不知道它是否解决了OP的问题,但也许会对某人有所帮助。
I stumbled across this question because I had the same problem. In my case, the issue was caused by specifying a
FileNotFoundException
as theResponseType
:After I created my own
FileNotFoundResponse
class:and specified it as
ResponseType
, the internal .NET classes were no longer displayed as schema:This behavior probably occurs with other internal types as well. However, I have not tested this.
So I don't know if it solves the OP's problem, but maybe it will help someone.