简体   繁体   English

Swashbuckle.AspNetCore (5.0.0-rc5) 忽略公共字段

[英]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.

相关问题 多版本控制 URL 在 Swashbuckle.AspNetCore 5.0.0rc 中不起作用 - Multiple versioning URL not working in Swashbuckle.AspNetCore 5.0.0rc Swashbuckle.AspNetCore仅生成带有字符串类型字段的模型 - Swashbuckle.AspNetCore only generating models with fields of type string 可选参数在Swashbuckle.AspNetCore中导致空异常 - Optional parameter causes null exception in Swashbuckle.AspNetCore Swashbuckle.AspNetCore-无法为继承基本控制器的控制器生成json - Swashbuckle.AspNetCore - Unable to generate json for controllers that inherit base controllers 迁移到 Swashbuckle.AspNetCore 版本 5 时,Swagger UI 中的不记名身份验证 - Bearer authentication in Swagger UI, when migrating to Swashbuckle.AspNetCore version 5 Swashbuckle.AspNetCore openapi 架构中未正确显示可空属性 - Nullable property is not presented in the Swashbuckle.AspNetCore openapi schema properly 无法解析 .net5.0 的“Swashbuckle.AspNetCore (>= 5.6.3)” - Unable to resolve 'Swashbuckle.AspNetCore (>= 5.6.3)' for 'net5.0' 如何使用Swashbuckle.AspNetCore隐藏响应代码200? - How can I hide response code 200 with Swashbuckle.AspNetCore? swashbuckle.aspnetcore 是否支持 asp.net core 3.0? - Is swashbuckle.aspnetcore supporting asp.net core 3.0? Swashbuckle.AspNetCore是否支持FluentValidation而不是DataAnnotations? - Does Swashbuckle.AspNetCore support FluentValidation instead of DataAnnotations?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM