gpt4 book ai didi

c# - 将代码 2.0 迁移到 3.1 核心代码,然后 swagger api 版本控制不起作用

转载 作者:行者123 更新时间:2023-12-05 09:11:06 25 4
gpt4 key购买 nike

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;

关于c# - 将代码 2.0 迁移到 3.1 核心代码,然后 swagger api 版本控制不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60563647/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com