[英]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.