|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.Linq; |
| 4 | +using System.Threading.Tasks; |
| 5 | +using Microsoft.AspNetCore.Builder; |
| 6 | +using Microsoft.AspNetCore.Hosting; |
| 7 | +using Microsoft.AspNetCore.HttpsPolicy; |
| 8 | +using Microsoft.AspNetCore.Mvc; |
| 9 | +using Microsoft.Extensions.Configuration; |
| 10 | +using Microsoft.Extensions.DependencyInjection; |
| 11 | +using Microsoft.Extensions.Logging; |
| 12 | +using Microsoft.Extensions.Options; |
| 13 | +using Swashbuckle.AspNetCore.Swagger; |
| 14 | + |
| 15 | +namespace api_docs |
| 16 | +{ |
| 17 | + public class Startup |
| 18 | + { |
| 19 | + public Startup(IConfiguration configuration) |
| 20 | + { |
| 21 | + Configuration = configuration; |
| 22 | + } |
| 23 | + |
| 24 | + public IConfiguration Configuration { get; } |
| 25 | + |
| 26 | + // This method gets called by the runtime. Use this method to add services to the container. |
| 27 | + public void ConfigureServices(IServiceCollection services) |
| 28 | + { |
| 29 | + services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); |
| 30 | + |
| 31 | + services.AddSwaggerGen(c => |
| 32 | + { |
| 33 | + c.SwaggerDoc("v1", new Info { Title = "API Docs", Version = "v1" }); |
| 34 | + }); |
| 35 | + } |
| 36 | + |
| 37 | + // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. |
| 38 | + public void Configure(IApplicationBuilder app, IHostingEnvironment env) |
| 39 | + { |
| 40 | + if (env.IsDevelopment()) |
| 41 | + { |
| 42 | + app.UseDeveloperExceptionPage(); |
| 43 | + } |
| 44 | + else |
| 45 | + { |
| 46 | + app.UseHsts(); |
| 47 | + } |
| 48 | + |
| 49 | + // Enable middleware to serve generated Swagger as a JSON endpoint. |
| 50 | + app.UseSwagger(); |
| 51 | + |
| 52 | + // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), |
| 53 | + // specifying the Swagger JSON endpoint. |
| 54 | + app.UseSwaggerUI(c => |
| 55 | + { |
| 56 | + c.SwaggerEndpoint("/swagger/v1/swagger.json", "API V1"); |
| 57 | + c.RoutePrefix = string.Empty; |
| 58 | + }); |
| 59 | + |
| 60 | + app.UseHttpsRedirection(); |
| 61 | + app.UseMvc(); |
| 62 | + } |
| 63 | + } |
| 64 | +} |
0 commit comments