diff --git a/core b/core index 8c4d64c094..e637e63d95 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 8c4d64c0943f9643308a6fd0bd98b5ea2aa57342 +Subproject commit e637e63d95a6c2149f4e0723c341ce3e47b7614c diff --git a/fluent-tests/Initialize-Tests.ps1 b/fluent-tests/Initialize-Tests.ps1 index 18fa3cef5c..0e35e5bcfb 100644 --- a/fluent-tests/Initialize-Tests.ps1 +++ b/fluent-tests/Initialize-Tests.ps1 @@ -158,6 +158,9 @@ $job = @( # special cases "--version=$AUTOREST_CORE_VERSION $FLUENTLITE_ARGUMENTS --regenerate-pom=false --input-file=./swagger/sync-stack.json --namespace=com.azure.mgmtlitetest.syncstack --enable-sync-stack=true" + # multiple PUTs under the same collection + "--version=$AUTOREST_CORE_VERSION $FLUENTLITE_ARGUMENTS --regenerate-pom=false --input-file=https://raw.githubusercontent.com/Azure/azure-rest-api-specs/980d7b8ba06697dd77b287a38aab617ad095f353/specification/providerhub/resource-manager/Microsoft.ProviderHub/stable/2024-09-01/providerhub.json --namespace=com.azure.mgmtlitetest.providerhub" + # "--version=$AUTOREST_CORE_VERSION $FLUENTLITE_ARGUMENTS --regenerate-pom=false https://raw.githubusercontent.com/Azure/azure-rest-api-specs/113b466bf76cd86da547beee5300d2ef5210cfb3/specification/network/resource-manager/readme.md --tag=package-2020-06 --java.namespace=com.azure.mgmtlitetest.network" # "--version=$AUTOREST_CORE_VERSION $FLUENTLITE_ARGUMENTS --regenerate-pom=false https://raw.githubusercontent.com/Azure/azure-rest-api-specs/113b466bf76cd86da547beee5300d2ef5210cfb3/specification/compute/resource-manager/readme.md --tag=package-2020-06-30 --java.namespace=com.azure.mgmtlitetest.compute" ) | ForEach-Object -Parallel $generateScript -ThrottleLimit $Parallelization -AsJob diff --git a/fluent-tests/src/test/java/com/azure/mgmttest/LiteCompilationTests.java b/fluent-tests/src/test/java/com/azure/mgmttest/LiteCompilationTests.java index 49aa59836d..21f5ca5871 100644 --- a/fluent-tests/src/test/java/com/azure/mgmttest/LiteCompilationTests.java +++ b/fluent-tests/src/test/java/com/azure/mgmttest/LiteCompilationTests.java @@ -21,6 +21,7 @@ import com.azure.mgmtlitetest.managednetworkfabric.models.CommonPostActionResponseForStateUpdate; import com.azure.mgmtlitetest.pageablewithinheritance.fluent.SavingsPlansClient; import com.azure.mgmtlitetest.pageablewithinheritance.fluent.models.SavingsPlanModelInner; +import com.azure.mgmtlitetest.providerhub.ProviderHubManager; import com.azure.mgmtlitetest.resources.ResourceManager; import com.azure.mgmtlitetest.resources.models.ResourceGroup; import com.azure.mgmtlitetest.storage.StorageManager; @@ -211,4 +212,11 @@ public void testSyncStack() { syncStackManager.normalPageables().list("name"); syncStackManager.normalPageables().list("name", "filter", Context.NONE); } + + public void testProviderHubSkuDefine() { + ProviderHubManager providerHubManager = mock(ProviderHubManager.class); + providerHubManager.skus().define("mySku") + .withExistingResourcetypeRegistration("My.Rp", "myResource") + .create(); + } } 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/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/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, + } + > {}