From 585945529fd176c2576312a26da86b4b7bd79a3e Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 11 Oct 2022 16:23:42 +0800 Subject: [PATCH 1/4] Add `service type` parameter to `ServiceProxyGenerator`. --- .../Mvc/ApiDescriptionExtensions.cs | 17 +++++++++++++---- .../AspNetCoreApiDescriptionModelProvider.cs | 1 + .../Volo/Abp/Cli/Commands/ProxyCommandBase.cs | 19 ++++++++++++++++++- .../Angular/AngularServiceProxyGenerator.cs | 7 ++++++- .../CSharp/CSharpServiceProxyGenerator.cs | 5 +++++ .../Cli/ServiceProxying/GenerateProxyArgs.cs | 4 ++++ .../JavaScriptServiceProxyGenerator.cs | 7 ++++++- .../ServiceProxyGeneratorBase.cs | 16 +++++++++++++++- .../Abp/Cli/ServiceProxying/ServiceType.cs | 8 ++++++++ .../Modeling/ControllerApiDescriptionModel.cs | 5 ++++- .../Modeling/ModuleApiDescriptionModel.cs | 4 ++-- 11 files changed, 82 insertions(+), 11 deletions(-) create mode 100644 framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/ServiceType.cs diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApiDescriptionExtensions.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApiDescriptionExtensions.cs index fdf33e788d..e0f9bbc6c1 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApiDescriptionExtensions.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/ApiDescriptionExtensions.cs @@ -1,5 +1,4 @@ -using Microsoft.AspNetCore.Mvc.Abstractions; -using Microsoft.AspNetCore.Mvc.ApiExplorer; +using Microsoft.AspNetCore.Mvc.ApiExplorer; using Microsoft.AspNetCore.Mvc.Controllers; using Volo.Abp.Reflection; @@ -7,9 +6,9 @@ namespace Volo.Abp.AspNetCore.Mvc; public static class ApiDescriptionExtensions { - public static bool IsRemoteService(this ApiDescription actionDescriptor) + public static bool IsRemoteService(this ApiDescription apiDescriptor) { - if (actionDescriptor.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor) + if (apiDescriptor.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor) { var remoteServiceAttr = ReflectionHelper.GetSingleAttributeOfMemberOrDeclaringTypeOrDefault(controllerActionDescriptor.MethodInfo); if (remoteServiceAttr != null && remoteServiceAttr.IsEnabled) @@ -31,4 +30,14 @@ public static class ApiDescriptionExtensions return false; } + + public static bool IsIntegrationService(this ApiDescription apiDescriptor) + { + if (apiDescriptor.ActionDescriptor is ControllerActionDescriptor controllerActionDescriptor) + { + return IntegrationServiceAttribute.IsDefinedOrInherited(controllerActionDescriptor.ControllerTypeInfo); + } + + return false; + } } diff --git a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs index dbc7532aab..f18e9d6c3c 100644 --- a/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs +++ b/framework/src/Volo.Abp.AspNetCore.Mvc/Volo/Abp/AspNetCore/Mvc/AspNetCoreApiDescriptionModelProvider.cs @@ -103,6 +103,7 @@ public class AspNetCoreApiDescriptionModelProvider : IApiDescriptionModelProvide _options.ControllerNameGenerator(controllerType, setting), FindGroupName(controllerType) ?? apiDescription.GroupName, apiDescription.IsRemoteService(), + apiDescription.IsIntegrationService(), apiDescription.GetProperty()?.ToString(), controllerType, _modelOptions.IgnoredInterfaces diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs index 67c61b2a28..bd48f5c828 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/Commands/ProxyCommandBase.cs @@ -68,8 +68,19 @@ public abstract class ProxyCommandBase : IConsoleCommand, ITransientDependenc var source = commandLineArgs.Options.GetOrNull(Options.Source.Short, Options.Source.Long); var workDirectory = commandLineArgs.Options.GetOrNull(Options.WorkDirectory.Short, Options.WorkDirectory.Long) ?? Directory.GetCurrentDirectory(); var folder = commandLineArgs.Options.GetOrNull(Options.Folder.Long); + var serviceTypeArg = commandLineArgs.Options.GetOrNull(Options.Module.Short, Options.ServiceType.Long); - return new GenerateProxyArgs(CommandName, workDirectory, module, url, output, target, apiName, source, folder, commandLineArgs.Options); + ServiceType? serviceType = null; + if (!serviceTypeArg.IsNullOrWhiteSpace()) + { + serviceType = serviceTypeArg.ToLower() == "application" + ? ServiceType.Application + : serviceTypeArg.ToLower() == "integration" + ? ServiceType.Integration + : null; + } + + return new GenerateProxyArgs(CommandName, workDirectory, module, url, output, target, apiName, source, folder, serviceType, commandLineArgs.Options); } public virtual string GetUsageInfo() @@ -162,5 +173,11 @@ public abstract class ProxyCommandBase : IConsoleCommand, ITransientDependenc public const string Short = "wd"; public const string Long = "working-directory"; } + + public static class ServiceType + { + public const string Short = "st"; + public const string Long = "service-type"; + } } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/Angular/AngularServiceProxyGenerator.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/Angular/AngularServiceProxyGenerator.cs index 5f1698661e..6ee080f41b 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/Angular/AngularServiceProxyGenerator.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/Angular/AngularServiceProxyGenerator.cs @@ -30,7 +30,7 @@ public class AngularServiceProxyGenerator : ServiceProxyGeneratorBase ExtraProperties { get; set; } @@ -38,6 +40,7 @@ public class GenerateProxyArgs string apiName, string source, string folder, + ServiceType? serviceType, Dictionary extraProperties = null) { CommandName = Check.NotNullOrWhiteSpace(commandName, nameof(commandName)); @@ -49,6 +52,7 @@ public class GenerateProxyArgs ApiName = apiName; Source = source; Folder = folder; + ServiceType = serviceType; ExtraProperties = extraProperties ?? new Dictionary(); } } diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/JavaScript/JavaScriptServiceProxyGenerator.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/JavaScript/JavaScriptServiceProxyGenerator.cs index f1f3bef1cc..4871679009 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/JavaScript/JavaScriptServiceProxyGenerator.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/JavaScript/JavaScriptServiceProxyGenerator.cs @@ -28,7 +28,7 @@ public class JavaScriptServiceProxyGenerator : ServiceProxyGeneratorBase : IServiceProxyGenerator wher throw new CliUsageException($"Module name: {args.Module} is invalid"); } + var serviceType = args.ServiceType ?? GetDefaultServiceType(args); + + switch (serviceType) + { + case ServiceType.Application: + moduleDefinition.Controllers.RemoveAll(x => !x.Value.IsRemoteService); + break; + case ServiceType.Integration: + moduleDefinition.Controllers.RemoveAll(x => !x.Value.IsIntegrationService); + break; + } + var apiDescriptionModel = ApplicationApiDescriptionModel.Create(); apiDescriptionModel.AddModule(moduleDefinition); - return apiDescriptionModel; } + protected abstract ServiceType? GetDefaultServiceType(GenerateProxyArgs args); + protected string GetLoggerOutputPath(string path, string workDirectory) { return path.Replace(workDirectory, string.Empty).TrimStart(Path.DirectorySeparatorChar); diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/ServiceType.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/ServiceType.cs new file mode 100644 index 0000000000..c0d9979593 --- /dev/null +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/ServiceType.cs @@ -0,0 +1,8 @@ +namespace Volo.Abp.Cli.ServiceProxying; + +public enum ServiceType : byte +{ + All = 0, + Application = 1, + Integration = 2 +} diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ControllerApiDescriptionModel.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ControllerApiDescriptionModel.cs index 05021a9115..cb2fce9bbb 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ControllerApiDescriptionModel.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ControllerApiDescriptionModel.cs @@ -14,6 +14,8 @@ public class ControllerApiDescriptionModel public bool IsRemoteService { get; set; } + public bool IsIntegrationService { get; set; } + public string ApiVersion { get; set; } public string Type { get; set; } @@ -27,13 +29,14 @@ public class ControllerApiDescriptionModel } - public static ControllerApiDescriptionModel Create(string controllerName, string groupName, bool isRemoteService, string apiVersion, Type type, [CanBeNull] HashSet ignoredInterfaces = null) + public static ControllerApiDescriptionModel Create(string controllerName, string groupName, bool isRemoteService, bool isIntegrationService, string apiVersion, Type type, [CanBeNull] HashSet ignoredInterfaces = null) { return new ControllerApiDescriptionModel { ControllerName = controllerName, ControllerGroupName = groupName, IsRemoteService = isRemoteService, + IsIntegrationService = isIntegrationService, ApiVersion = apiVersion, Type = type.FullName, Actions = new Dictionary(), diff --git a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModuleApiDescriptionModel.cs b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModuleApiDescriptionModel.cs index 48b6cd3cda..bb2c25e3eb 100644 --- a/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModuleApiDescriptionModel.cs +++ b/framework/src/Volo.Abp.Http/Volo/Abp/Http/Modeling/ModuleApiDescriptionModel.cs @@ -49,10 +49,10 @@ public class ModuleApiDescriptionModel return Controllers[controller.Type] = controller; } - public ControllerApiDescriptionModel GetOrAddController(string name, string groupName, bool isRemoteService, string apiVersion, Type type, [CanBeNull] HashSet ignoredInterfaces = null) + public ControllerApiDescriptionModel GetOrAddController(string name, string groupName, bool isRemoteService, bool isIntegrationService, string apiVersion, Type type, [CanBeNull] HashSet ignoredInterfaces = null) { var key = apiVersion.IsNullOrWhiteSpace() ? type.FullName : $"{apiVersion + "."}{type.FullName}"; - return Controllers.GetOrAdd(key, () => ControllerApiDescriptionModel.Create(name, groupName, isRemoteService, apiVersion, type, ignoredInterfaces)); + return Controllers.GetOrAdd(key, () => ControllerApiDescriptionModel.Create(name, groupName, isRemoteService, isIntegrationService, apiVersion, type, ignoredInterfaces)); } public ModuleApiDescriptionModel CreateSubModel(string[] controllers, string[] actions) From b64dc32f789b72640fcef63c48e0493a8ca22c5d Mon Sep 17 00:00:00 2001 From: maliming Date: Tue, 11 Oct 2022 17:23:54 +0800 Subject: [PATCH 2/4] Update CLI.md --- docs/en/CLI.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/en/CLI.md b/docs/en/CLI.md index 7a5e59a62a..dc8d0c3d4c 100644 --- a/docs/en/CLI.md +++ b/docs/en/CLI.md @@ -365,6 +365,7 @@ abp generate-proxy -t csharp -url https://localhost:44302/ * `--module` or `-m`: Specifies the name of the backend module you wish to generate proxies for. Default value: `app`. * `--working-directory` or `-wd`: Execution directory. For `csharp` and `js` client types. * `--url` or `-u`: API definition URL from. +* `--service-type` or `-sp`: Specifies the service type to generate. `application`, `integration` and `all`, Default value: `all` for C#, `application` for JavaScript / Angular. > See the [Angular Service Proxies document](UI/Angular/Service-Proxies.md) for more. From 977744ad34fdfc6e8a866cef2d8b1a1ab656374e Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 12 Oct 2022 08:38:24 +0800 Subject: [PATCH 3/4] Update docs/en/CLI.md Co-authored-by: Qingxiao Ren --- docs/en/CLI.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/en/CLI.md b/docs/en/CLI.md index dc8d0c3d4c..53ae66f1b4 100644 --- a/docs/en/CLI.md +++ b/docs/en/CLI.md @@ -365,7 +365,7 @@ abp generate-proxy -t csharp -url https://localhost:44302/ * `--module` or `-m`: Specifies the name of the backend module you wish to generate proxies for. Default value: `app`. * `--working-directory` or `-wd`: Execution directory. For `csharp` and `js` client types. * `--url` or `-u`: API definition URL from. -* `--service-type` or `-sp`: Specifies the service type to generate. `application`, `integration` and `all`, Default value: `all` for C#, `application` for JavaScript / Angular. +* `--service-type` or `-st`: Specifies the service type to generate. `application`, `integration` and `all`, Default value: `all` for C#, `application` for JavaScript / Angular. > See the [Angular Service Proxies document](UI/Angular/Service-Proxies.md) for more. From 8abf33f2e65930016df651c31bca211c2dc24eed Mon Sep 17 00:00:00 2001 From: maliming Date: Wed, 12 Oct 2022 16:47:37 +0800 Subject: [PATCH 4/4] Pass `service-type to `@abp/ng.schematics`. --- .../Angular/AngularServiceProxyGenerator.cs | 6 ++++++ .../Abp/Cli/ServiceProxying/ServiceProxyGeneratorBase.cs | 8 ++++++-- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/Angular/AngularServiceProxyGenerator.cs b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/Angular/AngularServiceProxyGenerator.cs index 6ee080f41b..0376828fc2 100644 --- a/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/Angular/AngularServiceProxyGenerator.cs +++ b/framework/src/Volo.Abp.Cli.Core/Volo/Abp/Cli/ServiceProxying/Angular/AngularServiceProxyGenerator.cs @@ -76,6 +76,12 @@ public class AngularServiceProxyGenerator : ServiceProxyGeneratorBase : IServiceProxyGenerator wher throw new CliUsageException($"Module name: {args.Module} is invalid"); } - var serviceType = args.ServiceType ?? GetDefaultServiceType(args); - + var serviceType = GetServiceType(args); switch (serviceType) { case ServiceType.Application: @@ -60,6 +59,11 @@ public abstract class ServiceProxyGeneratorBase : IServiceProxyGenerator wher return apiDescriptionModel; } + protected virtual ServiceType? GetServiceType(GenerateProxyArgs args) + { + return args.ServiceType ?? GetDefaultServiceType(args); + } + protected abstract ServiceType? GetDefaultServiceType(GenerateProxyArgs args); protected string GetLoggerOutputPath(string path, string workDirectory)