These instructions is a part of a live coding video.
- .NET Core 3.1 SDK - https://dotnet.microsoft.com/download
Create a base folder CodingLive003
.
Create the .gitignore file based on file https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
- Create project
- Add packages
- Entities > Client
- Requests > CreateClientRequest
- Requests > UpdateClientRequest
- Responses > ClientResponse
- MockData > ClientMock
- Controllers > ClientsController
- Wwwroot > Html Documentation
- Startup > Swagger configuration
- Controllers > Data annotations
dotnet new webapi --name MyApiWithDoc
dotnet add package Swashbuckle.AspNetCore -v 5.0.0
dotnet add package Microsoft.AspNetCore.Mvc.NewtonsoftJson -v 3.1.3
...
private static string GetPathOfXmlFromAssembly() => Path.Combine(AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml");
...
services.AddControllers()
.AddNewtonsoftJson(options =>
{
options.SerializerSettings.NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore;
options.SerializerSettings.Converters.Add(new Newtonsoft.Json.Converters.StringEnumConverter());
});
...
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API with Documentation", Version = "v1" });
options.IncludeXmlComments(GetPathOfXmlFromAssembly());
});
app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API width Documentation V1");
c.RoutePrefix = string.Empty;
});