Xamarin Forms Project Tutorial

Adding Swagger in Asp.net core App [Sampurna #1]

Configure Swagger in ASP.net Core Web Project App using Swashbuckle.AspNetCore
Step1:
Install package Swashbuckle.AspNetCore

Step2:
Configure Swagger middleware :
Startup.cs :
public void ConfigureServices(IServiceCollection services)
{
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1.0", new Info { Title = "My Demo API", Version = "1.0" });
});
}

Inside configure method inside Startup.cs :
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}

app.UseHttpsRedirection();

app.UseSwagger();
app.UseSwaggerUI(c =>
{
c.SwaggerEndpoint("/swagger/v1.0/swagger.json", "My Demo API (V 1.0)");
});

app.UseMvc();
}

134 total views, 1 views today

Leave a Reply