当枚举处于路径中时,Swashbuckle / Swagger缺少枚举信息
我使用swashbuckle有一个C#.NET 6 API为客户生成Swagger文档。
我有swashbuckle.aspnetcore 6.3.1和 *.filters 7.02安装了。
在startup.cs中,我
...
swaggerOptions.UseInlineDefinitionsForEnums();
swaggerOptions.SchemaFilter<EnumDescriptionFilter>(); // Custom filter.
...
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
})
我尝试摆弄配置,尝试注释软件包,切换到Newtonsoft等。但是没有运气。
如果将参数的类型更改为字符串,那么我会在Swagger中获得一种类型的字符串,但是我无法获得可能的值。
知道我缺少什么吗?
谢谢。
更新。进一步播放后,在查询中只能正确显示列表。如果我将[FromQuery] vehicletype车辆
添加到路线上,则它不带有类型的形式出现。
同时,[FROFQUERY]列表&lt; vehicletype&gt;车辆型
正确显示。
更新2:看起来这是OpenApi.net的问题 https://github.com/domaindrivendev/swashbuckle.aspnetcore.aspnetcore/issues/1329#:~:~: 20%28 Look%20AT%20Justenum%20in和%20次序列化%20to%20JSON%20BEHAVIOR%20 from%20THAT%20Library 。
根据线程,这是该错误的工作:
swaggerGenOptions.UseInlineDefinitionsForEnums();
I have a C# .Net 6 API using Swashbuckle to generate Swagger docs for clients.
I have Swashbuckle.AspNetCore 6.3.1 and *.Filters 7.02 installed.
In Startup.cs, I have
...
swaggerOptions.UseInlineDefinitionsForEnums();
swaggerOptions.SchemaFilter<EnumDescriptionFilter>(); // Custom filter.
...
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull;
options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter());
})
I have several enums in the APIs that are string serialized. This works great when the enum is in the query string:
However, this doesn't work when the enum is in the path:
I've tried fiddling with the configuration, experimenting with the Annotations package, switching to Newtonsoft, etc. but have had no such luck.
If I change the type of the parameter to string then I get a type of string in the swagger, but I don't get the possible values.
Any idea what I'm missing?
Thanks.
Update. Upon further playing around, in the querystring only List show up correctly. If I add [FromQuery] VehicleType vehicleType
to a route, then it shows up without a type.
At the same time, [FromQuery] List<VehicleType> vehicleTypes
shows up correctly.
Updated 2: Looks like this is an issue with OpenAPI.NET
https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1329#:~:text=Enum%20type%20is%20missing%20%28look%20at%20JustEnum%20in,and%20serialization%20to%20JSON%20behavior%20from%20that%20library.
As per the thread, this is a work around for the bug:
swaggerGenOptions.UseInlineDefinitionsForEnums();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论