Author : MD TAREQ HASSAN | Updated : 2021/07/11

Things You Should Know

API documentation

Generating OpenAPI Specs & API Docs

Generating OpenAPI specs and API documentation

Generating http client

Generating http client from OpenAPI spec

Documenting API with Swashbuckle

.Net 5.0+

Before .Net 5.0

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");
            });
            
            // ... ... ...
        }
    }
}

Best Practices

See: Best practices when developing microservices