When developing a project, it is always necessary to compile the documentation and keep it up-to-date. This can be achieved in several different ways. In general, the automatic documentation capabilities are always used, which allows you to obtain a good quality of documentation with a minimal time cost, which will always correspond to the current version of your API. Currently, a very popular and functional framework for working with the API is Swagger.
Let's create an ASP.NET Core API application. Later, add a default controller ValuesController.
To use Swagger, you must install the following library.
PM > Install-Package Swashbuckle.AspNetCore
- public void ConfigureServices(IServiceCollection services) {
- services.AddMvc();
- services.AddSwaggerGen(c => {
- c.SwaggerDoc("v1", new Info {
- Version = "v1",
- Title = "Test API",
- Description = "ASP.NET Core Web API"
- });
- });
- }
After that, add the Swagger UI to the Configure method, after which it will look like this.
- public void Configure(IApplicationBuilder app, IHostingEnvironment env) {
- if (env.IsDevelopment()) {
- app.UseDeveloperExceptionPage();
- }
- app.UseMvc();
- app.UseSwagger();
- app.UseSwaggerUI(c => {
- c.SwaggerEndpoint("/swagger/v1/swagger.json", "Test API V1");
- });
- }


You can see which templates are used in the API, which settings are required, and which ones are not. Here too, you can test the work of your methods. To do this, you must select the desired method and click on "Try it out".
- public class UserDto {
- [JsonIgnore]
- public Guid Id {
- get;
- set;
- }
- [Required]
- public string FirstName {
- get;
- set;
- }
- [Required]
- public string LastName {
- get;
- set;
- }
- [Required]
- [JsonProperty(PropertyName = "mobilePhone")]
- public string Phone {
- get;
- set;
- }
- public string Email {
- get;
- set;
- }
- }
You can see here that you can use various familiar attributes for all, which are well understood and treated in Swagger.
Use in Postman
At the moment, Swagger can work with more than 25 programming languages. Its use is, therefore, not limited to .NET Core. It can also be useful in almost any project in which the API is created.

AminPosted Oct 23, 2018, 2:46 PM
Thank you for this potic,
Rahul SenPosted Oct 19, 2018, 11:19 PM
Thank you for this grate share. Can we set up swagger for passing the authentication header(un ps)
Rebai HamidaPosted Oct 18, 2018, 2:14 PM
Thank you for sharing! nice article as usual!
Rushi MehtaPosted Oct 18, 2018, 1:53 AM
It is really a good article for the devloers
kalu singh raoPosted Oct 18, 2018, 12:37 AM
It is good article for beginner developers for using swagger implementations. Thanks for sharing.