From c9aeff4d036475aa92eb9c94182a6eb705bcf703 Mon Sep 17 00:00:00 2001 From: Srikanta Date: Mon, 20 Jul 2020 15:10:27 -0700 Subject: [PATCH] Add option to make proxy service interface public --- .../extension/base/plugin/JavaSettings.java | 15 ++++++++++++--- .../azure/autorest/template/ProxyTemplate.java | 8 +++++++- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/extension-base/src/main/java/com/azure/autorest/extension/base/plugin/JavaSettings.java b/extension-base/src/main/java/com/azure/autorest/extension/base/plugin/JavaSettings.java index 55f60a7799..e474c2125d 100644 --- a/extension-base/src/main/java/com/azure/autorest/extension/base/plugin/JavaSettings.java +++ b/extension-base/src/main/java/com/azure/autorest/extension/base/plugin/JavaSettings.java @@ -87,7 +87,8 @@ public static JavaSettings getInstance() host.getBooleanValue("generate-sync-async-clients", false), host.getStringValue("sync-methods", "essential"), host.getBooleanValue("client-logger", false), - host.getBooleanValue("required-fields-as-ctor-args")); + host.getBooleanValue("required-fields-as-ctor-args", false), + host.getBooleanValue("service-interface-as-public", false)); } return _instance; } @@ -108,6 +109,7 @@ public static JavaSettings getInstance() @param implementationSubpackage The sub-package that the Service and Method Group client implementation classes will be put into. @param modelsSubpackage The sub-package that Enums, Exceptions, and Model types will be put into. @param requiredParameterClientMethods Whether or not Service and Method Group client method overloads that omit optional parameters will be created. + @param serviceInterfaceAsPublic If set to true, proxy method service interface will be marked as public. */ private JavaSettings(boolean azure, boolean fluent, @@ -132,7 +134,8 @@ private JavaSettings(boolean azure, boolean generateSyncAsyncClients, String syncMethods, boolean clientLogger, - boolean requiredFieldsAsConstructorArgs) + boolean requiredFieldsAsConstructorArgs, + boolean serviceInterfaceAsPublic) { this.azure = azure; this.fluent = fluent; @@ -158,8 +161,10 @@ private JavaSettings(boolean azure, this.syncMethods = SyncMethodsGeneration.fromValue(syncMethods); this.clientLogger = clientLogger; this.requiredFieldsAsConstructorArgs = requiredFieldsAsConstructorArgs; + this.serviceInterfaceAsPublic = serviceInterfaceAsPublic; } + private boolean azure; public final boolean isAzure() { @@ -322,7 +327,11 @@ public boolean isRequiredFieldsAsConstructorArgs() { return requiredFieldsAsConstructorArgs; } - public enum SyncMethodsGeneration { + private boolean serviceInterfaceAsPublic; + public boolean isServiceInterfaceAsPublic() { + return serviceInterfaceAsPublic; + } + public enum SyncMethodsGeneration { ALL, ESSENTIAL, NONE; diff --git a/javagen/src/main/java/com/azure/autorest/template/ProxyTemplate.java b/javagen/src/main/java/com/azure/autorest/template/ProxyTemplate.java index ad46e5573f..02197006ec 100644 --- a/javagen/src/main/java/com/azure/autorest/template/ProxyTemplate.java +++ b/javagen/src/main/java/com/azure/autorest/template/ProxyTemplate.java @@ -44,7 +44,13 @@ public final void write(Proxy restAPI, JavaClass classBlock) { }); classBlock.annotation(String.format("Host(\"%1$s\")", restAPI.getBaseURL())); classBlock.annotation(String.format("ServiceInterface(name = \"%1$s\")", serviceInterfaceWithLengthLimit(restAPI.getClientTypeName()))); - classBlock.interfaceBlock(JavaVisibility.Private, restAPI.getName(), interfaceBlock -> + + JavaVisibility visibility = JavaVisibility.Private; + if (settings.isServiceInterfaceAsPublic()) { + visibility = JavaVisibility.Public; + } + + classBlock.interfaceBlock(visibility, restAPI.getName(), interfaceBlock -> { for (ProxyMethod restAPIMethod : restAPI.getMethods()) { if (restAPIMethod.getRequestContentType().equals("multipart/form-data") || restAPIMethod.getRequestContentType().equals("application/x-www-form-urlencoded")) {