[英]Swashbuckle.AspNetCore (5.0.0-rc5) ignoring public fields
First off, this worked fine in Swashbuckle.AspNetCore v4.首先,这在 Swashbuckle.AspNetCore v4 中运行良好。 So given this model & endpoint;
因此,鉴于此模型和端点;
public class TestRequest
{
public string test1 { get; set; }
public string test2;
}
[HttpPost]
public void Post([FromBody] TestRequest value)
{
}
Swagger only shows; Swagger 只显示;
{
"test1": "string"
}
as the example TestRequest value.作为示例 TestRequest 值。
Is this behaviour intended now?这种行为现在是有意的吗? Is there anyway to change this via setup or filters?
有没有办法通过设置或过滤器来改变这个? I have a ton of imported services that only use fields.
我有大量仅使用字段的导入服务。 (generated by dotnet-svcutil, which is pretty common)
(由 dotnet-svcutil 生成,这很常见)
ok, taking @Flydog57 suggestion to figure it out myself, I found that the new Swashbuckle.AspNetCore is using the MS json.net over Newtonsoft.好的,根据@Flydog57 的建议自行解决,我发现新的 Swashbuckle.AspNetCore 正在通过 Newtonsoft 使用 MS json.net。
So reading over the git readme a tenth time at https://github.com/domaindrivendev/Swashbuckle.AspNetCore所以在https://github.com/domaindrivendev/Swashbuckle.AspNetCore 上第十次阅读 git readme
I found that there is a way to revert the json serializer back to Newtonsoft.我发现有一种方法可以将 json 序列化程序恢复为 Newtonsoft。 First (as of the 5.0.0-rc5 release) install this package;
首先(从 5.0.0-rc5 版本开始)安装这个包;
Install-Package Swashbuckle.AspNetCore.Newtonsoft -Version 5.0.0-rc5
Then in Start.ConfigureServices tell Swashbuckle to use by;然后在 Start.ConfigureServices 中告诉 Swashbuckle 使用;
services.AddSwaggerGenNewtonsoftSupport();
Now you'll find all those public "Fields" have reappeared in your swagger page.现在,您会发现所有这些公共“字段”都重新出现在您的 swagger 页面中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.