Cannot implicitly convert type
'System.Collections.Generic.Dictionary<string, Microsoft.OpenApi.Models.OpenApiPathItem>' to 'Microsoft.OpenApi.Models.OpenApiPaths'
An explicit conversion exists (are you missing a cast?)
public class ReplaceVersionWithExactValueInPath : IDocumentFilter
{
public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
{
swaggerDoc.Paths = swaggerDoc.Paths
.ToDictionary(
path => path.Key.Replace("v{version}", swaggerDoc.Info.Version),
path => path.Value
);
}
}
最佳答案
看起来 OpenApiDocument.Path
不是字典
所以你不能使用 swaggerDoc.Paths = swaggerDoc.Paths.ToDictionary()
赋值
尝试使用新的 OpenApiPath
对象和 Add()
方法
var oap = new OpenApiPaths();
foreach (var p in swaggerDoc.Paths)
oap.Add(p.Key.Replace("v{version}", swaggerDoc.Info.Version),
p.Value);
swaggerDoc.Paths = oap;
https://stackoverflow.com/questions/60563647/