Last active
April 15, 2018 11:32
-
-
Save juanluelguerre/71bacdf432cdd2612b185656aaf2aafe to your computer and use it in GitHub Desktop.
Using Swashbuckle with NetCORE to get standard OpenAPI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.AspNetCore.Builder; | |
using Microsoft.AspNetCore.Hosting; | |
using Microsoft.AspNetCore.Mvc; | |
using Microsoft.Extensions.Configuration; | |
using Microsoft.Extensions.DependencyInjection; | |
using Swashbuckle.AspNetCore.Swagger; | |
namespace ElGuerre.Taskin.Api | |
{ | |
public class Startup | |
{ | |
public Startup(IConfiguration configuration) | |
{ | |
Configuration = configuration; | |
} | |
public IConfiguration Configuration { get; } | |
// This method gets called by the runtime. Use this method to add services to the container. | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); | |
// Add bellow statement to use HTTPS o a better option, set environment varibble ASPNETCORE_HTTPS_PORT | |
// services.AddHttpsRedirection(options => options.HttpsPort = 5003); | |
// Add Swagger | |
services.AddSwaggerGen(options => | |
{ | |
options.SwaggerDoc("v1", | |
new Info | |
{ | |
Version = "v1", | |
Title = "Taskin API", | |
Description = "API to expose Taskin logic", | |
TermsOfService = "https://github.com/juanluelguerre/Taskin/blob/master/LICENSE" | |
} | |
); | |
}); | |
} | |
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. | |
public void Configure(IApplicationBuilder app, IHostingEnvironment env) | |
{ | |
if (env.IsDevelopment()) | |
{ | |
app.UseDeveloperExceptionPage(); | |
} | |
else | |
{ | |
app.UseHsts(); | |
} | |
app.UseHttpsRedirection(); | |
app.UseMvc(); | |
app.UseSwagger() | |
.UseSwaggerUI(c => | |
{ | |
c.SwaggerEndpoint("/swagger/v1/swagger.json", "Taskin V1"); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment