From 726dabb68803d08edd29cb14c3acdb336e4de395 Mon Sep 17 00:00:00 2001 From: Ferenc Hammerl Date: Tue, 20 Oct 2020 20:37:00 +0000 Subject: [PATCH] Add swagger support --- ExpenseTracker.Api/ExpenseTracker.csproj | 1 + ExpenseTracker.Api/Startup.cs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/ExpenseTracker.Api/ExpenseTracker.csproj b/ExpenseTracker.Api/ExpenseTracker.csproj index 404fa77..f7ea5be 100644 --- a/ExpenseTracker.Api/ExpenseTracker.csproj +++ b/ExpenseTracker.Api/ExpenseTracker.csproj @@ -10,6 +10,7 @@ all + diff --git a/ExpenseTracker.Api/Startup.cs b/ExpenseTracker.Api/Startup.cs index 22c201b..7cb13a2 100644 --- a/ExpenseTracker.Api/Startup.cs +++ b/ExpenseTracker.Api/Startup.cs @@ -35,6 +35,7 @@ public void ConfigureServices(IServiceCollection services) { services.AddDbContext(options => options.UseSqlite($"Data Source=ExpenseTracker.Api/expensetracker.db")); } + services.AddSwaggerGen(); } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. @@ -44,6 +45,16 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env) { app.UseDeveloperExceptionPage(); } + + // Enable middleware to serve generated Swagger as a JSON endpoint. + app.UseSwagger(); + + // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), + // specifying the Swagger JSON endpoint. + app.UseSwaggerUI(c => + { + c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); + }); app.UseHttpsRedirection();