简体   繁体   English

swashbuckle.aspnetcore 是否支持 asp.net core 3.0?

[英]Is swashbuckle.aspnetcore supporting asp.net core 3.0?

I am installing a new asp.net core 3.0我正在安装一个新的 asp.net core 3.0

its using services.AddControllers();它使用services.AddControllers(); instead of services.addMvc();而不是services.addMvc();

and its using及其使用

  app.UseEndpoints(endpoints =>
            {
                endpoints.MapControllers();
            });

instead of代替

app.UserMvc();

i tried adding swashbuckle.aspnetcore to generated its swagger ui.我尝试添加swashbuckle.aspnetcore来生成它的 swagger ui。

its not working.它不工作。

is swashbuckle.aspnetcore already supporting asp.net core 3.0 ? swashbuckle.aspnetcore已经支持 asp.net core 3.0?

Yes, ASP.NET Core 3.0 supports Swashbuckle.是的,ASP.NET Core 3.0 支持 Swashbuckle。

1) You can simply install it by running the follow command in Package Manager Console: 1)您可以通过在包管理器控制台中运行以下命令来简单地安装它:

Install-Package Swashbuckle.AspNetCore -Version 5.0.0-rc3

2) Then add the Swagger generator to the services collection in the Startup.ConfigureServices method: 2)然后在Startup.ConfigureServices方法的services集合中添加Swagger生成器:

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

3) In Startup.Configure method, add these two to enable the middleware for serving the generated JSON document and the Swagger UI: 3) 在Startup.Configure方法中,添加这两个以启用中间件,用于为生成的 JSON 文档和 Swagger UI 提供服务:

// Enable middleware to serve generated Swagger as a JSON endpoint.
app.UseSwagger();

// Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.),
// specifying the Swagger JSON endpoint.
app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1");
});

To customize it, you can check complete guide here: https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-3.0&tabs=visual-studio要自定义它,您可以在此处查看完整指南: https : //docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-3.0&tabs=visual-studio

I'm able to access the swagger ui in 3.0 Preview 7 with the following:我可以使用以下内容访问 3.0 Preview 7 中的 swagger ui:

<PackageReference Include="NSwag.AspNetCore" Version="13.0.4" />
public void ConfigureServices(IServiceCollection services) {
...
   services.AddSwaggerDocument();
}

Configure() {
...
   app.UseSwaggerUi3();
}

使用 SwashBuckle.AspNetCore 版本 5.0.0-rc2 修复了它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 ASP.NET Core Swagger (Swashbuckle.AspNetCore) 中定义控制器描述? - How to define controller descriptions in ASP.NET Core Swagger (Swashbuckle.AspNetCore)? ASP.NET Core 3.0 / Swashbuckle:全局限制响应内容类型 - ASP.NET Core 3.0 / Swashbuckle : restrict responses content types globally 如何在 ASP.NET Core 3.0 中解密.AspNetCore.Identity.Application cookie? - How to decrypt .AspNetCore.Identity.Application cookie in ASP.NET Core 3.0? asp.net core swashbuckle 如何在同一个控制器中使用版本控制 - asp.net core swashbuckle how to use versioning in same controller ASP.NET 内核:NSwag 与 Swashbuckle - ASP.NET core: NSwag vs. Swashbuckle ASP.NET Core - Swashbuckle 未创建 swagger.json 文件 - ASP.NET Core - Swashbuckle not creating swagger.json file Swashbuckle 在 asp.net core 中失败,出现 NotSupportedException 异常 - Swashbuckle fails in asp.net core with NotSupportedException exception 使用 ASP.NET Core Web API 重命名 Swashbuckle 6 (Swagger) 中的模型 - Rename model in Swashbuckle 6 (Swagger) with ASP.NET Core Web API Swashbuckle/Swagger + ASP.Net Core:“无法加载 API 定义” - Swashbuckle/Swagger + ASP.Net Core: "Failed to load API definition" 可选参数在Swashbuckle.AspNetCore中导致空异常 - Optional parameter causes null exception in Swashbuckle.AspNetCore
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM