step 1.Create a ASP.NET Core Web API Project
step 2.Add Swagger to Web API Project -Package installation
To add Swagger to your ASP.NET Web API project, you need to install an open-source project called Swashbuckle via NuGet, as shown below.
Install-Package Swashbuckle.AspNetCore -Version 6.5.0
Nuget安装Swashbuckle.AspNetCore包
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
</ItemGroup>
</Project>
step 3.Configure Swagger in ASP.NET Web API Application
Add the Swagger generator to the services collection in Program.cs:
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
step 4.Enable the middleware for serving the generated JSON document and the Swagger UI, also in Program.cs:
app.UseSwagger();
app.UseSwaggerUI();
https://learn.microsoft.com/en-us/aspnet/core/tutorials/getting-started-with-swashbuckle?view=aspnetcore-8.0&tabs=netcore-cli
http://localhost:5050/swagger/index.html
http://localhost:5050/swagger/v1/swagger.json
Useful links
https://www.cnblogs.com/RainFate/p/17244526.html
https://www.c-sharpcorner.com/article/crud-operation-using-elastic-search-and-net-core-api/