Author : HASSAN MD TAREQ | Updated : 2020/10/21

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 NSwag

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