gpt4 book ai didi

c# - Swashbuckle和Swagger库无法识别“Info”类

转载 作者:行者123 更新时间:2023-12-03 09:45:22 28 4
gpt4 key购买 nike

我是否缺少软件包或引用,因为AddSwaggerGen方法无法编译。我的代码:

我添加了using Swashbuckle.AspNetCore.Swagger;
但是这段代码

  services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new Info { Title = "My API", Version = "v1" });
c.EnableAnnotations();
});

不会编译:

Error CS0246 The type or namespace name 'Info' could not be found (are you missing a using directive or an assembly reference?) Here is the csproj


<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>netcoreapp3.0</TargetFramework>
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
<DebugType>full</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="IdentityModel" Version="3.10.6" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-18618-05">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" Version="5.0.0-rc2" />
<PackageReference Include="Swashbuckle.AspNetCore.Swagger" Version="5.0.0-rc2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerGen" Version="5.0.0-rc2" />
<PackageReference Include="Swashbuckle.AspNetCore.SwaggerUI" Version="5.0.0-rc2" />
</ItemGroup>

最佳答案

Info在版本5中已弃用

它已被OpenApiInfo取代,因此您必须在您的 Swagger 设置中反射(reflect)出来:

c.SwaggerDoc("My_Api", new OpenApiInfo { Version = "1.0", Description = "my api " });

关于c# - Swashbuckle和Swagger库无法识别“Info”类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56502869/

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