From 9ff3dd500819d650b54ee88eb467c1f24e9d7af2 Mon Sep 17 00:00:00 2001 From: Mehdi Hadeli Date: Tue, 25 Jul 2023 23:21:22 +0330 Subject: [PATCH] Add swagger support (#4) * feat: add swagger * style: formatting code --- .../IdentityEndpointsSample.csproj | 23 +++++++++++-------- IdentityEndpointsSample/Program.cs | 10 ++++++++ .../Properties/launchSettings.json | 2 ++ 3 files changed, 25 insertions(+), 10 deletions(-) diff --git a/IdentityEndpointsSample/IdentityEndpointsSample.csproj b/IdentityEndpointsSample/IdentityEndpointsSample.csproj index 48d08c5..70e1b82 100644 --- a/IdentityEndpointsSample/IdentityEndpointsSample.csproj +++ b/IdentityEndpointsSample/IdentityEndpointsSample.csproj @@ -1,14 +1,17 @@ - - net8.0 - enable - enable - + + net8.0 + enable + enable + - - - - + + + + + + - + \ No newline at end of file diff --git a/IdentityEndpointsSample/Program.cs b/IdentityEndpointsSample/Program.cs index 2ec07a0..8b8bbd8 100644 --- a/IdentityEndpointsSample/Program.cs +++ b/IdentityEndpointsSample/Program.cs @@ -14,6 +14,10 @@ builder.Services.AddIdentityCore() .AddEntityFrameworkStores() .AddApiEndpoints(); +// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle +builder.Services.AddEndpointsApiExplorer(); +builder.Services.AddSwaggerGen(); + var app = builder.Build(); // Adds /register, /login and /refresh endpoints @@ -21,6 +25,12 @@ app.MapIdentityApi(); app.MapGet("/", (ClaimsPrincipal user) => $"Hello {user.Identity!.Name}").RequireAuthorization(); +if (app.Environment.IsDevelopment()) +{ + app.UseSwagger(); + app.UseSwaggerUI(); +} + app.Run(); class MyUser : IdentityUser { } diff --git a/IdentityEndpointsSample/Properties/launchSettings.json b/IdentityEndpointsSample/Properties/launchSettings.json index 3f7bf86..8d9a41f 100644 --- a/IdentityEndpointsSample/Properties/launchSettings.json +++ b/IdentityEndpointsSample/Properties/launchSettings.json @@ -13,6 +13,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, + "launchUrl": "swagger", "applicationUrl": "http://localhost:5285", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" @@ -22,6 +23,7 @@ "commandName": "Project", "dotnetRunMessages": true, "launchBrowser": true, + "launchUrl": "swagger", "applicationUrl": "https://localhost:7044;http://localhost:5285", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development"