简体   繁体   中英

Is swashbuckle.aspnetcore supporting asp.net core 3.0?

I am installing a new asp.net core 3.0

its using services.AddControllers(); instead of services.addMvc();

and its using

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

instead of

app.UserMvc();

i tried adding swashbuckle.aspnetcore to generated its swagger ui.

its not working.

is swashbuckle.aspnetcore already supporting asp.net core 3.0 ?

Yes, ASP.NET Core 3.0 supports Swashbuckle.

1) You can simply install it by running the follow command in Package Manager Console:

Install-Package Swashbuckle.AspNetCore -Version 5.0.0-rc3

2) Then add the Swagger generator to the services collection in the Startup.ConfigureServices method:

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:

// 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

I'm able to access the swagger ui in 3.0 Preview 7 with the following:

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

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM