From 5a7deafc2ccfef66a9171c2da7422bc738ec8b36 Mon Sep 17 00:00:00 2001 From: xiaofeicao Date: Sat, 28 Feb 2026 16:35:34 +0800 Subject: [PATCH 1/3] use XXManager for premium samples --- .../generator/mgmt/model/FluentType.java | 3 - .../FluentClientMethodExample.java | 86 +++---------------- 2 files changed, 14 insertions(+), 75 deletions(-) diff --git a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/FluentType.java b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/FluentType.java index aa115a0c1fd..d57588c394f 100644 --- a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/FluentType.java +++ b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/FluentType.java @@ -34,9 +34,6 @@ public class FluentType { public static final ClassType SYSTEM_DATA = new ClassType.Builder().packageName("com.azure.core.management").name("SystemData").build(); - public static final ClassType AZURE_RESOURCE_MANAGER - = new ClassType.Builder().packageName("com.azure.resourcemanager").name("AzureResourceManager").build(); - public static final ClassType ADDITIONAL_INFO = new ClassType.Builder().packageName("com.azure.core.management.exception").name("AdditionalInfo").build(); diff --git a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/examplemodel/FluentClientMethodExample.java b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/examplemodel/FluentClientMethodExample.java index 9f953078512..5b3d2cb75c3 100644 --- a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/examplemodel/FluentClientMethodExample.java +++ b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/examplemodel/FluentClientMethodExample.java @@ -8,13 +8,11 @@ import com.microsoft.typespec.http.client.generator.core.model.clientmodel.ClientMethod; import com.microsoft.typespec.http.client.generator.core.model.clientmodel.MethodGroupClient; import com.microsoft.typespec.http.client.generator.core.util.CodeNamer; -import com.microsoft.typespec.http.client.generator.mgmt.model.FluentType; +import com.microsoft.typespec.http.client.generator.mgmt.model.clientmodel.FluentStatic; import com.microsoft.typespec.http.client.generator.mgmt.model.clientmodel.ModelNaming; +import com.microsoft.typespec.http.client.generator.mgmt.util.FluentUtils; import java.util.ArrayList; -import java.util.LinkedHashMap; import java.util.List; -import java.util.Map; -import java.util.regex.Pattern; /** * Model of example for service client method (usually for Fluent Premium). @@ -26,6 +24,7 @@ public class FluentClientMethodExample implements FluentMethodExample { private final MethodGroupClient methodGroup; private final ClientMethod clientMethod; private final List parameters = new ArrayList<>(); + private final ClassType managerType; public FluentClientMethodExample(String name, String originalFileName, MethodGroupClient methodGroup, ClientMethod clientMethod) { @@ -33,6 +32,13 @@ public FluentClientMethodExample(String name, String originalFileName, MethodGro this.originalFileName = originalFileName; this.methodGroup = methodGroup; this.clientMethod = clientMethod; + + String clientName = FluentStatic.getClient().getServiceClient().getClientBaseName(); + String serviceName = FluentUtils.getServiceName(clientName); + JavaSettings settings = JavaSettings.getInstance(); + this.managerType = new ClassType.Builder().packageName(settings.getPackage()) + .name(CodeNamer.toPascalCase(serviceName) + "Manager") + .build(); } public MethodGroupClient getMethodGroup() { @@ -55,17 +61,17 @@ public String getOriginalFileName() { @Override public ClassType getEntryType() { - return FluentType.AZURE_RESOURCE_MANAGER; + return managerType; } @Override public String getEntryName() { - return "azure"; + return "manager"; } @Override public String getEntryDescription() { - return "The entry point for accessing resource management APIs in Azure."; + return String.format("Entry point to %1$s.", managerType.getName()); } @Override @@ -75,47 +81,9 @@ public List getParameters() { @Override public String getMethodReference() { - JavaSettings settings = JavaSettings.getInstance(); - - String namespace = settings.getPackage(); - String[] identifiers = namespace.split(Pattern.quote(".")); - String lastIdentifier = identifiers[identifiers.length - 1]; - - if (!MANAGER_REFERENCE.containsKey(lastIdentifier)) { - throw new IllegalStateException("Package '" + namespace + "' is not supported by Fluent Premium"); - } - - String managerReference = MANAGER_REFERENCE.get(lastIdentifier) + "." + ModelNaming.METHOD_MANAGER + "()"; String serviceClientReference = ModelNaming.METHOD_SERVICE_CLIENT + "()"; - if ("authorization".equals(lastIdentifier)) { - serviceClientReference = "roleServiceClient()"; - } else if ("resources".equals(lastIdentifier)) { - String tag = settings.getAutorestSettings().getTag(); - if (tag.contains("feature")) { - serviceClientReference = "featureClient()"; - } else if (tag.contains("policy")) { - serviceClientReference = "policyClient()"; - } else if (tag.contains("subscriptions")) { - serviceClientReference = "subscriptionClient()"; - } else if (tag.contains("locks")) { - serviceClientReference = "managementLockClient()"; - } else if (tag.contains("changes")) { - serviceClientReference = "resourceChangeClient()"; - } else if (tag.contains("databoundaries")) { - serviceClientReference = "dataBoundaryClient()"; - } else if (!tag.contains("resources")) { - // OpenAPI source of deployments moved to a separate folder - serviceClientReference = "deploymentClient()"; - } - } else if ("containerregistry".equals(lastIdentifier)) { - String title = settings.getAutorestSettings().getTitle(); - if ("ContainerRegistryTasks".equals(title)) { - serviceClientReference = "taskClient()"; - } - } - String methodGroupReference = "get" + CodeNamer.toPascalCase(methodGroup.getVariableName()) + "()"; - return managerReference + "." + serviceClientReference + "." + methodGroupReference; + return serviceClientReference + "." + methodGroupReference; } @Override @@ -123,30 +91,4 @@ public String getMethodName() { return clientMethod.getName(); } - private final static Map MANAGER_REFERENCE = new LinkedHashMap<>(); - static { - MANAGER_REFERENCE.put("appplatform", "springServices()"); - MANAGER_REFERENCE.put("appservice", "webApps()"); - MANAGER_REFERENCE.put("authorization", "accessManagement().roleAssignments()"); - MANAGER_REFERENCE.put("cdn", "cdnProfiles()"); - MANAGER_REFERENCE.put("compute", "virtualMachines()"); - MANAGER_REFERENCE.put("containerinstance", "containerGroups()"); - MANAGER_REFERENCE.put("containerregistry", "containerRegistries()"); - MANAGER_REFERENCE.put("containerservice", "kubernetesClusters()"); - MANAGER_REFERENCE.put("cosmos", "cosmosDBAccounts()"); - MANAGER_REFERENCE.put("dns", "dnsZones()"); - MANAGER_REFERENCE.put("eventhubs", "eventHubs()"); - MANAGER_REFERENCE.put("keyvault", "vaults()"); - MANAGER_REFERENCE.put("monitor", "diagnosticSettings()"); - MANAGER_REFERENCE.put("msi", "identities()"); - MANAGER_REFERENCE.put("network", "networks()"); - MANAGER_REFERENCE.put("privatedns", "privateDnsZones()"); - MANAGER_REFERENCE.put("redis", "redisCaches()"); - MANAGER_REFERENCE.put("resources", "genericResources()"); - MANAGER_REFERENCE.put("search", "searchServices()"); - MANAGER_REFERENCE.put("servicebus", "serviceBusNamespaces()"); - MANAGER_REFERENCE.put("sql", "sqlServers()"); - MANAGER_REFERENCE.put("storage", "storageAccounts()"); - MANAGER_REFERENCE.put("trafficmanager", "trafficManagerProfiles()"); - } } From 43859ed51968fd10125aa743b74ea67a64c792e4 Mon Sep 17 00:00:00 2001 From: Xiaofei Cao <92354331+XiaofeiCao@users.noreply.github.com> Date: Sat, 28 Feb 2026 17:38:31 +0800 Subject: [PATCH 2/3] changelog Updated changeKind to 'fix' for Java management entries. --- ..._use_individual_entry_for_premium-2026-1-28-9-31-24.md | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 .chronus/changes/java_mgmt_use_individual_entry_for_premium-2026-1-28-9-31-24.md diff --git a/.chronus/changes/java_mgmt_use_individual_entry_for_premium-2026-1-28-9-31-24.md b/.chronus/changes/java_mgmt_use_individual_entry_for_premium-2026-1-28-9-31-24.md new file mode 100644 index 00000000000..a98b8ca5b89 --- /dev/null +++ b/.chronus/changes/java_mgmt_use_individual_entry_for_premium-2026-1-28-9-31-24.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@typespec/http-client-java" +--- + +mgmt, use separate entry points for premium samples From 4b50e4045bfc0d903d729490da76a6a7a6b98991 Mon Sep 17 00:00:00 2001 From: "Xiaofei Cao (from Dev Box)" Date: Mon, 2 Mar 2026 16:41:13 +0800 Subject: [PATCH 3/3] add back premium check, to avoid accidental config issue --- .../FluentClientMethodExample.java | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/examplemodel/FluentClientMethodExample.java b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/examplemodel/FluentClientMethodExample.java index 5b3d2cb75c3..8a84ec1764c 100644 --- a/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/examplemodel/FluentClientMethodExample.java +++ b/packages/http-client-java/generator/http-client-generator-mgmt/src/main/java/com/microsoft/typespec/http/client/generator/mgmt/model/clientmodel/examplemodel/FluentClientMethodExample.java @@ -12,7 +12,9 @@ import com.microsoft.typespec.http.client.generator.mgmt.model.clientmodel.ModelNaming; import com.microsoft.typespec.http.client.generator.mgmt.util.FluentUtils; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * Model of example for service client method (usually for Fluent Premium). @@ -81,6 +83,15 @@ public List getParameters() { @Override public String getMethodReference() { + JavaSettings settings = JavaSettings.getInstance(); + String namespace = settings.getPackage(); + String lastIdentifier = namespace.substring(namespace.lastIndexOf('.') + 1); + + // Guard against accidental premium code generation for non-premium libraries + if (!MANAGER_REFERENCE.containsKey(lastIdentifier)) { + throw new IllegalStateException("Package '" + namespace + "' is not supported by Fluent Premium"); + } + String serviceClientReference = ModelNaming.METHOD_SERVICE_CLIENT + "()"; String methodGroupReference = "get" + CodeNamer.toPascalCase(methodGroup.getVariableName()) + "()"; return serviceClientReference + "." + methodGroupReference; @@ -91,4 +102,30 @@ public String getMethodName() { return clientMethod.getName(); } + private static final Map MANAGER_REFERENCE = new HashMap<>(); + static { + MANAGER_REFERENCE.put("appplatform", "springServices()"); + MANAGER_REFERENCE.put("appservice", "webApps()"); + MANAGER_REFERENCE.put("authorization", "accessManagement().roleAssignments()"); + MANAGER_REFERENCE.put("cdn", "cdnProfiles()"); + MANAGER_REFERENCE.put("compute", "virtualMachines()"); + MANAGER_REFERENCE.put("containerinstance", "containerGroups()"); + MANAGER_REFERENCE.put("containerregistry", "containerRegistries()"); + MANAGER_REFERENCE.put("containerservice", "kubernetesClusters()"); + MANAGER_REFERENCE.put("cosmos", "cosmosDBAccounts()"); + MANAGER_REFERENCE.put("dns", "dnsZones()"); + MANAGER_REFERENCE.put("eventhubs", "eventHubs()"); + MANAGER_REFERENCE.put("keyvault", "vaults()"); + MANAGER_REFERENCE.put("monitor", "diagnosticSettings()"); + MANAGER_REFERENCE.put("msi", "identities()"); + MANAGER_REFERENCE.put("network", "networks()"); + MANAGER_REFERENCE.put("privatedns", "privateDnsZones()"); + MANAGER_REFERENCE.put("redis", "redisCaches()"); + MANAGER_REFERENCE.put("resources", "genericResources()"); + MANAGER_REFERENCE.put("search", "searchServices()"); + MANAGER_REFERENCE.put("servicebus", "serviceBusNamespaces()"); + MANAGER_REFERENCE.put("sql", "sqlServers()"); + MANAGER_REFERENCE.put("storage", "storageAccounts()"); + MANAGER_REFERENCE.put("trafficmanager", "trafficManagerProfiles()"); + } }