Author : MD TAREQ HASSAN | Updated : 2021/07/11
Things You Should Know
API documentation
Generating OpenAPI Specs & API Docs
Generating http client
Documenting API with Swashbuckle
.Net 5.0+
- .Net 5.0+ natively support OpenAPI
- Visual Studio Scaffolding (creating new project) provides Swashbuckle and Swagger UI
Before .Net 5.0
- https://github.com/domaindrivendev/Swashbuckle.AspNetCore
- https://docs.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle
Nuget
Install-Package Swashbuckle.AspNetCore
Startup.cs
// ... ... ...
using Microsoft.OpenApi.Models;
namespace HPlusSportsAPI
{
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
// ... ... ...
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo
{
Title = "HPlusSports API",
Version = "1.0",
Description = "Product API for HPlusSports"
});
});
}
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
// ... ... ...
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Foo");
});
// ... ... ...
}
}
}