From 5cd3d6230c6bb53f348f9c2938522ae6b8122d86 Mon Sep 17 00:00:00 2001 From: Galip Tolga Erdem Date: Wed, 2 Mar 2022 15:34:01 +0300 Subject: [PATCH] Removed SwaggerWithAuthConfigurationHelper and added as a method to default configurer --- .../EShopOnAbpAuthServerModule.cs | 2 +- .../EShopOnAbpWebPublicGatewayModule.cs | 2 +- .../EShopOnAbpWebGatewayModule.cs | 2 +- .../AdministrationServiceHttpApiHostModule.cs | 2 +- .../BasketServiceModule.cs | 2 +- .../CatalogServiceHttpApiHostModule.cs | 2 +- .../IdentityServiceHttpApiHostModule.cs | 2 +- .../OrderingServiceHttpApiHostModule.cs | 2 +- .../PaymentServiceHttpApiHostModule.cs | 2 +- .../SwaggerConfigurationHelper.cs | 22 +++++++++++++- .../SwaggerWithAuthConfigurationHelper.cs | 30 ------------------- 11 files changed, 30 insertions(+), 40 deletions(-) delete mode 100644 shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerWithAuthConfigurationHelper.cs diff --git a/apps/auth-server/src/EShopOnAbp.AuthServer/EShopOnAbpAuthServerModule.cs b/apps/auth-server/src/EShopOnAbp.AuthServer/EShopOnAbpAuthServerModule.cs index 7e304d5c..8b57f016 100644 --- a/apps/auth-server/src/EShopOnAbp.AuthServer/EShopOnAbpAuthServerModule.cs +++ b/apps/auth-server/src/EShopOnAbp.AuthServer/EShopOnAbpAuthServerModule.cs @@ -214,7 +214,7 @@ public class EShopOnAbpAuthServerModule : AbpModule private void ConfigureSwagger(ServiceConfigurationContext context, IConfiguration configuration) { - SwaggerWithAuthConfigurationHelper.Configure( + SwaggerConfigurationHelper.ConfigureWithAuth( context: context, authority: configuration["AuthServer:Authority"], scopes: new Dictionary diff --git a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs index faab4ab4..a77e5660 100644 --- a/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs +++ b/gateways/web-public/src/EShopOnAbp.WebPublicGateway/EShopOnAbpWebPublicGatewayModule.cs @@ -23,7 +23,7 @@ public class EShopOnAbpWebPublicGatewayModule : AbpModule var configuration = context.Services.GetConfiguration(); var hostingEnvironment = context.Services.GetHostingEnvironment(); - SwaggerWithAuthConfigurationHelper.Configure( + SwaggerConfigurationHelper.ConfigureWithAuth( context: context, authority: configuration["AuthServer:Authority"], scopes: new Dictionary /* Requested scopes for authorization code request and descriptions for swagger UI only */ diff --git a/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs b/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs index a9bf6190..232fafb2 100644 --- a/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs +++ b/gateways/web/src/EShopOnAbp.WebGateway/EShopOnAbpWebGatewayModule.cs @@ -25,7 +25,7 @@ public class EShopOnAbpWebGatewayModule : AbpModule var configuration = context.Services.GetConfiguration(); var hostingEnvironment = context.Services.GetHostingEnvironment(); - SwaggerWithAuthConfigurationHelper.Configure( + SwaggerConfigurationHelper.ConfigureWithAuth( context: context, authority: configuration["AuthServer:Authority"], scopes: new diff --git a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs index 1c55c856..beafc3f7 100644 --- a/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs +++ b/services/administration/src/EShopOnAbp.AdministrationService.HttpApi.Host/AdministrationServiceHttpApiHostModule.cs @@ -37,7 +37,7 @@ public class AdministrationServiceHttpApiHostModule : AbpModule JwtBearerConfigurationHelper.Configure(context, "AdministrationService"); - SwaggerWithAuthConfigurationHelper.Configure( + SwaggerConfigurationHelper.ConfigureWithAuth( context: context, authority: configuration["AuthServer:Authority"], scopes: new diff --git a/services/basket/src/EShopOnAbp.BasketService/BasketServiceModule.cs b/services/basket/src/EShopOnAbp.BasketService/BasketServiceModule.cs index d9e2585e..3f952db3 100644 --- a/services/basket/src/EShopOnAbp.BasketService/BasketServiceModule.cs +++ b/services/basket/src/EShopOnAbp.BasketService/BasketServiceModule.cs @@ -94,7 +94,7 @@ namespace EShopOnAbp.BasketService private void ConfigureSwagger(ServiceConfigurationContext context, IConfiguration configuration) { - SwaggerWithAuthConfigurationHelper.Configure( + SwaggerConfigurationHelper.ConfigureWithAuth( context: context, authority: configuration["AuthServer:Authority"], scopes: new diff --git a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs index ae8547e6..b8a4881d 100644 --- a/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs +++ b/services/catalog/src/EShopOnAbp.CatalogService.HttpApi.Host/CatalogServiceHttpApiHostModule.cs @@ -37,7 +37,7 @@ public class CatalogServiceHttpApiHostModule : AbpModule JwtBearerConfigurationHelper.Configure(context, "CatalogService"); - SwaggerWithAuthConfigurationHelper.Configure( + SwaggerConfigurationHelper.ConfigureWithAuth( context: context, authority: configuration["AuthServer:Authority"], scopes: new diff --git a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs index 9e16cb2b..5fbed800 100644 --- a/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs +++ b/services/identity/src/EShopOnAbp.IdentityService.HttpApi.Host/IdentityServiceHttpApiHostModule.cs @@ -33,7 +33,7 @@ public class IdentityServiceHttpApiHostModule : AbpModule JwtBearerConfigurationHelper.Configure(context, "IdentityService"); - SwaggerWithAuthConfigurationHelper.Configure( + SwaggerConfigurationHelper.ConfigureWithAuth( context: context, authority: configuration["AuthServer:Authority"], scopes: new diff --git a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs index d94781b5..d5a9a9eb 100644 --- a/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs +++ b/services/ordering/src/EShopOnAbp.OrderingService.HttpApi.Host/OrderingServiceHttpApiHostModule.cs @@ -33,7 +33,7 @@ public class OrderingServiceHttpApiHostModule : AbpModule JwtBearerConfigurationHelper.Configure(context, "OrderingService"); - SwaggerWithAuthConfigurationHelper.Configure( + SwaggerConfigurationHelper.ConfigureWithAuth( context: context, authority: configuration["AuthServer:Authority"], scopes: new diff --git a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs index 64ebec59..e267e8d3 100644 --- a/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs +++ b/services/payment/src/EShopOnAbp.PaymentService.HttpApi.Host/PaymentServiceHttpApiHostModule.cs @@ -34,7 +34,7 @@ public class PaymentServiceHttpApiHostModule : AbpModule JwtBearerConfigurationHelper.Configure(context, "PaymentService"); - SwaggerWithAuthConfigurationHelper.Configure( + SwaggerConfigurationHelper.ConfigureWithAuth( context: context, authority: configuration["AuthServer:Authority"], scopes: new diff --git a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerConfigurationHelper.cs b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerConfigurationHelper.cs index 256828ef..3990971c 100644 --- a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerConfigurationHelper.cs +++ b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerConfigurationHelper.cs @@ -1,4 +1,5 @@ -using Microsoft.Extensions.DependencyInjection; +using System.Collections.Generic; +using Microsoft.Extensions.DependencyInjection; using Microsoft.OpenApi.Models; using Volo.Abp.Modularity; @@ -18,5 +19,24 @@ namespace EShopOnAbp.Shared.Hosting.AspNetCore options.CustomSchemaIds(type => type.FullName); }); } + public static void ConfigureWithAuth( + ServiceConfigurationContext context, + string authority, + Dictionary scopes, + string apiTitle, + string apiVersion = "v1", + string apiName = "v1" + ) + { + context.Services.AddAbpSwaggerGenWithOAuth( + authority: authority, + scopes: scopes, + options => + { + options.SwaggerDoc(apiName, new OpenApiInfo { Title = apiTitle, Version = apiVersion }); + options.DocInclusionPredicate((docName, description) => true); + options.CustomSchemaIds(type => type.FullName); + }); + } } } \ No newline at end of file diff --git a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerWithAuthConfigurationHelper.cs b/shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerWithAuthConfigurationHelper.cs deleted file mode 100644 index 33ac56a8..00000000 --- a/shared/EShopOnAbp.Shared.Hosting.AspNetCore/SwaggerWithAuthConfigurationHelper.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Collections.Generic; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.OpenApi.Models; -using Volo.Abp.Modularity; - -namespace EShopOnAbp.Shared.Hosting.AspNetCore -{ - public static class SwaggerWithAuthConfigurationHelper - { - public static void Configure( - ServiceConfigurationContext context, - string authority, - Dictionary scopes, - string apiTitle, - string apiVersion = "v1", - string apiName = "v1" - ) - { - context.Services.AddAbpSwaggerGenWithOAuth( - authority: authority, - scopes: scopes, - options => - { - options.SwaggerDoc(apiName, new OpenApiInfo { Title = apiTitle, Version = apiVersion }); - options.DocInclusionPredicate((docName, description) => true); - options.CustomSchemaIds(type => type.FullName); - }); - } - } -} \ No newline at end of file