diff --git a/.chronus/changes/java_mgmt_premium_sample_service_client-2026-2-19-9-20-23.md b/.chronus/changes/java_mgmt_premium_sample_service_client-2026-2-19-9-20-23.md new file mode 100644 index 00000000000..380d9d455d2 --- /dev/null +++ b/.chronus/changes/java_mgmt_premium_sample_service_client-2026-2-19-9-20-23.md @@ -0,0 +1,8 @@ +--- +# Change versionKind to one of: internal, fix, dependencies, feature, deprecation, breaking +changeKind: fix +packages: + - "@typespec/http-client-java" +--- + +mgmt premium, fix sample entry point and serviceClient reference diff --git a/cspell.yaml b/cspell.yaml index 6d4f45eceea..eb028800fa8 100644 --- a/cspell.yaml +++ b/cspell.yaml @@ -155,6 +155,7 @@ words: - mqtt - mros - msbuild + - msgraph - mspaint - MSRC - msrest 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 8a84ec1764c..c0f70415a8e 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 @@ -15,6 +15,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Optional; /** * Model of example for service client method (usually for Fluent Premium). @@ -92,7 +93,13 @@ public String getMethodReference() { throw new IllegalStateException("Package '" + namespace + "' is not supported by Fluent Premium"); } - String serviceClientReference = ModelNaming.METHOD_SERVICE_CLIENT + "()"; + String serviceClientReference; + Optional metadataSuffix = FluentStatic.getFluentJavaSettings().getMetadataSuffix(); + if (metadataSuffix.isPresent() && SECONDARY_SERVICE_CLIENT_ACCESSOR.containsKey(metadataSuffix.get())) { + serviceClientReference = SECONDARY_SERVICE_CLIENT_ACCESSOR.get(metadataSuffix.get()) + "()"; + } else { + serviceClientReference = ModelNaming.METHOD_SERVICE_CLIENT + "()"; + } String methodGroupReference = "get" + CodeNamer.toPascalCase(methodGroup.getVariableName()) + "()"; return serviceClientReference + "." + methodGroupReference; } @@ -128,4 +135,30 @@ public String getMethodName() { MANAGER_REFERENCE.put("storage", "storageAccounts()"); MANAGER_REFERENCE.put("trafficmanager", "trafficManagerProfiles()"); } + + // Maps metadata-suffix (from secondary specs in multi-spec packages) to the service client + // accessor method on the SDK Manager class. When a secondary spec shares a Manager with the + // primary spec, serviceClient() returns the primary inner client. This map provides the correct + // accessor for the secondary inner client. + // Source of truth: + // https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/resourcemanager/api-specs.json + private static final Map SECONDARY_SERVICE_CLIENT_ACCESSOR = new HashMap<>(); + static { + // resources package secondaries (ResourceManager) + SECONDARY_SERVICE_CLIENT_ACCESSOR.put("feature", "featureClient"); + SECONDARY_SERVICE_CLIENT_ACCESSOR.put("policy", "policyClient"); + SECONDARY_SERVICE_CLIENT_ACCESSOR.put("lock", "managementLockClient"); + SECONDARY_SERVICE_CLIENT_ACCESSOR.put("subscription", "subscriptionClient"); + SECONDARY_SERVICE_CLIENT_ACCESSOR.put("change", "resourceChangeClient"); + SECONDARY_SERVICE_CLIENT_ACCESSOR.put("databoundary", "dataBoundaryClient"); + SECONDARY_SERVICE_CLIENT_ACCESSOR.put("deployments", "deploymentClient"); + SECONDARY_SERVICE_CLIENT_ACCESSOR.put("deploymentstacks", "deploymentStackClient"); + // appservice package secondaries (AppServiceManager) + SECONDARY_SERVICE_CLIENT_ACCESSOR.put("certificateregistration", "certificateRegistrationClient"); + SECONDARY_SERVICE_CLIENT_ACCESSOR.put("domainregistration", "domainRegistrationClient"); + // containerregistry package secondary (ContainerRegistryManager) + SECONDARY_SERVICE_CLIENT_ACCESSOR.put("registrytasks", "taskClient"); + // authorization: msgraph uses default serviceClient() (AuthorizationManager implements + // HasServiceClient), no override needed + } }