Swagger in use in ASP.NET Core 3.0

1. Installation NuGet following dependencies:

  • Swashbuckle.AspNetCore.Swagger
  • Swashbuckle.AspNetCore.SwaggerGEN
  • Swashbuckle.AspNetCore.SwaggerUI

      Note: the highest version of the election version, I chose 5.0 rc4

2. Add the following code in ConfigureServices

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

3. Add the following code in the Configure

app.UseSwagger();
app.UseSwaggerUI(c =>
{
    c.SwaggerEndpoint("/swagger/v1/swagger.json", "CIT WebAPI v1");
});

4. Is access /swagger/v1/swagger.json display properly JSON

5. Access / swagger can access the document shows

Guess you like

Origin www.cnblogs.com/networkpilot/p/11955643.html