当从查询字符串中提取的模型将字典作为其属性之一时,Swagger 会生成错误的 URL。如何告诉 Swagger 更改 URL 中字典的格式或手动定义输入参数架构,而不自动生成?尝试使用 Swashbuckle 和 NSwag。
控制器
public class RecordsController : ControllerBase
{
[HttpGet]
[Route("services/records")]
public async Task<IActionResult> Records([FromQuery] QueryModel queryModel)
{
return null;
}
}
Run Code Online (Sandbox Code Playgroud)
输入模型 - 查询字符串
public class QueryModel
{
public int Page { get; set; }
public int Count { get; set; }
public Dictionary<Columns, string> Conditions { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
Swagger UI为查询模型上的“条件”属性显示了这种格式
{
"UserId": "string",
"GroupId": "string",
"RecordId": "string"
}
Run Code Online (Sandbox Code Playgroud)
Swagger 生成的 URL - Open API v2 - 不会绑定到“条件” …
swagger swashbuckle asp.net-core asp.net-core-webapi swashbuckle.aspnetcore
我正在阅读C# Cookbook 中的并发,这本书告诉我:
ConcurrentDictionary<TKey, TValue>当您有多个线程读取和写入共享集合时,这是最好的。如果更新不是恒定的(如果它们更罕见),那么这ImmutableDictionary<TKey,TValue>可能是一个更好的选择。
我知道 Add or Remove a large immutable collection 可能很慢,我的问题是,它们之间还有其他区别吗?既然它们都是线程安全的,那么ImmutableDictionary当更新不是恒定的时,为什么是更好的选择呢?