相关疑难解决方法(0)

在OpenAPI/Swagger文件中声明日期的正确方法是什么?

在swagger文件对象中声明日期的正确方法是什么?我认为它是:

  startDate:
    type: string
    description: Start date
    example: "2017-01-01"
    format: date
Run Code Online (Sandbox Code Playgroud)

但我看到很多这样的声明:

  startDate:
    type: string
    description: Start date
    example: "2017-01-01"
    format: date
    pattern: "YYYY-MM-DD"
    minLength: 0
    maxLength: 10
Run Code Online (Sandbox Code Playgroud)

谢谢.

swagger openapi

20
推荐指数
4
解决办法
2万
查看次数

如何将自定义模型活页夹与Swashbuckle,Swagger和NSwag一起使用?

我有一个包含以下端点的ASP.NET Core Web API。

[HttpGet]
[Route("models/{ids}")]
[Produces(typeof(IEnumerable<Model>))]
public IActionResult Get
(
    [ModelBinder(typeof(CsvModelBinder<string>))] IEnumerable<string> ids
)
{
    // Get models

    return Ok(models);
}
Run Code Online (Sandbox Code Playgroud)

该端点获取一个ID的CSV列表(例如/models/a,b,c),并返回相应Model对象的JSON数组。 CsvModelBinder<string>IModelBinder我编写的自定义实现,该实现将Ids的CSV列表拆分为IEnumerable<string>,我可以在查询中使用它来查找对象。这一切都很好。

我现在想做的是使用NSwag生成客户端库,但这被证明是有问题的,因为Swashbuckle生成的Swagger将ids参数描述为IEnumerable<string>,而不是string

选项A:有没有办法告诉Swashbuckle将参数描述为a string而不是as IEnumerable<string>

选项B:有没有办法告诉NSwag IEnumerable<string>在生成请求URL时应将此参数编组为CSV?

c# swagger swashbuckle asp.net-core nswag

8
推荐指数
1
解决办法
1900
查看次数

将 DateOnly 值与 DateTime 进行比较。难道不应该吗?

使用 .Net 6 和 VS2022 ,考虑以下代码:

DateOnly dateOnly= new DateOnly(2022,12,24);
            DateTime dateTime = DateTime.Now;

            if (dateTime > dateOnly)
            {

            }
Run Code Online (Sandbox Code Playgroud)

这会导致这个错误:

Operator '>' cannot be applied to operands of type 'DateTime' and 'DateOnly'

即使没有内置属性可以DateOnly从 a 中获取DateTime,而无需编写一些自定义扩展方法,这些DateOnly.Compare方法也不支持与DateTime类型进行比较。这个故事是一样的TimeOnly如果我没有遗漏什么,比较这两种类型的正确方法是什么?

更新:

刚刚发现甚至不可能像 webapi 查询参数中的其他类型一样使用这些类型!此外,EF core 6 在 SqlClient 中没有对这些类型的内置支持
也许延迟使用这些类型会更好......

c# datetime .net-6.0 dateonly

6
推荐指数
1
解决办法
4357
查看次数