c# - 要在 Web api 中发布的 TimeSpan 属性的有效值? C#

标签 c# swagger asp.net-core-webapi timespan

我有一个 TimeSpan 属性

public TimeSpan Time { get; set; }

目前使用 swagger 测试 API
试图找出在这里传递的值

“时间”: {},

尝试:

“时间”:{“01:01:01”},

“时间”:{“01:01”},

"时间": "01:01:01",

“时间”:01:01:01,

全部返回 401 代码

最佳答案

在另一个页面上,您将找到问题的解决方案:.Net Core 3.0 TimeSpan deserialization error - Fixed in .Net 5.0 .
以补充的方式,在 Swagger 中添加这个

c.MapType<TimeSpan>(() => new OpenApiSchema
                {
                    Type = "string",
                    Example = new OpenApiString("00:00:00")
                });

关于c# - 要在 Web api 中发布的 TimeSpan 属性的有效值? C#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60622946/

相关文章:

c# - 将 C# 应用程序注册为 shell 应用程序

c# - 在 unix (nginx) 上托管时 .NET Core 中的 TimeZoneInfo

cookies - OpenAPI安全方案: What is 'type' used for in Cookie auth?

c# - Process.Start 在 .net 核心中给出文件未指定错误

c# - 在 ASP.NET Core Web Api 中将初始化步骤放在哪里?

azure - 如何调试承载错误="invalid_token"

c# - 波兰字符接收消息 imap

c# - 单元测试遗留代码 : limits of "extract and override" vs JustMock/TypeMock/moles?

c# - SwashBuckle/Swagger 隐藏了我的不可变属性

arrays - 如何创建包含不同类型数组的 swagger 模式