From 9792182ef76ba6cfe9489343c2af0e73c47108ba Mon Sep 17 00:00:00 2001 From: Denis Prokhorchik Date: Fri, 22 Apr 2022 22:35:49 +0300 Subject: [PATCH] feat(issue-320): include Swashbuckle.AspNetCore v1.1.0 to o2-cgen api --- .../IoC/ServiceCollectionExtensions.cs | 1 + .../O2NextGen.CertificateManagement.Api.csproj | 1 + .../Properties/launchSettings.json | 1 + .../Startup.cs | 18 +++++++++++++++++- 4 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Api/IoC/ServiceCollectionExtensions.cs b/src/Services/c-gen/O2NextGen.CertificateManagement.Api/IoC/ServiceCollectionExtensions.cs index e32bec21..f20c0057 100644 --- a/src/Services/c-gen/O2NextGen.CertificateManagement.Api/IoC/ServiceCollectionExtensions.cs +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Api/IoC/ServiceCollectionExtensions.cs @@ -33,6 +33,7 @@ public static IServiceCollection AddRequiredMvcComponents(this IServiceCollectio services.AddTransient(); var mvcBuilder = services.AddMvcCore(options => { options.Filters.Add(); }); + mvcBuilder.AddApiExplorer(); //for swagger mvcBuilder.SetCompatibilityVersion(CompatibilityVersion.Version_2_2); mvcBuilder.AddJsonFormatters(); return services; diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Api/O2NextGen.CertificateManagement.Api.csproj b/src/Services/c-gen/O2NextGen.CertificateManagement.Api/O2NextGen.CertificateManagement.Api.csproj index 03a32ddb..c7bb9e21 100644 --- a/src/Services/c-gen/O2NextGen.CertificateManagement.Api/O2NextGen.CertificateManagement.Api.csproj +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Api/O2NextGen.CertificateManagement.Api.csproj @@ -27,6 +27,7 @@ + diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Api/Properties/launchSettings.json b/src/Services/c-gen/O2NextGen.CertificateManagement.Api/Properties/launchSettings.json index 32ab7244..18c3ea4c 100644 --- a/src/Services/c-gen/O2NextGen.CertificateManagement.Api/Properties/launchSettings.json +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Api/Properties/launchSettings.json @@ -3,6 +3,7 @@ "O2NextGen.CertificateManagement.Web": { "commandName": "Project", "launchBrowser": true, + "launchUrl": "swagger", "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, diff --git a/src/Services/c-gen/O2NextGen.CertificateManagement.Api/Startup.cs b/src/Services/c-gen/O2NextGen.CertificateManagement.Api/Startup.cs index a013de15..91a4200e 100644 --- a/src/Services/c-gen/O2NextGen.CertificateManagement.Api/Startup.cs +++ b/src/Services/c-gen/O2NextGen.CertificateManagement.Api/Startup.cs @@ -10,6 +10,7 @@ using O2NextGen.CertificateManagement.Api.Setup; using O2NextGen.CertificateManagement.Api.Helpers; using O2NextGen.CertificateManagement.Api.IoC; +using Swashbuckle.AspNetCore.Swagger; [assembly: ApiController] namespace O2NextGen.CertificateManagement.Api @@ -28,6 +29,17 @@ public void ConfigureServices(IServiceCollection services) { services.AddRequiredMvcComponents(); services.AddBusiness(); + services.AddSwaggerGen(options => + { + options.DescribeAllEnumsAsStrings(); + options.SwaggerDoc("v1",new Info() + { + Title = "O2NextGen Platform. C-Gen HTTP API", + Version = "v1", + Description = "C-Gen API Service. The service allows you to create certificates", + TermsOfService = "Terms of Service" + }); + }); services.AddConfigEf(AppConfiguration); services.ConfigurePOCO(AppConfiguration.GetSection("Urls")); } @@ -58,7 +70,11 @@ public void Configure(IApplicationBuilder app, IHostingEnvironment env) } app.UseStaticFiles(); - + app.UseSwagger() + .UseSwaggerUI(c => + { + c.SwaggerEndpoint($"/swagger/v1/swagger.json", "C-Gen API V1"); + }); app.Use(async (context, next) => { context.Response.OnStarting(() =>