diff --git a/docs/en/CLI.md b/docs/en/CLI.md index f9e592a788..5a8769a996 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 `-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. 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 5efae62b90..46c0ffa197 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,10 +68,22 @@ 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); + + ServiceType? serviceType = null; + if (!serviceTypeArg.IsNullOrWhiteSpace()) + { + serviceType = serviceTypeArg.ToLower() == "application" + ? ServiceType.Application + : serviceTypeArg.ToLower() == "integration" + ? ServiceType.Integration + : null; + } + var withoutContracts = commandLineArgs.Options.ContainsKey(Options.WithoutContracts.Short) || commandLineArgs.Options.ContainsKey(Options.WithoutContracts.Long); - return new GenerateProxyArgs(CommandName, workDirectory, module, url, output, target, apiName, source, folder, withoutContracts, commandLineArgs.Options); + return new GenerateProxyArgs(CommandName, workDirectory, module, url, output, target, apiName, source, folder, serviceType, withoutContracts, commandLineArgs.Options); } public virtual string GetUsageInfo() @@ -165,6 +177,13 @@ public abstract class ProxyCommandBase : IConsoleCommand, ITransientDependenc public const string Long = "working-directory"; } + + public static class ServiceType + { + public const string Short = "st"; + public const string Long = "service-type"; + } + public static class WithoutContracts { public const string Short = "c"; 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..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 @@ -30,7 +30,7 @@ public class AngularServiceProxyGenerator : ServiceProxyGeneratorBase extraProperties = null) { @@ -52,6 +55,7 @@ public class GenerateProxyArgs ApiName = apiName; Source = source; Folder = folder; + ServiceType = serviceType; WithoutContracts = withoutContracts; 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 = GetServiceType(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.Types = apiDefinition.Types; apiDescriptionModel.AddModule(moduleDefinition); - 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) { 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 81c64e8ec4..e2e0e53e9f 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,7 +14,7 @@ public class ControllerApiDescriptionModel public bool IsRemoteService { get; set; } - public bool IntegrationService { get; set; } + public bool IsIntegrationService { get; set; } public string ApiVersion { get; set; } @@ -29,14 +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, - IntegrationService = IntegrationServiceAttribute.IsDefinedOrInherited(type), + IsIntegrationService = isIntegrationService, //IntegrationServiceAttribute.IsDefinedOrInherited(type), 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)