From fea9d2e45bfcf39aeb8730a74bb1f1390905e3eb Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 9 Jan 2026 23:54:26 +0800 Subject: [PATCH 1/6] core on http-client-java_subclass-property-change --- core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core b/core index 8c4d64c094..c515fdd341 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 8c4d64c0943f9643308a6fd0bd98b5ea2aa57342 +Subproject commit c515fdd3419857041f2a0d0d1e72a5e7252f2aa2 From e33b7a20161965e7c8f7ae962aff227cc6950bab Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Sun, 11 Jan 2026 18:19:09 +0800 Subject: [PATCH 2/6] update core --- core | 2 +- .../combined/fluent/Combined.java | 7 - .../combined/implementation/CombinedImpl.java | 15 - .../implementation/DisksClientImpl.java | 21 +- .../VirtualMachinesClientImpl.java | 21 +- .../combined/CombinedBuilder.java | 24 +- .../combined/ServiceAServiceVersion.java | 45 -- .../combined/implementation/BarsImpl.java | 19 +- .../combined/implementation/CombinedImpl.java | 30 +- .../combined/implementation/FoosImpl.java | 19 +- .../tsptest/armlegacy/ArmLegacyManager.java | 282 ++++++++ .../armlegacy/fluent/ArmLegacyClient.java | 55 ++ .../tsptest/armlegacy/fluent/SkusClient.java | 207 ++++++ .../fluent/models/SkuResourceInner.java | 155 ++++ .../armlegacy/fluent/models/package-info.java | 9 + .../armlegacy/fluent/package-info.java | 9 + .../ArmLegacyClientBuilder.java | 138 ++++ .../implementation/ArmLegacyClientImpl.java | 308 ++++++++ .../implementation/ResourceManagerUtils.java | 195 ++++++ .../implementation/SkuResourceImpl.java | 105 +++ .../implementation/SkusClientImpl.java | 662 ++++++++++++++++++ .../armlegacy/implementation/SkusImpl.java | 202 ++++++ .../implementation/package-info.java | 9 + .../armlegacy/models/ProvisioningState.java | 76 ++ .../armlegacy/models/ResourceTypeSku.java | 73 ++ .../tsptest/armlegacy/models/SkuResource.java | 137 ++++ .../java/tsptest/armlegacy/models/Skus.java | 214 ++++++ .../armlegacy/models/package-info.java | 9 + .../java/tsptest/armlegacy/package-info.java | 9 + .../models/SawShark.java | 1 - .../tsptest/subclass/SubclassAsyncClient.java | 113 +++ .../java/tsptest/subclass/SubclassClient.java | 111 +++ .../subclass/SubclassClientBuilder.java | 287 ++++++++ .../implementation/SubclassClientImpl.java | 107 +++ .../subclass/implementation/SubclassImpl.java | 189 +++++ .../subclass/implementation/package-info.java | 10 + .../java/tsptest/subclass/models/Body.java | 154 ++++ .../models/DuplicateRequiredProperty.java | 83 +++ .../DuplicateRequiredPropertyParent.java | 83 +++ .../models/PropertyChangedToConstant.java | 77 ++ .../PropertyChangedToConstantParent.java | 83 +++ .../models/PropertyChangedToRequired.java | 82 +++ .../PropertyChangedToRequiredParent.java | 93 +++ .../tsptest/subclass/models/package-info.java | 10 + .../java/tsptest/subclass/package-info.java | 10 + .../proxy-config.json | 1 + .../reflect-config.json | 1 + ...urcemanager-armlegacy-generated.properties | 1 + .../resources/tsptest-subclass.properties | 2 + .../multiservice/ArmMultipleServiceTests.java | 39 ++ .../multiservice/MultipleServiceTests.java | 21 + .../subclass/SubclassPropertyTests.java | 33 + .../generated/SubclassClientTestBase.java | 34 + typespec-tests/tsp/arm-legacy.tsp | 129 ++++ typespec-tests/tsp/subclass.tsp | 54 ++ 55 files changed, 4705 insertions(+), 160 deletions(-) delete mode 100644 typespec-tests/src/main/java/service/multiservice/combined/ServiceAServiceVersion.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/ArmLegacyManager.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/fluent/ArmLegacyClient.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/fluent/SkusClient.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/fluent/models/SkuResourceInner.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/fluent/models/package-info.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/fluent/package-info.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/implementation/ArmLegacyClientBuilder.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/implementation/ArmLegacyClientImpl.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/implementation/ResourceManagerUtils.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/implementation/SkuResourceImpl.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/implementation/SkusClientImpl.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/implementation/SkusImpl.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/implementation/package-info.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/models/ProvisioningState.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/models/ResourceTypeSku.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/models/SkuResource.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/models/Skus.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/models/package-info.java create mode 100644 typespec-tests/src/main/java/tsptest/armlegacy/package-info.java create mode 100644 typespec-tests/src/main/java/tsptest/subclass/SubclassAsyncClient.java create mode 100644 typespec-tests/src/main/java/tsptest/subclass/SubclassClient.java create mode 100644 typespec-tests/src/main/java/tsptest/subclass/SubclassClientBuilder.java create mode 100644 typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassClientImpl.java create mode 100644 typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassImpl.java create mode 100644 typespec-tests/src/main/java/tsptest/subclass/implementation/package-info.java create mode 100644 typespec-tests/src/main/java/tsptest/subclass/models/Body.java create mode 100644 typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredProperty.java create mode 100644 typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredPropertyParent.java create mode 100644 typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToConstant.java create mode 100644 typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToConstantParent.java create mode 100644 typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToRequired.java create mode 100644 typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToRequiredParent.java create mode 100644 typespec-tests/src/main/java/tsptest/subclass/models/package-info.java create mode 100644 typespec-tests/src/main/java/tsptest/subclass/package-info.java create mode 100644 typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armlegacy-generated/proxy-config.json create mode 100644 typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armlegacy-generated/reflect-config.json create mode 100644 typespec-tests/src/main/resources/azure-resourcemanager-armlegacy-generated.properties create mode 100644 typespec-tests/src/main/resources/tsptest-subclass.properties create mode 100644 typespec-tests/src/test/java/azure/resourcemanager/multiservice/ArmMultipleServiceTests.java create mode 100644 typespec-tests/src/test/java/service/multiservice/MultipleServiceTests.java create mode 100644 typespec-tests/src/test/java/tsptest/subclass/SubclassPropertyTests.java create mode 100644 typespec-tests/src/test/java/tsptest/subclass/generated/SubclassClientTestBase.java create mode 100644 typespec-tests/tsp/arm-legacy.tsp create mode 100644 typespec-tests/tsp/subclass.tsp diff --git a/core b/core index c515fdd341..993951fca9 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit c515fdd3419857041f2a0d0d1e72a5e7252f2aa2 +Subproject commit 993951fca9b12333a0dbc30867e8a58b5b42cb47 diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/Combined.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/Combined.java index 34d52fe5aa..2cca6a21a4 100644 --- a/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/Combined.java +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/Combined.java @@ -18,13 +18,6 @@ public interface Combined { */ String getEndpoint(); - /** - * Gets Version parameter. - * - * @return the apiVersion value. - */ - String getApiVersion(); - /** * Gets The ID of the target subscription. The value must be an UUID. * diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/CombinedImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/CombinedImpl.java index 4e1282d491..3082d51ed3 100644 --- a/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/CombinedImpl.java +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/CombinedImpl.java @@ -57,20 +57,6 @@ public String getEndpoint() { return this.endpoint; } - /** - * Version parameter. - */ - private final String apiVersion; - - /** - * Gets Version parameter. - * - * @return the apiVersion value. - */ - public String getApiVersion() { - return this.apiVersion; - } - /** * The ID of the target subscription. The value must be an UUID. */ @@ -172,7 +158,6 @@ public DisksClient getDisks() { this.defaultPollInterval = defaultPollInterval; this.endpoint = endpoint; this.subscriptionId = subscriptionId; - this.apiVersion = "2025-04-01"; this.virtualMachines = new VirtualMachinesClientImpl(this); this.disks = new DisksClientImpl(this); } diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/DisksClientImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/DisksClientImpl.java index d46361c0be..163e986aa1 100644 --- a/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/DisksClientImpl.java +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/DisksClientImpl.java @@ -112,9 +112,10 @@ Response createOrUpdateSync(@HostParam("endpoint") String endpoint, */ @ServiceMethod(returns = ReturnType.SINGLE) private Mono> getByResourceGroupWithResponseAsync(String resourceGroupName, String diskName) { + final String apiVersion = "2025-01-02"; final String accept = "application/json"; return FluxUtil - .withContext(context -> service.getByResourceGroup(this.client.getEndpoint(), this.client.getApiVersion(), + .withContext(context -> service.getByResourceGroup(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), resourceGroupName, diskName, accept, context)) .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); } @@ -149,9 +150,10 @@ private Mono getByResourceGroupAsync(String resourceGroupName, String @ServiceMethod(returns = ReturnType.SINGLE) public Response getByResourceGroupWithResponse(String resourceGroupName, String diskName, Context context) { + final String apiVersion = "2025-01-02"; final String accept = "application/json"; - return service.getByResourceGroupSync(this.client.getEndpoint(), this.client.getApiVersion(), - this.client.getSubscriptionId(), resourceGroupName, diskName, accept, context); + return service.getByResourceGroupSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, diskName, accept, context); } /** @@ -183,10 +185,11 @@ public DiskInner getByResourceGroup(String resourceGroupName, String diskName) { @ServiceMethod(returns = ReturnType.SINGLE) private Mono>> createOrUpdateWithResponseAsync(String resourceGroupName, String diskName, DiskInner resource) { + final String apiVersion = "2025-01-02"; final String contentType = "application/json"; final String accept = "application/json"; return FluxUtil - .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), this.client.getApiVersion(), + .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), resourceGroupName, diskName, contentType, accept, resource, context)) .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); } @@ -205,10 +208,11 @@ private Mono>> createOrUpdateWithResponseAsync(String @ServiceMethod(returns = ReturnType.SINGLE) private Response createOrUpdateWithResponse(String resourceGroupName, String diskName, DiskInner resource) { + final String apiVersion = "2025-01-02"; final String contentType = "application/json"; final String accept = "application/json"; - return service.createOrUpdateSync(this.client.getEndpoint(), this.client.getApiVersion(), - this.client.getSubscriptionId(), resourceGroupName, diskName, contentType, accept, resource, Context.NONE); + return service.createOrUpdateSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, diskName, contentType, accept, resource, Context.NONE); } /** @@ -226,10 +230,11 @@ private Response createOrUpdateWithResponse(String resourceGroupName @ServiceMethod(returns = ReturnType.SINGLE) private Response createOrUpdateWithResponse(String resourceGroupName, String diskName, DiskInner resource, Context context) { + final String apiVersion = "2025-01-02"; final String contentType = "application/json"; final String accept = "application/json"; - return service.createOrUpdateSync(this.client.getEndpoint(), this.client.getApiVersion(), - this.client.getSubscriptionId(), resourceGroupName, diskName, contentType, accept, resource, context); + return service.createOrUpdateSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, diskName, contentType, accept, resource, context); } /** diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/VirtualMachinesClientImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/VirtualMachinesClientImpl.java index 2553053f80..46c32f950a 100644 --- a/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/VirtualMachinesClientImpl.java +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/VirtualMachinesClientImpl.java @@ -115,9 +115,10 @@ Response createOrUpdateSync(@HostParam("endpoint") String endpoint, @ServiceMethod(returns = ReturnType.SINGLE) private Mono> getByResourceGroupWithResponseAsync(String resourceGroupName, String vmName) { + final String apiVersion = "2025-04-01"; final String accept = "application/json"; return FluxUtil - .withContext(context -> service.getByResourceGroup(this.client.getEndpoint(), this.client.getApiVersion(), + .withContext(context -> service.getByResourceGroup(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), resourceGroupName, vmName, accept, context)) .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); } @@ -152,9 +153,10 @@ private Mono getByResourceGroupAsync(String resourceGroupNa @ServiceMethod(returns = ReturnType.SINGLE) public Response getByResourceGroupWithResponse(String resourceGroupName, String vmName, Context context) { + final String apiVersion = "2025-04-01"; final String accept = "application/json"; - return service.getByResourceGroupSync(this.client.getEndpoint(), this.client.getApiVersion(), - this.client.getSubscriptionId(), resourceGroupName, vmName, accept, context); + return service.getByResourceGroupSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, vmName, accept, context); } /** @@ -187,10 +189,11 @@ public VirtualMachineInner getByResourceGroup(String resourceGroupName, String v @ServiceMethod(returns = ReturnType.SINGLE) private Mono>> createOrUpdateWithResponseAsync(String resourceGroupName, String vmName, VirtualMachineInner resource) { + final String apiVersion = "2025-04-01"; final String contentType = "application/json"; final String accept = "application/json"; return FluxUtil - .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), this.client.getApiVersion(), + .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), resourceGroupName, vmName, contentType, accept, resource, context)) .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); } @@ -210,10 +213,11 @@ private Mono>> createOrUpdateWithResponseAsync(String @ServiceMethod(returns = ReturnType.SINGLE) private Response createOrUpdateWithResponse(String resourceGroupName, String vmName, VirtualMachineInner resource) { + final String apiVersion = "2025-04-01"; final String contentType = "application/json"; final String accept = "application/json"; - return service.createOrUpdateSync(this.client.getEndpoint(), this.client.getApiVersion(), - this.client.getSubscriptionId(), resourceGroupName, vmName, contentType, accept, resource, Context.NONE); + return service.createOrUpdateSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, vmName, contentType, accept, resource, Context.NONE); } /** @@ -232,10 +236,11 @@ private Response createOrUpdateWithResponse(String resourceGroupName @ServiceMethod(returns = ReturnType.SINGLE) private Response createOrUpdateWithResponse(String resourceGroupName, String vmName, VirtualMachineInner resource, Context context) { + final String apiVersion = "2025-04-01"; final String contentType = "application/json"; final String accept = "application/json"; - return service.createOrUpdateSync(this.client.getEndpoint(), this.client.getApiVersion(), - this.client.getSubscriptionId(), resourceGroupName, vmName, contentType, accept, resource, context); + return service.createOrUpdateSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, vmName, contentType, accept, resource, context); } /** diff --git a/typespec-tests/src/main/java/service/multiservice/combined/CombinedBuilder.java b/typespec-tests/src/main/java/service/multiservice/combined/CombinedBuilder.java index cc8acd00b7..b89f4e03a2 100644 --- a/typespec-tests/src/main/java/service/multiservice/combined/CombinedBuilder.java +++ b/typespec-tests/src/main/java/service/multiservice/combined/CombinedBuilder.java @@ -190,24 +190,6 @@ public CombinedBuilder endpoint(String endpoint) { return this; } - /* - * Service version - */ - @Generated - private ServiceAServiceVersion serviceVersion; - - /** - * Sets Service version. - * - * @param serviceVersion the serviceVersion value. - * @return the CombinedBuilder. - */ - @Generated - public CombinedBuilder serviceVersion(ServiceAServiceVersion serviceVersion) { - this.serviceVersion = serviceVersion; - return this; - } - /* * The retry policy that will attempt to retry failed requests, if applicable. */ @@ -236,10 +218,8 @@ private CombinedImpl buildInnerClient() { this.validateClient(); HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); String localEndpoint = (endpoint != null) ? endpoint : "http://localhost:3000"; - ServiceAServiceVersion localServiceVersion - = (serviceVersion != null) ? serviceVersion : ServiceAServiceVersion.getLatest(); - CombinedImpl client = new CombinedImpl(localPipeline, JacksonAdapter.createDefaultSerializerAdapter(), - localEndpoint, localServiceVersion); + CombinedImpl client + = new CombinedImpl(localPipeline, JacksonAdapter.createDefaultSerializerAdapter(), localEndpoint); return client; } diff --git a/typespec-tests/src/main/java/service/multiservice/combined/ServiceAServiceVersion.java b/typespec-tests/src/main/java/service/multiservice/combined/ServiceAServiceVersion.java deleted file mode 100644 index a400682653..0000000000 --- a/typespec-tests/src/main/java/service/multiservice/combined/ServiceAServiceVersion.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) TypeSpec Code Generator. - -package service.multiservice.combined; - -import com.azure.core.util.ServiceVersion; - -/** - * Service version of ServiceAClient. - */ -public enum ServiceAServiceVersion implements ServiceVersion { - /** - * Enum value av1. - */ - VAV1("av1"), - - /** - * Enum value av2. - */ - VAV2("av2"); - - private final String version; - - ServiceAServiceVersion(String version) { - this.version = version; - } - - /** - * {@inheritDoc} - */ - @Override - public String getVersion() { - return this.version; - } - - /** - * Gets the latest service version supported by this client library. - * - * @return The latest {@link ServiceAServiceVersion}. - */ - public static ServiceAServiceVersion getLatest() { - return VAV2; - } -} diff --git a/typespec-tests/src/main/java/service/multiservice/combined/implementation/BarsImpl.java b/typespec-tests/src/main/java/service/multiservice/combined/implementation/BarsImpl.java index 21ae41f7af..c481c89603 100644 --- a/typespec-tests/src/main/java/service/multiservice/combined/implementation/BarsImpl.java +++ b/typespec-tests/src/main/java/service/multiservice/combined/implementation/BarsImpl.java @@ -23,7 +23,6 @@ import com.azure.core.util.Context; import com.azure.core.util.FluxUtil; import reactor.core.publisher.Mono; -import service.multiservice.combined.ServiceAServiceVersion; /** * An instance of this class provides access to all the operations defined in Bars. @@ -49,15 +48,6 @@ public final class BarsImpl { this.client = client; } - /** - * Gets Service version. - * - * @return the serviceVersion value. - */ - public ServiceAServiceVersion getServiceVersion() { - return client.getServiceVersion(); - } - /** * The interface defining all the services for CombinedBars to be used by the proxy service to perform REST calls. */ @@ -95,8 +85,9 @@ Response testSync(@HostParam("endpoint") String endpoint, @QueryParam("api */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> testWithResponseAsync(RequestOptions requestOptions) { - return FluxUtil.withContext(context -> service.test(this.client.getEndpoint(), - this.client.getServiceVersion().getVersion(), requestOptions, context)); + final String apiVersion = "bv2"; + return FluxUtil + .withContext(context -> service.test(this.client.getEndpoint(), apiVersion, requestOptions, context)); } /** @@ -111,7 +102,7 @@ public Mono> testWithResponseAsync(RequestOptions requestOptions) */ @ServiceMethod(returns = ReturnType.SINGLE) public Response testWithResponse(RequestOptions requestOptions) { - return service.testSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), requestOptions, - Context.NONE); + final String apiVersion = "bv2"; + return service.testSync(this.client.getEndpoint(), apiVersion, requestOptions, Context.NONE); } } diff --git a/typespec-tests/src/main/java/service/multiservice/combined/implementation/CombinedImpl.java b/typespec-tests/src/main/java/service/multiservice/combined/implementation/CombinedImpl.java index 8c18060258..d524e6a1b3 100644 --- a/typespec-tests/src/main/java/service/multiservice/combined/implementation/CombinedImpl.java +++ b/typespec-tests/src/main/java/service/multiservice/combined/implementation/CombinedImpl.java @@ -10,7 +10,6 @@ import com.azure.core.http.policy.UserAgentPolicy; import com.azure.core.util.serializer.JacksonAdapter; import com.azure.core.util.serializer.SerializerAdapter; -import service.multiservice.combined.ServiceAServiceVersion; /** * Initializes a new instance of the Combined type. @@ -30,20 +29,6 @@ public String getEndpoint() { return this.endpoint; } - /** - * Service version. - */ - private final ServiceAServiceVersion serviceVersion; - - /** - * Gets Service version. - * - * @return the serviceVersion value. - */ - public ServiceAServiceVersion getServiceVersion() { - return this.serviceVersion; - } - /** * The HTTP pipeline to send requests through. */ @@ -104,11 +89,10 @@ public BarsImpl getBars() { * Initializes an instance of Combined client. * * @param endpoint Service host. - * @param serviceVersion Service version. */ - public CombinedImpl(String endpoint, ServiceAServiceVersion serviceVersion) { + public CombinedImpl(String endpoint) { this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(), - JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion); + JacksonAdapter.createDefaultSerializerAdapter(), endpoint); } /** @@ -116,10 +100,9 @@ public CombinedImpl(String endpoint, ServiceAServiceVersion serviceVersion) { * * @param httpPipeline The HTTP pipeline to send requests through. * @param endpoint Service host. - * @param serviceVersion Service version. */ - public CombinedImpl(HttpPipeline httpPipeline, String endpoint, ServiceAServiceVersion serviceVersion) { - this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion); + public CombinedImpl(HttpPipeline httpPipeline, String endpoint) { + this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint); } /** @@ -128,14 +111,11 @@ public CombinedImpl(HttpPipeline httpPipeline, String endpoint, ServiceAServiceV * @param httpPipeline The HTTP pipeline to send requests through. * @param serializerAdapter The serializer to serialize an object into a string. * @param endpoint Service host. - * @param serviceVersion Service version. */ - public CombinedImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint, - ServiceAServiceVersion serviceVersion) { + public CombinedImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint) { this.httpPipeline = httpPipeline; this.serializerAdapter = serializerAdapter; this.endpoint = endpoint; - this.serviceVersion = serviceVersion; this.foos = new FoosImpl(this); this.bars = new BarsImpl(this); } diff --git a/typespec-tests/src/main/java/service/multiservice/combined/implementation/FoosImpl.java b/typespec-tests/src/main/java/service/multiservice/combined/implementation/FoosImpl.java index 59071060d4..fe46738155 100644 --- a/typespec-tests/src/main/java/service/multiservice/combined/implementation/FoosImpl.java +++ b/typespec-tests/src/main/java/service/multiservice/combined/implementation/FoosImpl.java @@ -23,7 +23,6 @@ import com.azure.core.util.Context; import com.azure.core.util.FluxUtil; import reactor.core.publisher.Mono; -import service.multiservice.combined.ServiceAServiceVersion; /** * An instance of this class provides access to all the operations defined in Foos. @@ -49,15 +48,6 @@ public final class FoosImpl { this.client = client; } - /** - * Gets Service version. - * - * @return the serviceVersion value. - */ - public ServiceAServiceVersion getServiceVersion() { - return client.getServiceVersion(); - } - /** * The interface defining all the services for CombinedFoos to be used by the proxy service to perform REST calls. */ @@ -95,8 +85,9 @@ Response testSync(@HostParam("endpoint") String endpoint, @QueryParam("api */ @ServiceMethod(returns = ReturnType.SINGLE) public Mono> testWithResponseAsync(RequestOptions requestOptions) { - return FluxUtil.withContext(context -> service.test(this.client.getEndpoint(), - this.client.getServiceVersion().getVersion(), requestOptions, context)); + final String apiVersion = "av2"; + return FluxUtil + .withContext(context -> service.test(this.client.getEndpoint(), apiVersion, requestOptions, context)); } /** @@ -111,7 +102,7 @@ public Mono> testWithResponseAsync(RequestOptions requestOptions) */ @ServiceMethod(returns = ReturnType.SINGLE) public Response testWithResponse(RequestOptions requestOptions) { - return service.testSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), requestOptions, - Context.NONE); + final String apiVersion = "av2"; + return service.testSync(this.client.getEndpoint(), apiVersion, requestOptions, Context.NONE); } } diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/ArmLegacyManager.java b/typespec-tests/src/main/java/tsptest/armlegacy/ArmLegacyManager.java new file mode 100644 index 0000000000..234c70b7d1 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/ArmLegacyManager.java @@ -0,0 +1,282 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armlegacy; + +import com.azure.core.credential.TokenCredential; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; +import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.management.profile.AzureProfile; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.logging.ClientLogger; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; +import tsptest.armlegacy.fluent.ArmLegacyClient; +import tsptest.armlegacy.implementation.ArmLegacyClientBuilder; +import tsptest.armlegacy.implementation.SkusImpl; +import tsptest.armlegacy.models.Skus; + +/** + * Entry point to ArmLegacyManager. + * Arm Resource Provider management API. + */ +public final class ArmLegacyManager { + private Skus skus; + + private final ArmLegacyClient clientObject; + + private ArmLegacyManager(HttpPipeline httpPipeline, AzureProfile profile, Duration defaultPollInterval) { + Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + this.clientObject = new ArmLegacyClientBuilder().pipeline(httpPipeline) + .endpoint(profile.getEnvironment().getResourceManagerEndpoint()) + .subscriptionId(profile.getSubscriptionId()) + .defaultPollInterval(defaultPollInterval) + .buildClient(); + } + + /** + * Creates an instance of ArmLegacy service API entry point. + * + * @param credential the credential to use. + * @param profile the Azure profile for client. + * @return the ArmLegacy service API instance. + */ + public static ArmLegacyManager authenticate(TokenCredential credential, AzureProfile profile) { + Objects.requireNonNull(credential, "'credential' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + return configure().authenticate(credential, profile); + } + + /** + * Creates an instance of ArmLegacy service API entry point. + * + * @param httpPipeline the {@link HttpPipeline} configured with Azure authentication credential. + * @param profile the Azure profile for client. + * @return the ArmLegacy service API instance. + */ + public static ArmLegacyManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) { + Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + return new ArmLegacyManager(httpPipeline, profile, null); + } + + /** + * Gets a Configurable instance that can be used to create ArmLegacyManager with optional configuration. + * + * @return the Configurable instance allowing configurations. + */ + public static Configurable configure() { + return new ArmLegacyManager.Configurable(); + } + + /** + * The Configurable allowing configurations to be set. + */ + public static final class Configurable { + private static final ClientLogger LOGGER = new ClientLogger(Configurable.class); + private static final String SDK_VERSION = "version"; + private static final Map PROPERTIES + = CoreUtils.getProperties("azure-resourcemanager-armlegacy-generated.properties"); + + private HttpClient httpClient; + private HttpLogOptions httpLogOptions; + private final List policies = new ArrayList<>(); + private final List scopes = new ArrayList<>(); + private RetryPolicy retryPolicy; + private RetryOptions retryOptions; + private Duration defaultPollInterval; + + private Configurable() { + } + + /** + * Sets the http client. + * + * @param httpClient the HTTP client. + * @return the configurable object itself. + */ + public Configurable withHttpClient(HttpClient httpClient) { + this.httpClient = Objects.requireNonNull(httpClient, "'httpClient' cannot be null."); + return this; + } + + /** + * Sets the logging options to the HTTP pipeline. + * + * @param httpLogOptions the HTTP log options. + * @return the configurable object itself. + */ + public Configurable withLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = Objects.requireNonNull(httpLogOptions, "'httpLogOptions' cannot be null."); + return this; + } + + /** + * Adds the pipeline policy to the HTTP pipeline. + * + * @param policy the HTTP pipeline policy. + * @return the configurable object itself. + */ + public Configurable withPolicy(HttpPipelinePolicy policy) { + this.policies.add(Objects.requireNonNull(policy, "'policy' cannot be null.")); + return this; + } + + /** + * Adds the scope to permission sets. + * + * @param scope the scope. + * @return the configurable object itself. + */ + public Configurable withScope(String scope) { + this.scopes.add(Objects.requireNonNull(scope, "'scope' cannot be null.")); + return this; + } + + /** + * Sets the retry policy to the HTTP pipeline. + * + * @param retryPolicy the HTTP pipeline retry policy. + * @return the configurable object itself. + */ + public Configurable withRetryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = Objects.requireNonNull(retryPolicy, "'retryPolicy' cannot be null."); + return this; + } + + /** + * Sets the retry options for the HTTP pipeline retry policy. + *

+ * This setting has no effect, if retry policy is set via {@link #withRetryPolicy(RetryPolicy)}. + * + * @param retryOptions the retry options for the HTTP pipeline retry policy. + * @return the configurable object itself. + */ + public Configurable withRetryOptions(RetryOptions retryOptions) { + this.retryOptions = Objects.requireNonNull(retryOptions, "'retryOptions' cannot be null."); + return this; + } + + /** + * Sets the default poll interval, used when service does not provide "Retry-After" header. + * + * @param defaultPollInterval the default poll interval. + * @return the configurable object itself. + */ + public Configurable withDefaultPollInterval(Duration defaultPollInterval) { + this.defaultPollInterval + = Objects.requireNonNull(defaultPollInterval, "'defaultPollInterval' cannot be null."); + if (this.defaultPollInterval.isNegative()) { + throw LOGGER + .logExceptionAsError(new IllegalArgumentException("'defaultPollInterval' cannot be negative")); + } + return this; + } + + /** + * Creates an instance of ArmLegacy service API entry point. + * + * @param credential the credential to use. + * @param profile the Azure profile for client. + * @return the ArmLegacy service API instance. + */ + public ArmLegacyManager authenticate(TokenCredential credential, AzureProfile profile) { + Objects.requireNonNull(credential, "'credential' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + + String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); + + StringBuilder userAgentBuilder = new StringBuilder(); + userAgentBuilder.append("azsdk-java") + .append("-") + .append("tsptest.armlegacy") + .append("/") + .append(clientVersion); + if (!Configuration.getGlobalConfiguration().get("AZURE_TELEMETRY_DISABLED", false)) { + userAgentBuilder.append(" (") + .append(Configuration.getGlobalConfiguration().get("java.version")) + .append("; ") + .append(Configuration.getGlobalConfiguration().get("os.name")) + .append("; ") + .append(Configuration.getGlobalConfiguration().get("os.version")) + .append("; auto-generated)"); + } else { + userAgentBuilder.append(" (auto-generated)"); + } + + if (scopes.isEmpty()) { + scopes.add(profile.getEnvironment().getManagementEndpoint() + "/.default"); + } + if (retryPolicy == null) { + if (retryOptions != null) { + retryPolicy = new RetryPolicy(retryOptions); + } else { + retryPolicy = new RetryPolicy("Retry-After", ChronoUnit.SECONDS); + } + } + List policies = new ArrayList<>(); + policies.add(new UserAgentPolicy(userAgentBuilder.toString())); + policies.add(new AddHeadersFromContextPolicy()); + policies.add(new RequestIdPolicy()); + policies.addAll(this.policies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .collect(Collectors.toList())); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(retryPolicy); + policies.add(new AddDatePolicy()); + policies.add(new BearerTokenAuthenticationPolicy(credential, scopes.toArray(new String[0]))); + policies.addAll(this.policies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .collect(Collectors.toList())); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(httpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(httpClient) + .policies(policies.toArray(new HttpPipelinePolicy[0])) + .build(); + return new ArmLegacyManager(httpPipeline, profile, defaultPollInterval); + } + } + + /** + * Gets the resource collection API of Skus. It manages SkuResource. + * + * @return Resource collection API of Skus. + */ + public Skus skus() { + if (this.skus == null) { + this.skus = new SkusImpl(clientObject.getSkus(), this); + } + return skus; + } + + /** + * Gets wrapped service client ArmLegacyClient providing direct access to the underlying auto-generated API + * implementation, based on Azure REST API. + * + * @return Wrapped service client ArmLegacyClient. + */ + public ArmLegacyClient serviceClient() { + return this.clientObject; + } +} diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/fluent/ArmLegacyClient.java b/typespec-tests/src/main/java/tsptest/armlegacy/fluent/ArmLegacyClient.java new file mode 100644 index 0000000000..f33b4a5b34 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/fluent/ArmLegacyClient.java @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armlegacy.fluent; + +import com.azure.core.http.HttpPipeline; +import java.time.Duration; + +/** + * The interface for ArmLegacyClient class. + */ +public interface ArmLegacyClient { + /** + * Gets Service host. + * + * @return the endpoint value. + */ + String getEndpoint(); + + /** + * Gets Version parameter. + * + * @return the apiVersion value. + */ + String getApiVersion(); + + /** + * Gets The ID of the target subscription. The value must be an UUID. + * + * @return the subscriptionId value. + */ + String getSubscriptionId(); + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + HttpPipeline getHttpPipeline(); + + /** + * Gets The default poll interval for long-running operation. + * + * @return the defaultPollInterval value. + */ + Duration getDefaultPollInterval(); + + /** + * Gets the SkusClient object to access its operations. + * + * @return the SkusClient object. + */ + SkusClient getSkus(); +} diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/fluent/SkusClient.java b/typespec-tests/src/main/java/tsptest/armlegacy/fluent/SkusClient.java new file mode 100644 index 0000000000..26a5b4a17e --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/fluent/SkusClient.java @@ -0,0 +1,207 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armlegacy.fluent; + +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; +import tsptest.armlegacy.fluent.models.SkuResourceInner; + +/** + * An instance of this class provides access to all the operations defined in SkusClient. + */ +public interface SkusClient { + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response getNestedWithResponse(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku, Context context); + + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + SkuResourceInner getNested(String providerNamespace, String resourceType, String nestedResourceTypeFirst, + String sku); + + /** + * Create a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete proxy resource types can be created by aliasing this type using a specific property type along + * with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response createNestedWithResponse(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku, SkuResourceInner resource, Context context); + + /** + * Create a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete proxy resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + SkuResourceInner createNested(String providerNamespace, String resourceType, String nestedResourceTypeFirst, + String sku, SkuResourceInner resource); + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response deleteNestedWithResponse(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku, Context context); + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + void deleteNested(String providerNamespace, String resourceType, String nestedResourceTypeFirst, String sku); + + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response getRootWithResponse(String providerNamespace, String resourceType, String sku, + Context context); + + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + SkuResourceInner getRoot(String providerNamespace, String resourceType, String sku); + + /** + * Create a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete proxy resource types can be created by aliasing this type using a specific property type along + * with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response createRootWithResponse(String providerNamespace, String resourceType, String sku, + SkuResourceInner resource, Context context); + + /** + * Create a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete proxy resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + SkuResourceInner createRoot(String providerNamespace, String resourceType, String sku, SkuResourceInner resource); + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response deleteRootWithResponse(String providerNamespace, String resourceType, String sku, Context context); + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + void deleteRoot(String providerNamespace, String resourceType, String sku); +} diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/fluent/models/SkuResourceInner.java b/typespec-tests/src/main/java/tsptest/armlegacy/fluent/models/SkuResourceInner.java new file mode 100644 index 0000000000..21e966d91e --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/fluent/models/SkuResourceInner.java @@ -0,0 +1,155 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armlegacy.fluent.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.management.ProxyResource; +import com.azure.core.management.SystemData; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import tsptest.armlegacy.models.ResourceTypeSku; + +/** + * Concrete proxy resource types can be created by aliasing this type using a specific property type. + */ +@Fluent +public final class SkuResourceInner extends ProxyResource { + /* + * The resource-specific properties for this resource. + */ + private ResourceTypeSku properties; + + /* + * Azure Resource Manager metadata containing createdBy and modifiedBy information. + */ + private SystemData systemData; + + /* + * The type of the resource. + */ + private String type; + + /* + * The name of the resource. + */ + private String name; + + /* + * Fully qualified resource Id for the resource. + */ + private String id; + + /** + * Creates an instance of SkuResourceInner class. + */ + public SkuResourceInner() { + } + + /** + * Get the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + public ResourceTypeSku properties() { + return this.properties; + } + + /** + * Set the properties property: The resource-specific properties for this resource. + * + * @param properties the properties value to set. + * @return the SkuResourceInner object itself. + */ + public SkuResourceInner withProperties(ResourceTypeSku properties) { + this.properties = properties; + return this; + } + + /** + * Get the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + public SystemData systemData() { + return this.systemData; + } + + /** + * Get the type property: The type of the resource. + * + * @return the type value. + */ + @Override + public String type() { + return this.type; + } + + /** + * Get the name property: The name of the resource. + * + * @return the name value. + */ + @Override + public String name() { + return this.name; + } + + /** + * Get the id property: Fully qualified resource Id for the resource. + * + * @return the id value. + */ + @Override + public String id() { + return this.id; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("properties", this.properties); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SkuResourceInner from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SkuResourceInner if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the SkuResourceInner. + */ + public static SkuResourceInner fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + SkuResourceInner deserializedSkuResourceInner = new SkuResourceInner(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedSkuResourceInner.id = reader.getString(); + } else if ("name".equals(fieldName)) { + deserializedSkuResourceInner.name = reader.getString(); + } else if ("type".equals(fieldName)) { + deserializedSkuResourceInner.type = reader.getString(); + } else if ("properties".equals(fieldName)) { + deserializedSkuResourceInner.properties = ResourceTypeSku.fromJson(reader); + } else if ("systemData".equals(fieldName)) { + deserializedSkuResourceInner.systemData = SystemData.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedSkuResourceInner; + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/fluent/models/package-info.java b/typespec-tests/src/main/java/tsptest/armlegacy/fluent/models/package-info.java new file mode 100644 index 0000000000..943d736868 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/fluent/models/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the inner data models for ArmLegacy. + * Arm Resource Provider management API. + */ +package tsptest.armlegacy.fluent.models; diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/fluent/package-info.java b/typespec-tests/src/main/java/tsptest/armlegacy/fluent/package-info.java new file mode 100644 index 0000000000..f1f346a9dd --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/fluent/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the service clients for ArmLegacy. + * Arm Resource Provider management API. + */ +package tsptest.armlegacy.fluent; diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/implementation/ArmLegacyClientBuilder.java b/typespec-tests/src/main/java/tsptest/armlegacy/implementation/ArmLegacyClientBuilder.java new file mode 100644 index 0000000000..cdf55e7013 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/implementation/ArmLegacyClientBuilder.java @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armlegacy.implementation; + +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.serializer.SerializerFactory; +import com.azure.core.util.serializer.SerializerAdapter; +import java.time.Duration; + +/** + * A builder for creating a new instance of the ArmLegacyClientImpl type. + */ +@ServiceClientBuilder(serviceClients = { ArmLegacyClientImpl.class }) +public final class ArmLegacyClientBuilder { + /* + * Service host + */ + private String endpoint; + + /** + * Sets Service host. + * + * @param endpoint the endpoint value. + * @return the ArmLegacyClientBuilder. + */ + public ArmLegacyClientBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * The ID of the target subscription. The value must be an UUID. + */ + private String subscriptionId; + + /** + * Sets The ID of the target subscription. The value must be an UUID. + * + * @param subscriptionId the subscriptionId value. + * @return the ArmLegacyClientBuilder. + */ + public ArmLegacyClientBuilder subscriptionId(String subscriptionId) { + this.subscriptionId = subscriptionId; + return this; + } + + /* + * The environment to connect to + */ + private AzureEnvironment environment; + + /** + * Sets The environment to connect to. + * + * @param environment the environment value. + * @return the ArmLegacyClientBuilder. + */ + public ArmLegacyClientBuilder environment(AzureEnvironment environment) { + this.environment = environment; + return this; + } + + /* + * The HTTP pipeline to send requests through + */ + private HttpPipeline pipeline; + + /** + * Sets The HTTP pipeline to send requests through. + * + * @param pipeline the pipeline value. + * @return the ArmLegacyClientBuilder. + */ + public ArmLegacyClientBuilder pipeline(HttpPipeline pipeline) { + this.pipeline = pipeline; + return this; + } + + /* + * The default poll interval for long-running operation + */ + private Duration defaultPollInterval; + + /** + * Sets The default poll interval for long-running operation. + * + * @param defaultPollInterval the defaultPollInterval value. + * @return the ArmLegacyClientBuilder. + */ + public ArmLegacyClientBuilder defaultPollInterval(Duration defaultPollInterval) { + this.defaultPollInterval = defaultPollInterval; + return this; + } + + /* + * The serializer to serialize an object into a string + */ + private SerializerAdapter serializerAdapter; + + /** + * Sets The serializer to serialize an object into a string. + * + * @param serializerAdapter the serializerAdapter value. + * @return the ArmLegacyClientBuilder. + */ + public ArmLegacyClientBuilder serializerAdapter(SerializerAdapter serializerAdapter) { + this.serializerAdapter = serializerAdapter; + return this; + } + + /** + * Builds an instance of ArmLegacyClientImpl with the provided parameters. + * + * @return an instance of ArmLegacyClientImpl. + */ + public ArmLegacyClientImpl buildClient() { + String localEndpoint = (endpoint != null) ? endpoint : "https://management.azure.com"; + AzureEnvironment localEnvironment = (environment != null) ? environment : AzureEnvironment.AZURE; + HttpPipeline localPipeline = (pipeline != null) + ? pipeline + : new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(); + Duration localDefaultPollInterval + = (defaultPollInterval != null) ? defaultPollInterval : Duration.ofSeconds(30); + SerializerAdapter localSerializerAdapter = (serializerAdapter != null) + ? serializerAdapter + : SerializerFactory.createDefaultManagementSerializerAdapter(); + ArmLegacyClientImpl client = new ArmLegacyClientImpl(localPipeline, localSerializerAdapter, + localDefaultPollInterval, localEnvironment, localEndpoint, this.subscriptionId); + return client; + } +} diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/implementation/ArmLegacyClientImpl.java b/typespec-tests/src/main/java/tsptest/armlegacy/implementation/ArmLegacyClientImpl.java new file mode 100644 index 0000000000..032d64f27d --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/implementation/ArmLegacyClientImpl.java @@ -0,0 +1,308 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armlegacy.implementation; + +import com.azure.core.annotation.ServiceClient; +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpResponse; +import com.azure.core.http.rest.Response; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.exception.ManagementError; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.polling.PollResult; +import com.azure.core.management.polling.PollerFactory; +import com.azure.core.management.polling.SyncPollerFactory; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.polling.AsyncPollResponse; +import com.azure.core.util.polling.LongRunningOperationStatus; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.polling.SyncPoller; +import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.core.util.serializer.SerializerEncoding; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.time.Duration; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; +import tsptest.armlegacy.fluent.ArmLegacyClient; +import tsptest.armlegacy.fluent.SkusClient; + +/** + * Initializes a new instance of the ArmLegacyClientImpl type. + */ +@ServiceClient(builder = ArmLegacyClientBuilder.class) +public final class ArmLegacyClientImpl implements ArmLegacyClient { + /** + * Service host. + */ + private final String endpoint; + + /** + * Gets Service host. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** + * Version parameter. + */ + private final String apiVersion; + + /** + * Gets Version parameter. + * + * @return the apiVersion value. + */ + public String getApiVersion() { + return this.apiVersion; + } + + /** + * The ID of the target subscription. The value must be an UUID. + */ + private final String subscriptionId; + + /** + * Gets The ID of the target subscription. The value must be an UUID. + * + * @return the subscriptionId value. + */ + public String getSubscriptionId() { + return this.subscriptionId; + } + + /** + * The HTTP pipeline to send requests through. + */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The serializer to serialize an object into a string. + */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * The default poll interval for long-running operation. + */ + private final Duration defaultPollInterval; + + /** + * Gets The default poll interval for long-running operation. + * + * @return the defaultPollInterval value. + */ + public Duration getDefaultPollInterval() { + return this.defaultPollInterval; + } + + /** + * The SkusClient object to access its operations. + */ + private final SkusClient skus; + + /** + * Gets the SkusClient object to access its operations. + * + * @return the SkusClient object. + */ + public SkusClient getSkus() { + return this.skus; + } + + /** + * Initializes an instance of ArmLegacyClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param defaultPollInterval The default poll interval for long-running operation. + * @param environment The Azure environment. + * @param endpoint Service host. + * @param subscriptionId The ID of the target subscription. The value must be an UUID. + */ + ArmLegacyClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, Duration defaultPollInterval, + AzureEnvironment environment, String endpoint, String subscriptionId) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.defaultPollInterval = defaultPollInterval; + this.endpoint = endpoint; + this.subscriptionId = subscriptionId; + this.apiVersion = "2024-12-01"; + this.skus = new SkusClientImpl(this); + } + + /** + * Gets default client context. + * + * @return the default client context. + */ + public Context getContext() { + return Context.NONE; + } + + /** + * Merges default client context with provided context. + * + * @param context the context to be merged with default client context. + * @return the merged context. + */ + public Context mergeContext(Context context) { + return CoreUtils.mergeContexts(this.getContext(), context); + } + + /** + * Gets long running operation result. + * + * @param activationResponse the response of activation operation. + * @param httpPipeline the http pipeline. + * @param pollResultType type of poll result. + * @param finalResultType type of final result. + * @param context the context shared by all requests. + * @param type of poll result. + * @param type of final result. + * @return poller flux for poll result and final result. + */ + public PollerFlux, U> getLroResult(Mono>> activationResponse, + HttpPipeline httpPipeline, Type pollResultType, Type finalResultType, Context context) { + return PollerFactory.create(serializerAdapter, httpPipeline, pollResultType, finalResultType, + defaultPollInterval, activationResponse, context); + } + + /** + * Gets long running operation result. + * + * @param activationResponse the response of activation operation. + * @param pollResultType type of poll result. + * @param finalResultType type of final result. + * @param context the context shared by all requests. + * @param type of poll result. + * @param type of final result. + * @return SyncPoller for poll result and final result. + */ + public SyncPoller, U> getLroResult(Response activationResponse, + Type pollResultType, Type finalResultType, Context context) { + return SyncPollerFactory.create(serializerAdapter, httpPipeline, pollResultType, finalResultType, + defaultPollInterval, () -> activationResponse, context); + } + + /** + * Gets the final result, or an error, based on last async poll response. + * + * @param response the last async poll response. + * @param type of poll result. + * @param type of final result. + * @return the final result, or an error. + */ + public Mono getLroFinalResultOrError(AsyncPollResponse, U> response) { + if (response.getStatus() != LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) { + String errorMessage; + ManagementError managementError = null; + HttpResponse errorResponse = null; + PollResult.Error lroError = response.getValue().getError(); + if (lroError != null) { + errorResponse = new HttpResponseImpl(lroError.getResponseStatusCode(), lroError.getResponseHeaders(), + lroError.getResponseBody()); + + errorMessage = response.getValue().getError().getMessage(); + String errorBody = response.getValue().getError().getResponseBody(); + if (errorBody != null) { + // try to deserialize error body to ManagementError + try { + managementError = this.getSerializerAdapter() + .deserialize(errorBody, ManagementError.class, SerializerEncoding.JSON); + if (managementError.getCode() == null || managementError.getMessage() == null) { + managementError = null; + } + } catch (IOException | RuntimeException ioe) { + LOGGER.logThrowableAsWarning(ioe); + } + } + } else { + // fallback to default error message + errorMessage = "Long running operation failed."; + } + if (managementError == null) { + // fallback to default ManagementError + managementError = new ManagementError(response.getStatus().toString(), errorMessage); + } + return Mono.error(new ManagementException(errorMessage, errorResponse, managementError)); + } else { + return response.getFinalResult(); + } + } + + private static final class HttpResponseImpl extends HttpResponse { + private final int statusCode; + + private final byte[] responseBody; + + private final HttpHeaders httpHeaders; + + HttpResponseImpl(int statusCode, HttpHeaders httpHeaders, String responseBody) { + super(null); + this.statusCode = statusCode; + this.httpHeaders = httpHeaders; + this.responseBody = responseBody == null ? null : responseBody.getBytes(StandardCharsets.UTF_8); + } + + public int getStatusCode() { + return statusCode; + } + + public String getHeaderValue(String s) { + return httpHeaders.getValue(HttpHeaderName.fromString(s)); + } + + public HttpHeaders getHeaders() { + return httpHeaders; + } + + public Flux getBody() { + return Flux.just(ByteBuffer.wrap(responseBody)); + } + + public Mono getBodyAsByteArray() { + return Mono.just(responseBody); + } + + public Mono getBodyAsString() { + return Mono.just(new String(responseBody, StandardCharsets.UTF_8)); + } + + public Mono getBodyAsString(Charset charset) { + return Mono.just(new String(responseBody, charset)); + } + } + + private static final ClientLogger LOGGER = new ClientLogger(ArmLegacyClientImpl.class); +} diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/implementation/ResourceManagerUtils.java b/typespec-tests/src/main/java/tsptest/armlegacy/implementation/ResourceManagerUtils.java new file mode 100644 index 0000000000..96b4a0a5a0 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/implementation/ResourceManagerUtils.java @@ -0,0 +1,195 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armlegacy.implementation; + +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.util.CoreUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import reactor.core.publisher.Flux; + +final class ResourceManagerUtils { + private ResourceManagerUtils() { + } + + static String getValueFromIdByName(String id, String name) { + if (id == null) { + return null; + } + Iterator itr = Arrays.stream(id.split("/")).iterator(); + while (itr.hasNext()) { + String part = itr.next(); + if (part != null && !part.trim().isEmpty()) { + if (part.equalsIgnoreCase(name)) { + if (itr.hasNext()) { + return itr.next(); + } else { + return null; + } + } + } + } + return null; + } + + static String getValueFromIdByParameterName(String id, String pathTemplate, String parameterName) { + if (id == null || pathTemplate == null) { + return null; + } + String parameterNameParentheses = "{" + parameterName + "}"; + List idSegmentsReverted = Arrays.asList(id.split("/")); + List pathSegments = Arrays.asList(pathTemplate.split("/")); + Collections.reverse(idSegmentsReverted); + Iterator idItrReverted = idSegmentsReverted.iterator(); + int pathIndex = pathSegments.size(); + while (idItrReverted.hasNext() && pathIndex > 0) { + String idSegment = idItrReverted.next(); + String pathSegment = pathSegments.get(--pathIndex); + if (!CoreUtils.isNullOrEmpty(idSegment) && !CoreUtils.isNullOrEmpty(pathSegment)) { + if (pathSegment.equalsIgnoreCase(parameterNameParentheses)) { + if (pathIndex == 0 || (pathIndex == 1 && pathSegments.get(0).isEmpty())) { + List segments = new ArrayList<>(); + segments.add(idSegment); + idItrReverted.forEachRemaining(segments::add); + Collections.reverse(segments); + if (!segments.isEmpty() && segments.get(0).isEmpty()) { + segments.remove(0); + } + return String.join("/", segments); + } else { + return idSegment; + } + } + } + } + return null; + } + + static PagedIterable mapPage(PagedIterable pageIterable, Function mapper) { + return new PagedIterableImpl<>(pageIterable, mapper); + } + + private static final class PagedIterableImpl extends PagedIterable { + + private final PagedIterable pagedIterable; + private final Function mapper; + private final Function, PagedResponse> pageMapper; + + private PagedIterableImpl(PagedIterable pagedIterable, Function mapper) { + super(PagedFlux.create(() -> (continuationToken, pageSize) -> Flux + .fromStream(pagedIterable.streamByPage().map(getPageMapper(mapper))))); + this.pagedIterable = pagedIterable; + this.mapper = mapper; + this.pageMapper = getPageMapper(mapper); + } + + private static Function, PagedResponse> getPageMapper(Function mapper) { + return page -> new PagedResponseBase(page.getRequest(), page.getStatusCode(), page.getHeaders(), + page.getElements().stream().map(mapper).collect(Collectors.toList()), page.getContinuationToken(), + null); + } + + @Override + public Stream stream() { + return pagedIterable.stream().map(mapper); + } + + @Override + public Stream> streamByPage() { + return pagedIterable.streamByPage().map(pageMapper); + } + + @Override + public Stream> streamByPage(String continuationToken) { + return pagedIterable.streamByPage(continuationToken).map(pageMapper); + } + + @Override + public Stream> streamByPage(int preferredPageSize) { + return pagedIterable.streamByPage(preferredPageSize).map(pageMapper); + } + + @Override + public Stream> streamByPage(String continuationToken, int preferredPageSize) { + return pagedIterable.streamByPage(continuationToken, preferredPageSize).map(pageMapper); + } + + @Override + public Iterator iterator() { + return new IteratorImpl<>(pagedIterable.iterator(), mapper); + } + + @Override + public Iterable> iterableByPage() { + return new IterableImpl<>(pagedIterable.iterableByPage(), pageMapper); + } + + @Override + public Iterable> iterableByPage(String continuationToken) { + return new IterableImpl<>(pagedIterable.iterableByPage(continuationToken), pageMapper); + } + + @Override + public Iterable> iterableByPage(int preferredPageSize) { + return new IterableImpl<>(pagedIterable.iterableByPage(preferredPageSize), pageMapper); + } + + @Override + public Iterable> iterableByPage(String continuationToken, int preferredPageSize) { + return new IterableImpl<>(pagedIterable.iterableByPage(continuationToken, preferredPageSize), pageMapper); + } + } + + private static final class IteratorImpl implements Iterator { + + private final Iterator iterator; + private final Function mapper; + + private IteratorImpl(Iterator iterator, Function mapper) { + this.iterator = iterator; + this.mapper = mapper; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public S next() { + return mapper.apply(iterator.next()); + } + + @Override + public void remove() { + iterator.remove(); + } + } + + private static final class IterableImpl implements Iterable { + + private final Iterable iterable; + private final Function mapper; + + private IterableImpl(Iterable iterable, Function mapper) { + this.iterable = iterable; + this.mapper = mapper; + } + + @Override + public Iterator iterator() { + return new IteratorImpl<>(iterable.iterator(), mapper); + } + } +} diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/implementation/SkuResourceImpl.java b/typespec-tests/src/main/java/tsptest/armlegacy/implementation/SkuResourceImpl.java new file mode 100644 index 0000000000..c0d6172ee3 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/implementation/SkuResourceImpl.java @@ -0,0 +1,105 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armlegacy.implementation; + +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; +import tsptest.armlegacy.fluent.models.SkuResourceInner; +import tsptest.armlegacy.models.ResourceTypeSku; +import tsptest.armlegacy.models.SkuResource; + +public final class SkuResourceImpl implements SkuResource, SkuResource.Definition { + private SkuResourceInner innerObject; + + private final tsptest.armlegacy.ArmLegacyManager serviceManager; + + SkuResourceImpl(SkuResourceInner innerObject, tsptest.armlegacy.ArmLegacyManager serviceManager) { + this.innerObject = innerObject; + this.serviceManager = serviceManager; + } + + public String id() { + return this.innerModel().id(); + } + + public String name() { + return this.innerModel().name(); + } + + public String type() { + return this.innerModel().type(); + } + + public ResourceTypeSku properties() { + return this.innerModel().properties(); + } + + public SystemData systemData() { + return this.innerModel().systemData(); + } + + public SkuResourceInner innerModel() { + return this.innerObject; + } + + private tsptest.armlegacy.ArmLegacyManager manager() { + return this.serviceManager; + } + + private String providerNamespace; + + private String resourceType; + + private String sku; + + public SkuResourceImpl withExistingResourcetypeRegistration(String providerNamespace, String resourceType) { + this.providerNamespace = providerNamespace; + this.resourceType = resourceType; + return this; + } + + public SkuResource create() { + this.innerObject = serviceManager.serviceClient() + .getSkus() + .createRootWithResponse(providerNamespace, resourceType, sku, this.innerModel(), Context.NONE) + .getValue(); + return this; + } + + public SkuResource create(Context context) { + this.innerObject = serviceManager.serviceClient() + .getSkus() + .createRootWithResponse(providerNamespace, resourceType, sku, this.innerModel(), context) + .getValue(); + return this; + } + + SkuResourceImpl(String name, tsptest.armlegacy.ArmLegacyManager serviceManager) { + this.innerObject = new SkuResourceInner(); + this.serviceManager = serviceManager; + this.sku = name; + } + + public SkuResource refresh() { + this.innerObject = serviceManager.serviceClient() + .getSkus() + .getRootWithResponse(providerNamespace, resourceType, sku, Context.NONE) + .getValue(); + return this; + } + + public SkuResource refresh(Context context) { + this.innerObject = serviceManager.serviceClient() + .getSkus() + .getRootWithResponse(providerNamespace, resourceType, sku, context) + .getValue(); + return this; + } + + public SkuResourceImpl withProperties(ResourceTypeSku properties) { + this.innerModel().withProperties(properties); + return this; + } +} diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/implementation/SkusClientImpl.java b/typespec-tests/src/main/java/tsptest/armlegacy/implementation/SkusClientImpl.java new file mode 100644 index 0000000000..094bde3847 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/implementation/SkusClientImpl.java @@ -0,0 +1,662 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armlegacy.implementation; + +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.Delete; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Headers; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Put; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; +import tsptest.armlegacy.fluent.SkusClient; +import tsptest.armlegacy.fluent.models.SkuResourceInner; + +/** + * An instance of this class provides access to all the operations defined in SkusClient. + */ +public final class SkusClientImpl implements SkusClient { + /** + * The proxy service used to perform REST calls. + */ + private final SkusService service; + + /** + * The service client containing this operation class. + */ + private final ArmLegacyClientImpl client; + + /** + * Initializes an instance of SkusClientImpl. + * + * @param client the instance of the service client containing this operation class. + */ + SkusClientImpl(ArmLegacyClientImpl client) { + this.service = RestProxy.create(SkusService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for ArmLegacyClientSkus to be used by the proxy service to perform REST + * calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "ArmLegacyClientSkus") + public interface SkusService { + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/providers/Microsoft.ThisWillBeReplaced/providerRegistrations/{providerNamespace}/resourcetypeRegistrations/{resourceType}/resourcetypeRegistrations/{nestedResourceTypeFirst}/skus/{sku}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> getNested(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("providerNamespace") String providerNamespace, @PathParam("resourceType") String resourceType, + @PathParam("nestedResourceTypeFirst") String nestedResourceTypeFirst, @PathParam("sku") String sku, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/providers/Microsoft.ThisWillBeReplaced/providerRegistrations/{providerNamespace}/resourcetypeRegistrations/{resourceType}/resourcetypeRegistrations/{nestedResourceTypeFirst}/skus/{sku}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response getNestedSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("providerNamespace") String providerNamespace, @PathParam("resourceType") String resourceType, + @PathParam("nestedResourceTypeFirst") String nestedResourceTypeFirst, @PathParam("sku") String sku, + @HeaderParam("Accept") String accept, Context context); + + @Put("/subscriptions/{subscriptionId}/providers/Microsoft.ThisWillBeReplaced/providerRegistrations/{providerNamespace}/resourcetypeRegistrations/{resourceType}/resourcetypeRegistrations/{nestedResourceTypeFirst}/skus/{sku}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> createNested(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("providerNamespace") String providerNamespace, @PathParam("resourceType") String resourceType, + @PathParam("nestedResourceTypeFirst") String nestedResourceTypeFirst, @PathParam("sku") String sku, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") SkuResourceInner resource, Context context); + + @Put("/subscriptions/{subscriptionId}/providers/Microsoft.ThisWillBeReplaced/providerRegistrations/{providerNamespace}/resourcetypeRegistrations/{resourceType}/resourcetypeRegistrations/{nestedResourceTypeFirst}/skus/{sku}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response createNestedSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("providerNamespace") String providerNamespace, @PathParam("resourceType") String resourceType, + @PathParam("nestedResourceTypeFirst") String nestedResourceTypeFirst, @PathParam("sku") String sku, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") SkuResourceInner resource, Context context); + + @Headers({ "Accept: application/json;q=0.9", "Content-Type: application/json" }) + @Delete("/subscriptions/{subscriptionId}/providers/Microsoft.ThisWillBeReplaced/providerRegistrations/{providerNamespace}/resourcetypeRegistrations/{resourceType}/resourcetypeRegistrations/{nestedResourceTypeFirst}/skus/{sku}") + @ExpectedResponses({ 200, 204 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> deleteNested(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("providerNamespace") String providerNamespace, @PathParam("resourceType") String resourceType, + @PathParam("nestedResourceTypeFirst") String nestedResourceTypeFirst, @PathParam("sku") String sku, + Context context); + + @Headers({ "Accept: application/json;q=0.9", "Content-Type: application/json" }) + @Delete("/subscriptions/{subscriptionId}/providers/Microsoft.ThisWillBeReplaced/providerRegistrations/{providerNamespace}/resourcetypeRegistrations/{resourceType}/resourcetypeRegistrations/{nestedResourceTypeFirst}/skus/{sku}") + @ExpectedResponses({ 200, 204 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response deleteNestedSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("providerNamespace") String providerNamespace, @PathParam("resourceType") String resourceType, + @PathParam("nestedResourceTypeFirst") String nestedResourceTypeFirst, @PathParam("sku") String sku, + Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/providers/Microsoft.ThisWillBeReplaced/providerRegistrations/{providerNamespace}/resourcetypeRegistrations/{resourceType}/skus/{sku}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> getRoot(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("providerNamespace") String providerNamespace, @PathParam("resourceType") String resourceType, + @PathParam("sku") String sku, @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/providers/Microsoft.ThisWillBeReplaced/providerRegistrations/{providerNamespace}/resourcetypeRegistrations/{resourceType}/skus/{sku}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response getRootSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("providerNamespace") String providerNamespace, @PathParam("resourceType") String resourceType, + @PathParam("sku") String sku, @HeaderParam("Accept") String accept, Context context); + + @Put("/subscriptions/{subscriptionId}/providers/Microsoft.ThisWillBeReplaced/providerRegistrations/{providerNamespace}/resourcetypeRegistrations/{resourceType}/skus/{sku}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> createRoot(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("providerNamespace") String providerNamespace, @PathParam("resourceType") String resourceType, + @PathParam("sku") String sku, @HeaderParam("Content-Type") String contentType, + @HeaderParam("Accept") String accept, @BodyParam("application/json") SkuResourceInner resource, + Context context); + + @Put("/subscriptions/{subscriptionId}/providers/Microsoft.ThisWillBeReplaced/providerRegistrations/{providerNamespace}/resourcetypeRegistrations/{resourceType}/skus/{sku}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response createRootSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("providerNamespace") String providerNamespace, @PathParam("resourceType") String resourceType, + @PathParam("sku") String sku, @HeaderParam("Content-Type") String contentType, + @HeaderParam("Accept") String accept, @BodyParam("application/json") SkuResourceInner resource, + Context context); + + @Headers({ "Accept: application/json;q=0.9", "Content-Type: application/json" }) + @Delete("/subscriptions/{subscriptionId}/providers/Microsoft.ThisWillBeReplaced/providerRegistrations/{providerNamespace}/resourcetypeRegistrations/{resourceType}/skus/{sku}") + @ExpectedResponses({ 200, 204 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> deleteRoot(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("providerNamespace") String providerNamespace, @PathParam("resourceType") String resourceType, + @PathParam("sku") String sku, Context context); + + @Headers({ "Accept: application/json;q=0.9", "Content-Type: application/json" }) + @Delete("/subscriptions/{subscriptionId}/providers/Microsoft.ThisWillBeReplaced/providerRegistrations/{providerNamespace}/resourcetypeRegistrations/{resourceType}/skus/{sku}") + @ExpectedResponses({ 200, 204 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response deleteRootSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("providerNamespace") String providerNamespace, @PathParam("resourceType") String resourceType, + @PathParam("sku") String sku, Context context); + } + + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> getNestedWithResponseAsync(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.getNested(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), providerNamespace, resourceType, nestedResourceTypeFirst, sku, accept, + context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono getNestedAsync(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku) { + return getNestedWithResponseAsync(providerNamespace, resourceType, nestedResourceTypeFirst, sku) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getNestedWithResponse(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku, Context context) { + final String accept = "application/json"; + return service.getNestedSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), providerNamespace, resourceType, nestedResourceTypeFirst, sku, accept, + context); + } + + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public SkuResourceInner getNested(String providerNamespace, String resourceType, String nestedResourceTypeFirst, + String sku) { + return getNestedWithResponse(providerNamespace, resourceType, nestedResourceTypeFirst, sku, Context.NONE) + .getValue(); + } + + /** + * Create a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete proxy resource types can be created by aliasing this type using a specific property type along + * with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> createNestedWithResponseAsync(String providerNamespace, + String resourceType, String nestedResourceTypeFirst, String sku, SkuResourceInner resource) { + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.createNested(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), providerNamespace, resourceType, nestedResourceTypeFirst, sku, + contentType, accept, resource, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Create a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete proxy resource types can be created by aliasing this type using a specific property type on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono createNestedAsync(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku, SkuResourceInner resource) { + return createNestedWithResponseAsync(providerNamespace, resourceType, nestedResourceTypeFirst, sku, resource) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Create a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete proxy resource types can be created by aliasing this type using a specific property type along + * with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response createNestedWithResponse(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku, SkuResourceInner resource, Context context) { + final String contentType = "application/json"; + final String accept = "application/json"; + return service.createNestedSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), providerNamespace, resourceType, nestedResourceTypeFirst, sku, contentType, + accept, resource, context); + } + + /** + * Create a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete proxy resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public SkuResourceInner createNested(String providerNamespace, String resourceType, String nestedResourceTypeFirst, + String sku, SkuResourceInner resource) { + return createNestedWithResponse(providerNamespace, resourceType, nestedResourceTypeFirst, sku, resource, + Context.NONE).getValue(); + } + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> deleteNestedWithResponseAsync(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku) { + return FluxUtil + .withContext(context -> service.deleteNested(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), providerNamespace, resourceType, nestedResourceTypeFirst, sku, + context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return A {@link Mono} that completes when a successful response is received. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono deleteNestedAsync(String providerNamespace, String resourceType, String nestedResourceTypeFirst, + String sku) { + return deleteNestedWithResponseAsync(providerNamespace, resourceType, nestedResourceTypeFirst, sku) + .flatMap(ignored -> Mono.empty()); + } + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response deleteNestedWithResponse(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku, Context context) { + return service.deleteNestedSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), providerNamespace, resourceType, nestedResourceTypeFirst, sku, context); + } + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void deleteNested(String providerNamespace, String resourceType, String nestedResourceTypeFirst, + String sku) { + deleteNestedWithResponse(providerNamespace, resourceType, nestedResourceTypeFirst, sku, Context.NONE); + } + + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> getRootWithResponseAsync(String providerNamespace, String resourceType, + String sku) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.getRoot(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), providerNamespace, resourceType, sku, accept, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono getRootAsync(String providerNamespace, String resourceType, String sku) { + return getRootWithResponseAsync(providerNamespace, resourceType, sku) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getRootWithResponse(String providerNamespace, String resourceType, String sku, + Context context) { + final String accept = "application/json"; + return service.getRootSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), providerNamespace, resourceType, sku, accept, context); + } + + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public SkuResourceInner getRoot(String providerNamespace, String resourceType, String sku) { + return getRootWithResponse(providerNamespace, resourceType, sku, Context.NONE).getValue(); + } + + /** + * Create a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete proxy resource types can be created by aliasing this type using a specific property type along + * with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> createRootWithResponseAsync(String providerNamespace, String resourceType, + String sku, SkuResourceInner resource) { + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.createRoot(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), providerNamespace, resourceType, sku, contentType, accept, resource, + context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Create a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete proxy resource types can be created by aliasing this type using a specific property type on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono createRootAsync(String providerNamespace, String resourceType, String sku, + SkuResourceInner resource) { + return createRootWithResponseAsync(providerNamespace, resourceType, sku, resource) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Create a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete proxy resource types can be created by aliasing this type using a specific property type along + * with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response createRootWithResponse(String providerNamespace, String resourceType, String sku, + SkuResourceInner resource, Context context) { + final String contentType = "application/json"; + final String accept = "application/json"; + return service.createRootSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), providerNamespace, resourceType, sku, contentType, accept, resource, + context); + } + + /** + * Create a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete proxy resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public SkuResourceInner createRoot(String providerNamespace, String resourceType, String sku, + SkuResourceInner resource) { + return createRootWithResponse(providerNamespace, resourceType, sku, resource, Context.NONE).getValue(); + } + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> deleteRootWithResponseAsync(String providerNamespace, String resourceType, + String sku) { + return FluxUtil + .withContext(context -> service.deleteRoot(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), providerNamespace, resourceType, sku, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return A {@link Mono} that completes when a successful response is received. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono deleteRootAsync(String providerNamespace, String resourceType, String sku) { + return deleteRootWithResponseAsync(providerNamespace, resourceType, sku).flatMap(ignored -> Mono.empty()); + } + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response deleteRootWithResponse(String providerNamespace, String resourceType, String sku, + Context context) { + return service.deleteRootSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), providerNamespace, resourceType, sku, context); + } + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public void deleteRoot(String providerNamespace, String resourceType, String sku) { + deleteRootWithResponse(providerNamespace, resourceType, sku, Context.NONE); + } +} diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/implementation/SkusImpl.java b/typespec-tests/src/main/java/tsptest/armlegacy/implementation/SkusImpl.java new file mode 100644 index 0000000000..99a246c7ae --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/implementation/SkusImpl.java @@ -0,0 +1,202 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armlegacy.implementation; + +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.util.Context; +import com.azure.core.util.logging.ClientLogger; +import tsptest.armlegacy.fluent.SkusClient; +import tsptest.armlegacy.fluent.models.SkuResourceInner; +import tsptest.armlegacy.models.SkuResource; +import tsptest.armlegacy.models.Skus; + +public final class SkusImpl implements Skus { + private static final ClientLogger LOGGER = new ClientLogger(SkusImpl.class); + + private final SkusClient innerClient; + + private final tsptest.armlegacy.ArmLegacyManager serviceManager; + + public SkusImpl(SkusClient innerClient, tsptest.armlegacy.ArmLegacyManager serviceManager) { + this.innerClient = innerClient; + this.serviceManager = serviceManager; + } + + public Response getNestedWithResponse(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku, Context context) { + Response inner = this.serviceClient() + .getNestedWithResponse(providerNamespace, resourceType, nestedResourceTypeFirst, sku, context); + if (inner != null) { + return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(), + new SkuResourceImpl(inner.getValue(), this.manager())); + } else { + return null; + } + } + + public SkuResource getNested(String providerNamespace, String resourceType, String nestedResourceTypeFirst, + String sku) { + SkuResourceInner inner + = this.serviceClient().getNested(providerNamespace, resourceType, nestedResourceTypeFirst, sku); + if (inner != null) { + return new SkuResourceImpl(inner, this.manager()); + } else { + return null; + } + } + + public Response createNestedWithResponse(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku, SkuResourceInner resource, Context context) { + Response inner = this.serviceClient() + .createNestedWithResponse(providerNamespace, resourceType, nestedResourceTypeFirst, sku, resource, context); + if (inner != null) { + return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(), + new SkuResourceImpl(inner.getValue(), this.manager())); + } else { + return null; + } + } + + public SkuResource createNested(String providerNamespace, String resourceType, String nestedResourceTypeFirst, + String sku, SkuResourceInner resource) { + SkuResourceInner inner = this.serviceClient() + .createNested(providerNamespace, resourceType, nestedResourceTypeFirst, sku, resource); + if (inner != null) { + return new SkuResourceImpl(inner, this.manager()); + } else { + return null; + } + } + + public Response deleteNestedWithResponse(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku, Context context) { + return this.serviceClient() + .deleteNestedWithResponse(providerNamespace, resourceType, nestedResourceTypeFirst, sku, context); + } + + public void deleteNested(String providerNamespace, String resourceType, String nestedResourceTypeFirst, + String sku) { + this.serviceClient().deleteNested(providerNamespace, resourceType, nestedResourceTypeFirst, sku); + } + + public Response getRootWithResponse(String providerNamespace, String resourceType, String sku, + Context context) { + Response inner + = this.serviceClient().getRootWithResponse(providerNamespace, resourceType, sku, context); + if (inner != null) { + return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(), + new SkuResourceImpl(inner.getValue(), this.manager())); + } else { + return null; + } + } + + public SkuResource getRoot(String providerNamespace, String resourceType, String sku) { + SkuResourceInner inner = this.serviceClient().getRoot(providerNamespace, resourceType, sku); + if (inner != null) { + return new SkuResourceImpl(inner, this.manager()); + } else { + return null; + } + } + + public Response deleteRootWithResponse(String providerNamespace, String resourceType, String sku, + Context context) { + return this.serviceClient().deleteRootWithResponse(providerNamespace, resourceType, sku, context); + } + + public void deleteRoot(String providerNamespace, String resourceType, String sku) { + this.serviceClient().deleteRoot(providerNamespace, resourceType, sku); + } + + public SkuResource getRootById(String id) { + String providerNamespace = ResourceManagerUtils.getValueFromIdByName(id, "providerRegistrations"); + if (providerNamespace == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'providerRegistrations'.", id))); + } + String resourceType = ResourceManagerUtils.getValueFromIdByName(id, "resourcetypeRegistrations"); + if (resourceType == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException(String + .format("The resource ID '%s' is not valid. Missing path segment 'resourcetypeRegistrations'.", id))); + } + String sku = ResourceManagerUtils.getValueFromIdByName(id, "skus"); + if (sku == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'skus'.", id))); + } + return this.getRootWithResponse(providerNamespace, resourceType, sku, Context.NONE).getValue(); + } + + public Response getRootByIdWithResponse(String id, Context context) { + String providerNamespace = ResourceManagerUtils.getValueFromIdByName(id, "providerRegistrations"); + if (providerNamespace == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'providerRegistrations'.", id))); + } + String resourceType = ResourceManagerUtils.getValueFromIdByName(id, "resourcetypeRegistrations"); + if (resourceType == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException(String + .format("The resource ID '%s' is not valid. Missing path segment 'resourcetypeRegistrations'.", id))); + } + String sku = ResourceManagerUtils.getValueFromIdByName(id, "skus"); + if (sku == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'skus'.", id))); + } + return this.getRootWithResponse(providerNamespace, resourceType, sku, context); + } + + public void deleteRootById(String id) { + String providerNamespace = ResourceManagerUtils.getValueFromIdByName(id, "providerRegistrations"); + if (providerNamespace == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'providerRegistrations'.", id))); + } + String resourceType = ResourceManagerUtils.getValueFromIdByName(id, "resourcetypeRegistrations"); + if (resourceType == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException(String + .format("The resource ID '%s' is not valid. Missing path segment 'resourcetypeRegistrations'.", id))); + } + String sku = ResourceManagerUtils.getValueFromIdByName(id, "skus"); + if (sku == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'skus'.", id))); + } + this.deleteRootWithResponse(providerNamespace, resourceType, sku, Context.NONE); + } + + public Response deleteRootByIdWithResponse(String id, Context context) { + String providerNamespace = ResourceManagerUtils.getValueFromIdByName(id, "providerRegistrations"); + if (providerNamespace == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'providerRegistrations'.", id))); + } + String resourceType = ResourceManagerUtils.getValueFromIdByName(id, "resourcetypeRegistrations"); + if (resourceType == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException(String + .format("The resource ID '%s' is not valid. Missing path segment 'resourcetypeRegistrations'.", id))); + } + String sku = ResourceManagerUtils.getValueFromIdByName(id, "skus"); + if (sku == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'skus'.", id))); + } + return this.deleteRootWithResponse(providerNamespace, resourceType, sku, context); + } + + private SkusClient serviceClient() { + return this.innerClient; + } + + private tsptest.armlegacy.ArmLegacyManager manager() { + return this.serviceManager; + } + + public SkuResourceImpl define(String name) { + return new SkuResourceImpl(name, this.manager()); + } +} diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/implementation/package-info.java b/typespec-tests/src/main/java/tsptest/armlegacy/implementation/package-info.java new file mode 100644 index 0000000000..7c77130eb6 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/implementation/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the implementations for ArmLegacy. + * Arm Resource Provider management API. + */ +package tsptest.armlegacy.implementation; diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/models/ProvisioningState.java b/typespec-tests/src/main/java/tsptest/armlegacy/models/ProvisioningState.java new file mode 100644 index 0000000000..4c5281afda --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/models/ProvisioningState.java @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armlegacy.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * Defines values for ProvisioningState. + */ +public final class ProvisioningState extends ExpandableStringEnum { + /** + * Resource has been created. + */ + public static final ProvisioningState SUCCEEDED = fromString("Succeeded"); + + /** + * Resource creation failed. + */ + public static final ProvisioningState FAILED = fromString("Failed"); + + /** + * Resource creation was canceled. + */ + public static final ProvisioningState CANCELED = fromString("Canceled"); + + /** + * Static value Provisioning for ProvisioningState. + */ + public static final ProvisioningState PROVISIONING = fromString("Provisioning"); + + /** + * Static value Updating for ProvisioningState. + */ + public static final ProvisioningState UPDATING = fromString("Updating"); + + /** + * Static value Deleting for ProvisioningState. + */ + public static final ProvisioningState DELETING = fromString("Deleting"); + + /** + * Static value Accepted for ProvisioningState. + */ + public static final ProvisioningState ACCEPTED = fromString("Accepted"); + + /** + * Creates a new instance of ProvisioningState value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public ProvisioningState() { + } + + /** + * Creates or finds a ProvisioningState from its string representation. + * + * @param name a name to look for. + * @return the corresponding ProvisioningState. + */ + public static ProvisioningState fromString(String name) { + return fromString(name, ProvisioningState.class); + } + + /** + * Gets known ProvisioningState values. + * + * @return known ProvisioningState values. + */ + public static Collection values() { + return values(ProvisioningState.class); + } +} diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/models/ResourceTypeSku.java b/typespec-tests/src/main/java/tsptest/armlegacy/models/ResourceTypeSku.java new file mode 100644 index 0000000000..470a039632 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/models/ResourceTypeSku.java @@ -0,0 +1,73 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armlegacy.models; + +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The ResourceTypeSku model. + */ +@Immutable +public final class ResourceTypeSku implements JsonSerializable { + /* + * The provisioningState property. + */ + private ProvisioningState provisioningState; + + /** + * Creates an instance of ResourceTypeSku class. + */ + public ResourceTypeSku() { + } + + /** + * Get the provisioningState property: The provisioningState property. + * + * @return the provisioningState value. + */ + public ProvisioningState provisioningState() { + return this.provisioningState; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ResourceTypeSku from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ResourceTypeSku if the JsonReader was pointing to an instance of it, or null if it was + * pointing to JSON null. + * @throws IOException If an error occurs while reading the ResourceTypeSku. + */ + public static ResourceTypeSku fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ResourceTypeSku deserializedResourceTypeSku = new ResourceTypeSku(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("provisioningState".equals(fieldName)) { + deserializedResourceTypeSku.provisioningState = ProvisioningState.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + + return deserializedResourceTypeSku; + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/models/SkuResource.java b/typespec-tests/src/main/java/tsptest/armlegacy/models/SkuResource.java new file mode 100644 index 0000000000..7136d52dbf --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/models/SkuResource.java @@ -0,0 +1,137 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armlegacy.models; + +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; +import tsptest.armlegacy.fluent.models.SkuResourceInner; + +/** + * An immutable client-side representation of SkuResource. + */ +public interface SkuResource { + /** + * Gets the id property: Fully qualified resource Id for the resource. + * + * @return the id value. + */ + String id(); + + /** + * Gets the name property: The name of the resource. + * + * @return the name value. + */ + String name(); + + /** + * Gets the type property: The type of the resource. + * + * @return the type value. + */ + String type(); + + /** + * Gets the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + ResourceTypeSku properties(); + + /** + * Gets the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + SystemData systemData(); + + /** + * Gets the inner tsptest.armlegacy.fluent.models.SkuResourceInner object. + * + * @return the inner object. + */ + SkuResourceInner innerModel(); + + /** + * The entirety of the SkuResource definition. + */ + interface Definition + extends DefinitionStages.Blank, DefinitionStages.WithParentResource, DefinitionStages.WithCreate { + } + + /** + * The SkuResource definition stages. + */ + interface DefinitionStages { + /** + * The first stage of the SkuResource definition. + */ + interface Blank extends WithParentResource { + } + + /** + * The stage of the SkuResource definition allowing to specify parent resource. + */ + interface WithParentResource { + /** + * Specifies providerNamespace, resourceType. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @return the next definition stage. + */ + WithCreate withExistingResourcetypeRegistration(String providerNamespace, String resourceType); + } + + /** + * The stage of the SkuResource definition which contains all the minimum required properties for the resource + * to be created, but also allows for any other optional properties to be specified. + */ + interface WithCreate extends DefinitionStages.WithProperties { + /** + * Executes the create request. + * + * @return the created resource. + */ + SkuResource create(); + + /** + * Executes the create request. + * + * @param context The context to associate with this operation. + * @return the created resource. + */ + SkuResource create(Context context); + } + + /** + * The stage of the SkuResource definition allowing to specify properties. + */ + interface WithProperties { + /** + * Specifies the properties property: The resource-specific properties for this resource.. + * + * @param properties The resource-specific properties for this resource. + * @return the next definition stage. + */ + WithCreate withProperties(ResourceTypeSku properties); + } + } + + /** + * Refreshes the resource to sync with Azure. + * + * @return the refreshed resource. + */ + SkuResource refresh(); + + /** + * Refreshes the resource to sync with Azure. + * + * @param context The context to associate with this operation. + * @return the refreshed resource. + */ + SkuResource refresh(Context context); +} diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/models/Skus.java b/typespec-tests/src/main/java/tsptest/armlegacy/models/Skus.java new file mode 100644 index 0000000000..ea55ce0b7c --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/models/Skus.java @@ -0,0 +1,214 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.armlegacy.models; + +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; +import tsptest.armlegacy.fluent.models.SkuResourceInner; + +/** + * Resource collection API of Skus. + */ +public interface Skus { + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource along with {@link Response}. + */ + Response getNestedWithResponse(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku, Context context); + + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource. + */ + SkuResource getNested(String providerNamespace, String resourceType, String nestedResourceTypeFirst, String sku); + + /** + * Create a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete proxy resource types can be created by aliasing this type using a specific property type along + * with {@link Response}. + */ + Response createNestedWithResponse(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku, SkuResourceInner resource, Context context); + + /** + * Create a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return concrete proxy resource types can be created by aliasing this type using a specific property type. + */ + SkuResource createNested(String providerNamespace, String resourceType, String nestedResourceTypeFirst, String sku, + SkuResourceInner resource); + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + Response deleteNestedWithResponse(String providerNamespace, String resourceType, + String nestedResourceTypeFirst, String sku, Context context); + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param nestedResourceTypeFirst The first child resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + void deleteNested(String providerNamespace, String resourceType, String nestedResourceTypeFirst, String sku); + + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource along with {@link Response}. + */ + Response getRootWithResponse(String providerNamespace, String resourceType, String sku, + Context context); + + /** + * Get a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource. + */ + SkuResource getRoot(String providerNamespace, String resourceType, String sku); + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + Response deleteRootWithResponse(String providerNamespace, String resourceType, String sku, Context context); + + /** + * Delete a SkuResource. + * + * @param providerNamespace The name of the resource provider hosted within ProviderHub. + * @param resourceType The resource type. + * @param sku The SKU. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + void deleteRoot(String providerNamespace, String resourceType, String sku); + + /** + * Get a SkuResource. + * + * @param id the resource ID. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource along with {@link Response}. + */ + SkuResource getRootById(String id); + + /** + * Get a SkuResource. + * + * @param id the resource ID. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a SkuResource along with {@link Response}. + */ + Response getRootByIdWithResponse(String id, Context context); + + /** + * Delete a SkuResource. + * + * @param id the resource ID. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + void deleteRootById(String id); + + /** + * Delete a SkuResource. + * + * @param id the resource ID. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link Response}. + */ + Response deleteRootByIdWithResponse(String id, Context context); + + /** + * Begins definition for a new SkuResource resource. + * + * @param name resource name. + * @return the first stage of the new SkuResource definition. + */ + SkuResource.DefinitionStages.Blank define(String name); +} diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/models/package-info.java b/typespec-tests/src/main/java/tsptest/armlegacy/models/package-info.java new file mode 100644 index 0000000000..c58defcfc9 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/models/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the data models for ArmLegacy. + * Arm Resource Provider management API. + */ +package tsptest.armlegacy.models; diff --git a/typespec-tests/src/main/java/tsptest/armlegacy/package-info.java b/typespec-tests/src/main/java/tsptest/armlegacy/package-info.java new file mode 100644 index 0000000000..c5f766eb6d --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/armlegacy/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the classes for ArmLegacy. + * Arm Resource Provider management API. + */ +package tsptest.armlegacy; diff --git a/typespec-tests/src/main/java/tsptest/armstreamstyleserialization/models/SawShark.java b/typespec-tests/src/main/java/tsptest/armstreamstyleserialization/models/SawShark.java index dad701b3bc..49590e9c11 100644 --- a/typespec-tests/src/main/java/tsptest/armstreamstyleserialization/models/SawShark.java +++ b/typespec-tests/src/main/java/tsptest/armstreamstyleserialization/models/SawShark.java @@ -276,7 +276,6 @@ public void validate() { public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); jsonWriter.writeStringField("kind", this.kind); - jsonWriter.writeIntField("age", age()); jsonWriter.writeJsonField("properties", innerProperties()); jsonWriter.writeJsonField("anotherProperties", innerAnotherProperties()); jsonWriter.writeStringField("dna", this.dna); diff --git a/typespec-tests/src/main/java/tsptest/subclass/SubclassAsyncClient.java b/typespec-tests/src/main/java/tsptest/subclass/SubclassAsyncClient.java new file mode 100644 index 0000000000..6b4b01bb4d --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/SubclassAsyncClient.java @@ -0,0 +1,113 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; +import tsptest.subclass.implementation.SubclassImpl; +import tsptest.subclass.models.Body; + +/** + * Initializes a new instance of the asynchronous SubclassClient type. + */ +@ServiceClient(builder = SubclassClientBuilder.class, isAsync = true) +public final class SubclassAsyncClient { + @Generated + private final SubclassImpl serviceClient; + + /** + * Initializes an instance of SubclassAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + SubclassAsyncClient(SubclassImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The propertyInSubclass operation. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param body The body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> propertyInSubclassWithResponse(BinaryData body, RequestOptions requestOptions) { + return this.serviceClient.propertyInSubclassWithResponseAsync(body, requestOptions); + } + + /** + * The propertyInSubclass operation. + * + * @param body The body parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response body on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono propertyInSubclass(Body body) { + // Generated convenience method for propertyInSubclassWithResponse + RequestOptions requestOptions = new RequestOptions(); + return propertyInSubclassWithResponse(BinaryData.fromObject(body), requestOptions).flatMap(FluxUtil::toMono) + .map(protocolMethodData -> protocolMethodData.toObject(Body.class)); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/SubclassClient.java b/typespec-tests/src/main/java/tsptest/subclass/SubclassClient.java new file mode 100644 index 0000000000..7dfe8614ef --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/SubclassClient.java @@ -0,0 +1,111 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import tsptest.subclass.implementation.SubclassImpl; +import tsptest.subclass.models.Body; + +/** + * Initializes a new instance of the synchronous SubclassClient type. + */ +@ServiceClient(builder = SubclassClientBuilder.class) +public final class SubclassClient { + @Generated + private final SubclassImpl serviceClient; + + /** + * Initializes an instance of SubclassClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + SubclassClient(SubclassImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The propertyInSubclass operation. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param body The body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response propertyInSubclassWithResponse(BinaryData body, RequestOptions requestOptions) { + return this.serviceClient.propertyInSubclassWithResponse(body, requestOptions); + } + + /** + * The propertyInSubclass operation. + * + * @param body The body parameter. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Body propertyInSubclass(Body body) { + // Generated convenience method for propertyInSubclassWithResponse + RequestOptions requestOptions = new RequestOptions(); + return propertyInSubclassWithResponse(BinaryData.fromObject(body), requestOptions).getValue() + .toObject(Body.class); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/SubclassClientBuilder.java b/typespec-tests/src/main/java/tsptest/subclass/SubclassClientBuilder.java new file mode 100644 index 0000000000..13b233af8f --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/SubclassClientBuilder.java @@ -0,0 +1,287 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.client.traits.ConfigurationTrait; +import com.azure.core.client.traits.EndpointTrait; +import com.azure.core.client.traits.HttpTrait; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; +import com.azure.core.http.policy.AddHeadersPolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.ClientOptions; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.builder.ClientBuilderUtil; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.serializer.JacksonAdapter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import tsptest.subclass.implementation.SubclassClientImpl; + +/** + * A builder for creating a new instance of the SubclassClient type. + */ +@ServiceClientBuilder(serviceClients = { SubclassClient.class, SubclassAsyncClient.class }) +public final class SubclassClientBuilder implements HttpTrait, + ConfigurationTrait, EndpointTrait { + @Generated + private static final String SDK_NAME = "name"; + + @Generated + private static final String SDK_VERSION = "version"; + + @Generated + private static final Map PROPERTIES = CoreUtils.getProperties("tsptest-subclass.properties"); + + @Generated + private final List pipelinePolicies; + + /** + * Create an instance of the SubclassClientBuilder. + */ + @Generated + public SubclassClientBuilder() { + this.pipelinePolicies = new ArrayList<>(); + } + + /* + * The HTTP client used to send the request. + */ + @Generated + private HttpClient httpClient; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /* + * The HTTP pipeline to send requests through. + */ + @Generated + private HttpPipeline pipeline; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder pipeline(HttpPipeline pipeline) { + if (this.pipeline != null && pipeline == null) { + LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured."); + } + this.pipeline = pipeline; + return this; + } + + /* + * The logging configuration for HTTP requests and responses. + */ + @Generated + private HttpLogOptions httpLogOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = httpLogOptions; + return this; + } + + /* + * The client options such as application ID and custom headers to set on a request. + */ + @Generated + private ClientOptions clientOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + return this; + } + + /* + * The retry options to configure retry policy for failed requests. + */ + @Generated + private RetryOptions retryOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder retryOptions(RetryOptions retryOptions) { + this.retryOptions = retryOptions; + return this; + } + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { + Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null."); + pipelinePolicies.add(customPolicy); + return this; + } + + /* + * The configuration store that is used during construction of the service client. + */ + @Generated + private Configuration configuration; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder configuration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + /* + * The service endpoint + */ + @Generated + private String endpoint; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public SubclassClientBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * The retry policy that will attempt to retry failed requests, if applicable. + */ + @Generated + private RetryPolicy retryPolicy; + + /** + * Sets The retry policy that will attempt to retry failed requests, if applicable. + * + * @param retryPolicy the retryPolicy value. + * @return the SubclassClientBuilder. + */ + @Generated + public SubclassClientBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + + /** + * Builds an instance of SubclassClientImpl with the provided parameters. + * + * @return an instance of SubclassClientImpl. + */ + @Generated + private SubclassClientImpl buildInnerClient() { + this.validateClient(); + HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); + SubclassClientImpl client + = new SubclassClientImpl(localPipeline, JacksonAdapter.createDefaultSerializerAdapter(), this.endpoint); + return client; + } + + @Generated + private void validateClient() { + // This method is invoked from 'buildInnerClient'/'buildClient' method. + // Developer can customize this method, to validate that the necessary conditions are met for the new client. + Objects.requireNonNull(endpoint, "'endpoint' cannot be null."); + } + + @Generated + private HttpPipeline createHttpPipeline() { + Configuration buildConfiguration + = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; + HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions; + ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions; + List policies = new ArrayList<>(); + String clientName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName"); + String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); + String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions); + policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + policies.add(new RequestIdPolicy()); + policies.add(new AddHeadersFromContextPolicy()); + HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(localClientOptions); + if (headers != null) { + policies.add(new AddHeadersPolicy(headers)); + } + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); + policies.add(new AddDatePolicy()); + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(localHttpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) + .httpClient(httpClient) + .clientOptions(localClientOptions) + .build(); + return httpPipeline; + } + + /** + * Builds an instance of SubclassAsyncClient class. + * + * @return an instance of SubclassAsyncClient. + */ + @Generated + public SubclassAsyncClient buildAsyncClient() { + return new SubclassAsyncClient(buildInnerClient().getSubclass()); + } + + /** + * Builds an instance of SubclassClient class. + * + * @return an instance of SubclassClient. + */ + @Generated + public SubclassClient buildClient() { + return new SubclassClient(buildInnerClient().getSubclass()); + } + + private static final ClientLogger LOGGER = new ClientLogger(SubclassClientBuilder.class); +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassClientImpl.java b/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassClientImpl.java new file mode 100644 index 0000000000..5566742f36 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassClientImpl.java @@ -0,0 +1,107 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.implementation; + +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; + +/** + * Initializes a new instance of the SubclassClient type. + */ +public final class SubclassClientImpl { + /** + * Service host. + */ + private final String endpoint; + + /** + * Gets Service host. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** + * The HTTP pipeline to send requests through. + */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The serializer to serialize an object into a string. + */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + public SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * The SubclassImpl object to access its operations. + */ + private final SubclassImpl subclass; + + /** + * Gets the SubclassImpl object to access its operations. + * + * @return the SubclassImpl object. + */ + public SubclassImpl getSubclass() { + return this.subclass; + } + + /** + * Initializes an instance of SubclassClient client. + * + * @param endpoint Service host. + */ + public SubclassClientImpl(String endpoint) { + this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(), + JacksonAdapter.createDefaultSerializerAdapter(), endpoint); + } + + /** + * Initializes an instance of SubclassClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param endpoint Service host. + */ + public SubclassClientImpl(HttpPipeline httpPipeline, String endpoint) { + this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint); + } + + /** + * Initializes an instance of SubclassClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param endpoint Service host. + */ + public SubclassClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.endpoint = endpoint; + this.subclass = new SubclassImpl(this); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassImpl.java b/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassImpl.java new file mode 100644 index 0000000000..306cb98244 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassImpl.java @@ -0,0 +1,189 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.implementation; + +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.Post; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in Subclass. + */ +public final class SubclassImpl { + /** + * The proxy service used to perform REST calls. + */ + private final SubclassService service; + + /** + * The service client containing this operation class. + */ + private final SubclassClientImpl client; + + /** + * Initializes an instance of SubclassImpl. + * + * @param client the instance of the service client containing this operation class. + */ + SubclassImpl(SubclassClientImpl client) { + this.service = RestProxy.create(SubclassService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for SubclassClientSubclass to be used by the proxy service to perform + * REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "SubclassClientSubclass") + public interface SubclassService { + @Post("/subclass/property-in-subclass") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> propertyInSubclass(@HostParam("endpoint") String endpoint, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") BinaryData body, RequestOptions requestOptions, Context context); + + @Post("/subclass/property-in-subclass") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response propertyInSubclassSync(@HostParam("endpoint") String endpoint, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") BinaryData body, RequestOptions requestOptions, Context context); + } + + /** + * The propertyInSubclass operation. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param body The body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> propertyInSubclassWithResponseAsync(BinaryData body, + RequestOptions requestOptions) { + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.propertyInSubclass(this.client.getEndpoint(), contentType, + accept, body, requestOptions, context)); + } + + /** + * The propertyInSubclass operation. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     duplicateRequiredProperty (Optional): {
+     *         duplicateRequiredProperty: String (Required)
+     *     }
+     *     propertyChangedToRequired (Optional): {
+     *         propertyChangedToRequired: String (Required)
+     *     }
+     *     propertyChangedToConstant (Optional): {
+     *         propertyChangedToConstant: String (Required)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param body The body parameter. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response propertyInSubclassWithResponse(BinaryData body, RequestOptions requestOptions) { + final String contentType = "application/json"; + final String accept = "application/json"; + return service.propertyInSubclassSync(this.client.getEndpoint(), contentType, accept, body, requestOptions, + Context.NONE); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/implementation/package-info.java b/typespec-tests/src/main/java/tsptest/subclass/implementation/package-info.java new file mode 100644 index 0000000000..4cc0977cd8 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/implementation/package-info.java @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * + * Package containing the implementations for Subclass. + * + */ +package tsptest.subclass.implementation; diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/Body.java b/typespec-tests/src/main/java/tsptest/subclass/models/Body.java new file mode 100644 index 0000000000..432ee35a8b --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/Body.java @@ -0,0 +1,154 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.annotation.Generated; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The Body model. + */ +@Fluent +public final class Body implements JsonSerializable { + /* + * The duplicateRequiredProperty property. + */ + @Generated + private DuplicateRequiredProperty duplicateRequiredProperty; + + /* + * The propertyChangedToRequired property. + */ + @Generated + private PropertyChangedToRequired propertyChangedToRequired; + + /* + * The propertyChangedToConstant property. + */ + @Generated + private PropertyChangedToConstant propertyChangedToConstant; + + /** + * Creates an instance of Body class. + */ + @Generated + public Body() { + } + + /** + * Get the duplicateRequiredProperty property: The duplicateRequiredProperty property. + * + * @return the duplicateRequiredProperty value. + */ + @Generated + public DuplicateRequiredProperty getDuplicateRequiredProperty() { + return this.duplicateRequiredProperty; + } + + /** + * Set the duplicateRequiredProperty property: The duplicateRequiredProperty property. + * + * @param duplicateRequiredProperty the duplicateRequiredProperty value to set. + * @return the Body object itself. + */ + @Generated + public Body setDuplicateRequiredProperty(DuplicateRequiredProperty duplicateRequiredProperty) { + this.duplicateRequiredProperty = duplicateRequiredProperty; + return this; + } + + /** + * Get the propertyChangedToRequired property: The propertyChangedToRequired property. + * + * @return the propertyChangedToRequired value. + */ + @Generated + public PropertyChangedToRequired getPropertyChangedToRequired() { + return this.propertyChangedToRequired; + } + + /** + * Set the propertyChangedToRequired property: The propertyChangedToRequired property. + * + * @param propertyChangedToRequired the propertyChangedToRequired value to set. + * @return the Body object itself. + */ + @Generated + public Body setPropertyChangedToRequired(PropertyChangedToRequired propertyChangedToRequired) { + this.propertyChangedToRequired = propertyChangedToRequired; + return this; + } + + /** + * Get the propertyChangedToConstant property: The propertyChangedToConstant property. + * + * @return the propertyChangedToConstant value. + */ + @Generated + public PropertyChangedToConstant getPropertyChangedToConstant() { + return this.propertyChangedToConstant; + } + + /** + * Set the propertyChangedToConstant property: The propertyChangedToConstant property. + * + * @param propertyChangedToConstant the propertyChangedToConstant value to set. + * @return the Body object itself. + */ + @Generated + public Body setPropertyChangedToConstant(PropertyChangedToConstant propertyChangedToConstant) { + this.propertyChangedToConstant = propertyChangedToConstant; + return this; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("duplicateRequiredProperty", this.duplicateRequiredProperty); + jsonWriter.writeJsonField("propertyChangedToRequired", this.propertyChangedToRequired); + jsonWriter.writeJsonField("propertyChangedToConstant", this.propertyChangedToConstant); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of Body from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of Body if the JsonReader was pointing to an instance of it, or null if it was pointing to + * JSON null. + * @throws IOException If an error occurs while reading the Body. + */ + @Generated + public static Body fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + Body deserializedBody = new Body(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("duplicateRequiredProperty".equals(fieldName)) { + deserializedBody.duplicateRequiredProperty = DuplicateRequiredProperty.fromJson(reader); + } else if ("propertyChangedToRequired".equals(fieldName)) { + deserializedBody.propertyChangedToRequired = PropertyChangedToRequired.fromJson(reader); + } else if ("propertyChangedToConstant".equals(fieldName)) { + deserializedBody.propertyChangedToConstant = PropertyChangedToConstant.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedBody; + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredProperty.java b/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredProperty.java new file mode 100644 index 0000000000..828f6a0797 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredProperty.java @@ -0,0 +1,83 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The DuplicateRequiredProperty model. + */ +@Immutable +public final class DuplicateRequiredProperty extends DuplicateRequiredPropertyParent { + /* + * The duplicateRequiredProperty property. + */ + @Generated + private final String duplicateRequiredProperty; + + /** + * Creates an instance of DuplicateRequiredProperty class. + * + * @param duplicateRequiredProperty the duplicateRequiredProperty value to set. + */ + @Generated + public DuplicateRequiredProperty(String duplicateRequiredProperty) { + super(duplicateRequiredProperty); + this.duplicateRequiredProperty = duplicateRequiredProperty; + } + + /** + * Get the duplicateRequiredProperty property: The duplicateRequiredProperty property. + * + * @return the duplicateRequiredProperty value. + */ + @Generated + public String getDuplicateRequiredProperty() { + return this.duplicateRequiredProperty; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("duplicateRequiredProperty", this.duplicateRequiredProperty); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of DuplicateRequiredProperty from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of DuplicateRequiredProperty if the JsonReader was pointing to an instance of it, or null if + * it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the DuplicateRequiredProperty. + */ + @Generated + public static DuplicateRequiredProperty fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String duplicateRequiredProperty = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("duplicateRequiredProperty".equals(fieldName)) { + duplicateRequiredProperty = reader.getString(); + } else { + reader.skipChildren(); + } + } + return new DuplicateRequiredProperty(duplicateRequiredProperty); + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredPropertyParent.java b/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredPropertyParent.java new file mode 100644 index 0000000000..f936a25bb6 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredPropertyParent.java @@ -0,0 +1,83 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The DuplicateRequiredPropertyParent model. + */ +@Immutable +public class DuplicateRequiredPropertyParent implements JsonSerializable { + /* + * The duplicateRequiredProperty property. + */ + @Generated + private final String duplicateRequiredProperty; + + /** + * Creates an instance of DuplicateRequiredPropertyParent class. + * + * @param duplicateRequiredProperty the duplicateRequiredProperty value to set. + */ + @Generated + public DuplicateRequiredPropertyParent(String duplicateRequiredProperty) { + this.duplicateRequiredProperty = duplicateRequiredProperty; + } + + /** + * Get the duplicateRequiredProperty property: The duplicateRequiredProperty property. + * + * @return the duplicateRequiredProperty value. + */ + @Generated + public String getDuplicateRequiredProperty() { + return this.duplicateRequiredProperty; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("duplicateRequiredProperty", this.duplicateRequiredProperty); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of DuplicateRequiredPropertyParent from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of DuplicateRequiredPropertyParent if the JsonReader was pointing to an instance of it, or + * null if it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the DuplicateRequiredPropertyParent. + */ + @Generated + public static DuplicateRequiredPropertyParent fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String duplicateRequiredProperty = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("duplicateRequiredProperty".equals(fieldName)) { + duplicateRequiredProperty = reader.getString(); + } else { + reader.skipChildren(); + } + } + return new DuplicateRequiredPropertyParent(duplicateRequiredProperty); + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToConstant.java b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToConstant.java new file mode 100644 index 0000000000..4112d8e0e6 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToConstant.java @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The PropertyChangedToConstant model. + */ +@Immutable +public final class PropertyChangedToConstant extends PropertyChangedToConstantParent { + /* + * The propertyChangedToConstant property. + */ + @Generated + private final String propertyChangedToConstant = "constantValue"; + + /** + * Creates an instance of PropertyChangedToConstant class. + */ + @Generated + public PropertyChangedToConstant() { + super("constantValue"); + } + + /** + * Get the propertyChangedToConstant property: The propertyChangedToConstant property. + * + * @return the propertyChangedToConstant value. + */ + @Generated + public String getPropertyChangedToConstant() { + return this.propertyChangedToConstant; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("propertyChangedToConstant", this.propertyChangedToConstant); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of PropertyChangedToConstant from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of PropertyChangedToConstant if the JsonReader was pointing to an instance of it, or null if + * it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the PropertyChangedToConstant. + */ + @Generated + public static PropertyChangedToConstant fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + PropertyChangedToConstant deserializedPropertyChangedToConstant = new PropertyChangedToConstant(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + reader.skipChildren(); + } + + return deserializedPropertyChangedToConstant; + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToConstantParent.java b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToConstantParent.java new file mode 100644 index 0000000000..42ec9ff3a1 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToConstantParent.java @@ -0,0 +1,83 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The PropertyChangedToConstantParent model. + */ +@Immutable +public class PropertyChangedToConstantParent implements JsonSerializable { + /* + * The propertyChangedToConstant property. + */ + @Generated + private final String propertyChangedToConstant; + + /** + * Creates an instance of PropertyChangedToConstantParent class. + * + * @param propertyChangedToConstant the propertyChangedToConstant value to set. + */ + @Generated + public PropertyChangedToConstantParent(String propertyChangedToConstant) { + this.propertyChangedToConstant = propertyChangedToConstant; + } + + /** + * Get the propertyChangedToConstant property: The propertyChangedToConstant property. + * + * @return the propertyChangedToConstant value. + */ + @Generated + public String getPropertyChangedToConstant() { + return this.propertyChangedToConstant; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("propertyChangedToConstant", this.propertyChangedToConstant); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of PropertyChangedToConstantParent from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of PropertyChangedToConstantParent if the JsonReader was pointing to an instance of it, or + * null if it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the PropertyChangedToConstantParent. + */ + @Generated + public static PropertyChangedToConstantParent fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String propertyChangedToConstant = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("propertyChangedToConstant".equals(fieldName)) { + propertyChangedToConstant = reader.getString(); + } else { + reader.skipChildren(); + } + } + return new PropertyChangedToConstantParent(propertyChangedToConstant); + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToRequired.java b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToRequired.java new file mode 100644 index 0000000000..b71da97a6a --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToRequired.java @@ -0,0 +1,82 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.annotation.Generated; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The PropertyChangedToRequired model. + */ +@Fluent +public final class PropertyChangedToRequired extends PropertyChangedToRequiredParent { + /* + * The propertyChangedToRequired property. + */ + @Generated + private final String propertyChangedToRequired; + + /** + * Creates an instance of PropertyChangedToRequired class. + * + * @param propertyChangedToRequired the propertyChangedToRequired value to set. + */ + @Generated + public PropertyChangedToRequired(String propertyChangedToRequired) { + this.propertyChangedToRequired = propertyChangedToRequired; + } + + /** + * Get the propertyChangedToRequired property: The propertyChangedToRequired property. + * + * @return the propertyChangedToRequired value. + */ + @Generated + public String getPropertyChangedToRequired() { + return this.propertyChangedToRequired; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("propertyChangedToRequired", this.propertyChangedToRequired); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of PropertyChangedToRequired from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of PropertyChangedToRequired if the JsonReader was pointing to an instance of it, or null if + * it was pointing to JSON null. + * @throws IllegalStateException If the deserialized JSON object was missing any required properties. + * @throws IOException If an error occurs while reading the PropertyChangedToRequired. + */ + @Generated + public static PropertyChangedToRequired fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String propertyChangedToRequired = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("propertyChangedToRequired".equals(fieldName)) { + propertyChangedToRequired = reader.getString(); + } else { + reader.skipChildren(); + } + } + return new PropertyChangedToRequired(propertyChangedToRequired); + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToRequiredParent.java b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToRequiredParent.java new file mode 100644 index 0000000000..2ab1511ea6 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/PropertyChangedToRequiredParent.java @@ -0,0 +1,93 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.models; + +import com.azure.core.annotation.Fluent; +import com.azure.core.annotation.Generated; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The PropertyChangedToRequiredParent model. + */ +@Fluent +public class PropertyChangedToRequiredParent implements JsonSerializable { + /* + * The propertyChangedToRequired property. + */ + @Generated + private String propertyChangedToRequired; + + /** + * Creates an instance of PropertyChangedToRequiredParent class. + */ + @Generated + public PropertyChangedToRequiredParent() { + } + + /** + * Get the propertyChangedToRequired property: The propertyChangedToRequired property. + * + * @return the propertyChangedToRequired value. + */ + @Generated + public String getPropertyChangedToRequired() { + return this.propertyChangedToRequired; + } + + /** + * Set the propertyChangedToRequired property: The propertyChangedToRequired property. + * + * @param propertyChangedToRequired the propertyChangedToRequired value to set. + * @return the PropertyChangedToRequiredParent object itself. + */ + @Generated + public PropertyChangedToRequiredParent setPropertyChangedToRequired(String propertyChangedToRequired) { + this.propertyChangedToRequired = propertyChangedToRequired; + return this; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("propertyChangedToRequired", this.propertyChangedToRequired); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of PropertyChangedToRequiredParent from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of PropertyChangedToRequiredParent if the JsonReader was pointing to an instance of it, or + * null if it was pointing to JSON null. + * @throws IOException If an error occurs while reading the PropertyChangedToRequiredParent. + */ + @Generated + public static PropertyChangedToRequiredParent fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + PropertyChangedToRequiredParent deserializedPropertyChangedToRequiredParent + = new PropertyChangedToRequiredParent(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("propertyChangedToRequired".equals(fieldName)) { + deserializedPropertyChangedToRequiredParent.propertyChangedToRequired = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedPropertyChangedToRequiredParent; + }); + } +} diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/package-info.java b/typespec-tests/src/main/java/tsptest/subclass/models/package-info.java new file mode 100644 index 0000000000..a14fc55334 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/models/package-info.java @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * + * Package containing the data models for Subclass. + * + */ +package tsptest.subclass.models; diff --git a/typespec-tests/src/main/java/tsptest/subclass/package-info.java b/typespec-tests/src/main/java/tsptest/subclass/package-info.java new file mode 100644 index 0000000000..925d7ab7f0 --- /dev/null +++ b/typespec-tests/src/main/java/tsptest/subclass/package-info.java @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * + * Package containing the classes for Subclass. + * + */ +package tsptest.subclass; diff --git a/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armlegacy-generated/proxy-config.json b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armlegacy-generated/proxy-config.json new file mode 100644 index 0000000000..14dc57b73c --- /dev/null +++ b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armlegacy-generated/proxy-config.json @@ -0,0 +1 @@ +[["tsptest.armlegacy.implementation.SkusClientImpl$SkusService"]] \ No newline at end of file diff --git a/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armlegacy-generated/reflect-config.json b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armlegacy-generated/reflect-config.json new file mode 100644 index 0000000000..0637a088a0 --- /dev/null +++ b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-armlegacy-generated/reflect-config.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/typespec-tests/src/main/resources/azure-resourcemanager-armlegacy-generated.properties b/typespec-tests/src/main/resources/azure-resourcemanager-armlegacy-generated.properties new file mode 100644 index 0000000000..defbd48204 --- /dev/null +++ b/typespec-tests/src/main/resources/azure-resourcemanager-armlegacy-generated.properties @@ -0,0 +1 @@ +version=${project.version} diff --git a/typespec-tests/src/main/resources/tsptest-subclass.properties b/typespec-tests/src/main/resources/tsptest-subclass.properties new file mode 100644 index 0000000000..ca812989b4 --- /dev/null +++ b/typespec-tests/src/main/resources/tsptest-subclass.properties @@ -0,0 +1,2 @@ +name=${project.artifactId} +version=${project.version} diff --git a/typespec-tests/src/test/java/azure/resourcemanager/multiservice/ArmMultipleServiceTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiservice/ArmMultipleServiceTests.java new file mode 100644 index 0000000000..690005694e --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiservice/ArmMultipleServiceTests.java @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package azure.resourcemanager.multiservice; + +import azure.resourcemanager.multiservice.combined.CombinedManager; +import azure.resourcemanager.multiservice.combined.models.DiskProperties; +import azure.resourcemanager.multiservice.combined.models.VirtualMachineProperties; +import com.azure.core.management.Region; +import org.junit.jupiter.api.Test; +import org.utils.ArmUtils; + +public final class ArmMultipleServiceTests { + + private final CombinedManager manager + = CombinedManager.authenticate(ArmUtils.createTestHttpPipeline(), ArmUtils.getAzureProfile()); + + private static final String RESOURCE_GROUP_NAME = "test-rg"; + private static final Region REGION = Region.US_EAST; + + @Test + public void testCombinedClient() { + manager.disks() + .define("disk1") + .withRegion(REGION) + .withExistingResourceGroup(RESOURCE_GROUP_NAME) + .withProperties(new DiskProperties()) + .create(); + manager.disks().getByResourceGroup(RESOURCE_GROUP_NAME, "disk1"); + + manager.virtualMachines() + .define("vm1") + .withRegion(REGION) + .withExistingResourceGroup(RESOURCE_GROUP_NAME) + .withProperties(new VirtualMachineProperties()) + .create(); + manager.virtualMachines().getByResourceGroup(RESOURCE_GROUP_NAME, "vm1"); + } +} diff --git a/typespec-tests/src/test/java/service/multiservice/MultipleServiceTests.java b/typespec-tests/src/test/java/service/multiservice/MultipleServiceTests.java new file mode 100644 index 0000000000..f80736805a --- /dev/null +++ b/typespec-tests/src/test/java/service/multiservice/MultipleServiceTests.java @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package service.multiservice; + +import org.junit.jupiter.api.Test; +import service.multiservice.combined.BarClient; +import service.multiservice.combined.CombinedBuilder; +import service.multiservice.combined.FooClient; + +public final class MultipleServiceTests { + + private final FooClient fooClient = new CombinedBuilder().buildFooClient(); + private final BarClient barClient = new CombinedBuilder().buildBarClient(); + + @Test + public void testCombinedClient() { + fooClient.test(); + barClient.test(); + } +} diff --git a/typespec-tests/src/test/java/tsptest/subclass/SubclassPropertyTests.java b/typespec-tests/src/test/java/tsptest/subclass/SubclassPropertyTests.java new file mode 100644 index 0000000000..0d425cbad4 --- /dev/null +++ b/typespec-tests/src/test/java/tsptest/subclass/SubclassPropertyTests.java @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package tsptest.subclass; + +import com.azure.core.util.BinaryData; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; +import tsptest.subclass.models.PropertyChangedToConstant; +import tsptest.subclass.models.PropertyChangedToRequired; + +public class SubclassPropertyTests { + + @Test + public void testPropertyChangedToRequired() { + PropertyChangedToRequired model = new PropertyChangedToRequired("value"); + String json = BinaryData.fromObject(model).toString(); + Assertions.assertEquals("{\"propertyChangedToRequired\":\"value\"}", json); + + model = BinaryData.fromString(json).toObject(PropertyChangedToRequired.class); + Assertions.assertEquals("value", model.getPropertyChangedToRequired()); + } + + @Test + public void testPropertyChangedToConstant() { + PropertyChangedToConstant model = new PropertyChangedToConstant(); + String json = BinaryData.fromObject(model).toString(); + Assertions.assertEquals("{\"propertyChangedToConstant\":\"constantValue\"}", json); + + model = BinaryData.fromString(json).toObject(PropertyChangedToConstant.class); + Assertions.assertEquals("constantValue", model.getPropertyChangedToConstant()); + } +} diff --git a/typespec-tests/src/test/java/tsptest/subclass/generated/SubclassClientTestBase.java b/typespec-tests/src/test/java/tsptest/subclass/generated/SubclassClientTestBase.java new file mode 100644 index 0000000000..5ade858bbc --- /dev/null +++ b/typespec-tests/src/test/java/tsptest/subclass/generated/SubclassClientTestBase.java @@ -0,0 +1,34 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package tsptest.subclass.generated; + +// The Java test files under 'generated' package are generated for your reference. +// If you wish to modify these files, please copy them out of the 'generated' package, and modify there. +// See https://aka.ms/azsdk/dpg/java/tests for guide on adding a test. + +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.test.TestMode; +import com.azure.core.test.TestProxyTestBase; +import com.azure.core.util.Configuration; +import tsptest.subclass.SubclassClient; +import tsptest.subclass.SubclassClientBuilder; + +class SubclassClientTestBase extends TestProxyTestBase { + protected SubclassClient subclassClient; + + @Override + protected void beforeTest() { + SubclassClientBuilder subclassClientbuilder + = new SubclassClientBuilder().endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "endpoint")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.RECORD) { + subclassClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + subclassClient = subclassClientbuilder.buildClient(); + + } +} diff --git a/typespec-tests/tsp/arm-legacy.tsp b/typespec-tests/tsp/arm-legacy.tsp new file mode 100644 index 0000000000..dbb8f07452 --- /dev/null +++ b/typespec-tests/tsp/arm-legacy.tsp @@ -0,0 +1,129 @@ +import "@typespec/http"; +import "@typespec/rest"; +import "@typespec/versioning"; +import "@azure-tools/typespec-azure-core"; +import "@azure-tools/typespec-azure-resource-manager"; +import "@azure-tools/typespec-client-generator-core"; + +using TypeSpec.Http; +using TypeSpec.Rest; +using TypeSpec.Versioning; +using Azure.ResourceManager; +using Azure.ClientGenerator.Core; + +@armProviderNamespace +@service(#{ title: "ArmLegacy" }) +@versioned(Versions) +@doc("Arm Resource Provider management API.") +namespace TspTest.ArmLegacy; + +enum Versions { + v2024_12_01: "2024-12-01", +} + +model SkuResource is Azure.ResourceManager.ProxyResource { + ...ResourceNameParameter< + Resource = SkuResource, + KeyName = "sku", + SegmentName = "skus", + NamePattern = "" + >; +} + +@armResourceOperations +interface Skus { + getNested is SkuNested.Read; + + createNested is SkuNested.CreateOrUpdateSync< + SkuResource, + Response = ArmResourceUpdatedResponse + >; + + deleteNested is SkuNested.DeleteSync; + + getRoot is SkuRoot.Read; + + createRoot is SkuRoot.CreateOrUpdateSync< + SkuResource, + Response = ArmResourceUpdatedResponse + >; + + deleteRoot is SkuRoot.DeleteSync; +} + +model ResourceTypeSku { + @visibility(Lifecycle.Read) + provisioningState?: ProvisioningState; +} + +union ProvisioningState { + ResourceProvisioningState, + Provisioning: "Provisioning", + Updating: "Updating", + Deleting: "Deleting", + Accepted: "Accepted", +} + +interface SkuRoot + extends Azure.ResourceManager.Legacy.ExtensionOperations< + { + ...ApiVersionParameter, + ...SubscriptionIdParameter, + ...Azure.ResourceManager.Legacy.Provider, + + /** The name of the resource provider hosted within ProviderHub. */ + @path + @segment("providerRegistrations") + @key + providerNamespace: string, + + /** The resource type. */ + @path + @segment("resourcetypeRegistrations") + @key + resourceType: string, + }, + {}, + { + /** The SKU. */ + @path + @segment("skus") + @key + sku: string, + } + > {} + +interface SkuNested + extends Azure.ResourceManager.Legacy.ExtensionOperations< + { + ...ApiVersionParameter, + ...SubscriptionIdParameter, + ...Azure.ResourceManager.Legacy.Provider, + + /** The name of the resource provider hosted within ProviderHub. */ + @path + @segment("providerRegistrations") + @key + providerNamespace: string, + + /** The resource type. */ + @path + @segment("resourcetypeRegistrations") + @key + resourceType: string, + + /** The first child resource type. */ + @path + @segment("resourcetypeRegistrations") + @key + nestedResourceTypeFirst: string, + }, + {}, + { + /** The SKU. */ + @path + @segment("skus") + @key + sku: string, + } + > {} diff --git a/typespec-tests/tsp/subclass.tsp b/typespec-tests/tsp/subclass.tsp new file mode 100644 index 0000000000..8afbf8e9d6 --- /dev/null +++ b/typespec-tests/tsp/subclass.tsp @@ -0,0 +1,54 @@ +import "@typespec/rest"; +import "@azure-tools/typespec-azure-core"; +import "@azure-tools/typespec-client-generator-core"; + +using TypeSpec.Http; + +@service(#{ title: "Subclass" }) +namespace TspTest.Subclass; + +model DuplicateRequiredPropertyParent { + duplicateRequiredProperty: string; +} +model DuplicateRequiredProperty extends DuplicateRequiredPropertyParent { + duplicateRequiredProperty: string; +} + +model PropertyChangedToRequiredParent { + propertyChangedToRequired?: string; +} +model PropertyChangedToRequired extends PropertyChangedToRequiredParent { + propertyChangedToRequired: string; +} + +model PropertyChangedToConstantParent { + propertyChangedToConstant: string; +} +model PropertyChangedToConstant extends PropertyChangedToConstantParent { + propertyChangedToConstant: "constantValue"; +} + +// Incompatible return type in Java method override +// model PropertyChangedToEnumParent { +// propertyChangedToEnum: string; +// } +// model PropertyChangedToEnum extends PropertyChangedToEnumParent { +// propertyChangedToEnum: EnumModel; +// } +// union EnumModel { +// string, +// "value1", +// } + +model Body { + duplicateRequiredProperty?: DuplicateRequiredProperty; + propertyChangedToRequired?: PropertyChangedToRequired; + propertyChangedToConstant?: PropertyChangedToConstant; +} + +@route("/subclass") +interface Subclass { + @post + @route("/property-in-subclass") + propertyInSubclass(@body body: Body): Body; +} From f4898f7ad610faad923ac8ac21df6dae7243f1bc Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Sun, 11 Jan 2026 18:20:39 +0800 Subject: [PATCH 3/6] update core --- core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core b/core index 993951fca9..dafe0ec77c 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 993951fca9b12333a0dbc30867e8a58b5b42cb47 +Subproject commit dafe0ec77c34474c450c5d56981ba286027c6852 From 1d76c9c4600a9d2568a5ec85adce9def24a8022b Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Sun, 11 Jan 2026 19:10:39 +0800 Subject: [PATCH 4/6] update core --- core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core b/core index dafe0ec77c..a675ba6af6 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit dafe0ec77c34474c450c5d56981ba286027c6852 +Subproject commit a675ba6af68ebaa2b9986eac553dddfa9fca4caa From dc64104b5355c30cc909c319fcc1110062c5a6bc Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Sun, 11 Jan 2026 19:59:03 +0800 Subject: [PATCH 5/6] update core --- core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core b/core index a675ba6af6..bdef8c0b9c 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit a675ba6af68ebaa2b9986eac553dddfa9fca4caa +Subproject commit bdef8c0b9cc8cec9cd4e0cbe2b706bebd3688067 From d8a2e36a569b45cb7e6b0bd091018db861c666b7 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Sun, 11 Jan 2026 20:03:52 +0800 Subject: [PATCH 6/6] sync test --- .../tsptest/subclass/SubclassAsyncClient.java | 2 ++ .../java/tsptest/subclass/SubclassClient.java | 2 ++ .../subclass/implementation/SubclassImpl.java | 4 +++ .../models/DuplicateRequiredProperty.java | 33 +++++++++++-------- .../DuplicateRequiredPropertyParent.java | 28 ++++++++++++++-- typespec-tests/tsp/subclass.tsp | 6 +++- 6 files changed, 57 insertions(+), 18 deletions(-) diff --git a/typespec-tests/src/main/java/tsptest/subclass/SubclassAsyncClient.java b/typespec-tests/src/main/java/tsptest/subclass/SubclassAsyncClient.java index 6b4b01bb4d..b1dde9b3e0 100644 --- a/typespec-tests/src/main/java/tsptest/subclass/SubclassAsyncClient.java +++ b/typespec-tests/src/main/java/tsptest/subclass/SubclassAsyncClient.java @@ -46,6 +46,7 @@ public final class SubclassAsyncClient { * {@code * { * duplicateRequiredProperty (Optional): { + * property: String (Required) * duplicateRequiredProperty: String (Required) * } * propertyChangedToRequired (Optional): { @@ -64,6 +65,7 @@ public final class SubclassAsyncClient { * {@code * { * duplicateRequiredProperty (Optional): { + * property: String (Required) * duplicateRequiredProperty: String (Required) * } * propertyChangedToRequired (Optional): { diff --git a/typespec-tests/src/main/java/tsptest/subclass/SubclassClient.java b/typespec-tests/src/main/java/tsptest/subclass/SubclassClient.java index 7dfe8614ef..775c767336 100644 --- a/typespec-tests/src/main/java/tsptest/subclass/SubclassClient.java +++ b/typespec-tests/src/main/java/tsptest/subclass/SubclassClient.java @@ -44,6 +44,7 @@ public final class SubclassClient { * {@code * { * duplicateRequiredProperty (Optional): { + * property: String (Required) * duplicateRequiredProperty: String (Required) * } * propertyChangedToRequired (Optional): { @@ -62,6 +63,7 @@ public final class SubclassClient { * {@code * { * duplicateRequiredProperty (Optional): { + * property: String (Required) * duplicateRequiredProperty: String (Required) * } * propertyChangedToRequired (Optional): { diff --git a/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassImpl.java b/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassImpl.java index 306cb98244..92a552910a 100644 --- a/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassImpl.java +++ b/typespec-tests/src/main/java/tsptest/subclass/implementation/SubclassImpl.java @@ -86,6 +86,7 @@ Response propertyInSubclassSync(@HostParam("endpoint") String endpoi * {@code * { * duplicateRequiredProperty (Optional): { + * property: String (Required) * duplicateRequiredProperty: String (Required) * } * propertyChangedToRequired (Optional): { @@ -104,6 +105,7 @@ Response propertyInSubclassSync(@HostParam("endpoint") String endpoi * {@code * { * duplicateRequiredProperty (Optional): { + * property: String (Required) * duplicateRequiredProperty: String (Required) * } * propertyChangedToRequired (Optional): { @@ -141,6 +143,7 @@ public Mono> propertyInSubclassWithResponseAsync(BinaryData * {@code * { * duplicateRequiredProperty (Optional): { + * property: String (Required) * duplicateRequiredProperty: String (Required) * } * propertyChangedToRequired (Optional): { @@ -159,6 +162,7 @@ public Mono> propertyInSubclassWithResponseAsync(BinaryData * {@code * { * duplicateRequiredProperty (Optional): { + * property: String (Required) * duplicateRequiredProperty: String (Required) * } * propertyChangedToRequired (Optional): { diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredProperty.java b/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredProperty.java index 828f6a0797..0444173953 100644 --- a/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredProperty.java +++ b/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredProperty.java @@ -20,27 +20,28 @@ public final class DuplicateRequiredProperty extends DuplicateRequiredPropertyPa * The duplicateRequiredProperty property. */ @Generated - private final String duplicateRequiredProperty; + private final String newRequiredProperty; /** * Creates an instance of DuplicateRequiredProperty class. * - * @param duplicateRequiredProperty the duplicateRequiredProperty value to set. + * @param requiredProperty the requiredProperty value to set. + * @param newRequiredProperty the newRequiredProperty value to set. */ @Generated - public DuplicateRequiredProperty(String duplicateRequiredProperty) { - super(duplicateRequiredProperty); - this.duplicateRequiredProperty = duplicateRequiredProperty; + public DuplicateRequiredProperty(String requiredProperty, String newRequiredProperty) { + super(requiredProperty, newRequiredProperty); + this.newRequiredProperty = newRequiredProperty; } /** - * Get the duplicateRequiredProperty property: The duplicateRequiredProperty property. + * Get the newRequiredProperty property: The duplicateRequiredProperty property. * - * @return the duplicateRequiredProperty value. + * @return the newRequiredProperty value. */ @Generated - public String getDuplicateRequiredProperty() { - return this.duplicateRequiredProperty; + public String getNewRequiredProperty() { + return this.newRequiredProperty; } /** @@ -50,7 +51,8 @@ public String getDuplicateRequiredProperty() { @Override public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { jsonWriter.writeStartObject(); - jsonWriter.writeStringField("duplicateRequiredProperty", this.duplicateRequiredProperty); + jsonWriter.writeStringField("property", getRequiredProperty()); + jsonWriter.writeStringField("duplicateRequiredProperty", this.newRequiredProperty); return jsonWriter.writeEndObject(); } @@ -66,18 +68,21 @@ public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { @Generated public static DuplicateRequiredProperty fromJson(JsonReader jsonReader) throws IOException { return jsonReader.readObject(reader -> { - String duplicateRequiredProperty = null; + String requiredProperty = null; + String newRequiredProperty = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("duplicateRequiredProperty".equals(fieldName)) { - duplicateRequiredProperty = reader.getString(); + if ("property".equals(fieldName)) { + requiredProperty = reader.getString(); + } else if ("duplicateRequiredProperty".equals(fieldName)) { + newRequiredProperty = reader.getString(); } else { reader.skipChildren(); } } - return new DuplicateRequiredProperty(duplicateRequiredProperty); + return new DuplicateRequiredProperty(requiredProperty, newRequiredProperty); }); } } diff --git a/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredPropertyParent.java b/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredPropertyParent.java index f936a25bb6..14989bc2da 100644 --- a/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredPropertyParent.java +++ b/typespec-tests/src/main/java/tsptest/subclass/models/DuplicateRequiredPropertyParent.java @@ -17,6 +17,12 @@ */ @Immutable public class DuplicateRequiredPropertyParent implements JsonSerializable { + /* + * The property property. + */ + @Generated + private final String requiredProperty; + /* * The duplicateRequiredProperty property. */ @@ -26,13 +32,25 @@ public class DuplicateRequiredPropertyParent implements JsonSerializable { + String requiredProperty = null; String duplicateRequiredProperty = null; while (reader.nextToken() != JsonToken.END_OBJECT) { String fieldName = reader.getFieldName(); reader.nextToken(); - if ("duplicateRequiredProperty".equals(fieldName)) { + if ("property".equals(fieldName)) { + requiredProperty = reader.getString(); + } else if ("duplicateRequiredProperty".equals(fieldName)) { duplicateRequiredProperty = reader.getString(); } else { reader.skipChildren(); } } - return new DuplicateRequiredPropertyParent(duplicateRequiredProperty); + return new DuplicateRequiredPropertyParent(requiredProperty, duplicateRequiredProperty); }); } } diff --git a/typespec-tests/tsp/subclass.tsp b/typespec-tests/tsp/subclass.tsp index 8afbf8e9d6..8f76d84f82 100644 --- a/typespec-tests/tsp/subclass.tsp +++ b/typespec-tests/tsp/subclass.tsp @@ -8,10 +8,14 @@ using TypeSpec.Http; namespace TspTest.Subclass; model DuplicateRequiredPropertyParent { + @encodedName("application/json", "property") + requiredProperty: string; + duplicateRequiredProperty: string; } model DuplicateRequiredProperty extends DuplicateRequiredPropertyParent { - duplicateRequiredProperty: string; + @encodedName("application/json", "duplicateRequiredProperty") + newRequiredProperty: string; } model PropertyChangedToRequiredParent {