From 0077e4b19009f3363e603c106982c0b3db3a6c4b Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Thu, 16 Jan 2025 15:58:08 +0800 Subject: [PATCH] sync tests (#3013) --- .../OperationTemplatesManager.java | 33 + .../fluent/CheckNameAvailabilitiesClient.java | 71 ++ .../fluent/OperationTemplatesClient.java | 14 + .../fluent/OperationsClient.java | 40 + .../CheckNameAvailabilityResponseInner.java | 120 +++ .../fluent/models/OperationInner.java | 159 ++++ .../CheckNameAvailabilitiesClientImpl.java | 310 ++++++ .../CheckNameAvailabilitiesImpl.java | 79 ++ .../CheckNameAvailabilityResponseImpl.java | 41 + .../implementation/OperationImpl.java | 51 + .../OperationTemplatesClientImpl.java | 32 + .../implementation/OperationsClientImpl.java | 235 +++++ .../implementation/OperationsImpl.java | 45 + .../models/OperationListResult.java | 113 +++ .../operationtemplates/models/ActionType.java | 46 + .../models/CheckNameAvailabilities.java | 62 ++ .../models/CheckNameAvailabilityReason.java | 51 + .../models/CheckNameAvailabilityRequest.java | 121 +++ .../models/CheckNameAvailabilityResponse.java | 40 + .../operationtemplates/models/Operation.java | 58 ++ .../models/OperationDisplay.java | 136 +++ .../operationtemplates/models/Operations.java | 35 + .../operationtemplates/models/Origin.java | 57 ++ .../resources/ResourcesManager.java | 32 + .../fluent/ExtensionsResourcesClient.java | 194 ++++ .../fluent/LocationResourcesClient.java | 157 ++++ .../resources/fluent/ResourcesClient.java | 14 + .../models/ExtensionsResourceInner.java | 166 ++++ .../fluent/models/LocationResourceInner.java | 166 ++++ .../ExtensionsResourceImpl.java | 128 +++ .../ExtensionsResourcesClientImpl.java | 885 ++++++++++++++++++ .../ExtensionsResourcesImpl.java | 153 +++ .../implementation/LocationResourceImpl.java | 126 +++ .../LocationResourcesClientImpl.java | 813 ++++++++++++++++ .../implementation/LocationResourcesImpl.java | 136 +++ .../implementation/ResourcesClientImpl.java | 32 + .../models/ExtensionsResourceListResult.java | 114 +++ .../models/LocationResourceListResult.java | 114 +++ .../resources/models/ExtensionsResource.java | 180 ++++ .../models/ExtensionsResourceProperties.java | 110 +++ .../resources/models/ExtensionsResources.java | 140 +++ .../resources/models/LocationResource.java | 181 ++++ .../models/LocationResourceProperties.java | 110 +++ .../resources/models/LocationResources.java | 139 +++ .../ClientNamespaceFirstAsyncClient.java | 84 ++ .../ClientNamespaceFirstClient.java | 81 ++ .../ClientNamespaceFirstClientBuilder.java | 287 ++++++ .../first/models/FirstClientResult.java | 83 ++ .../first/models/package-info.java | 11 + .../ClientNamespaceFirstClientImpl.java | 196 ++++ .../ClientNamespaceSecondClientImpl.java | 196 ++++ .../implementation/package-info.java | 11 + .../clientnamespace}/package-info.java | 6 +- .../ClientNamespaceSecondAsyncClient.java | 84 ++ .../second/ClientNamespaceSecondClient.java | 81 ++ .../ClientNamespaceSecondClientBuilder.java | 287 ++++++ .../second/models/SecondClientResult.java | 84 ++ .../second/models/package-info.java | 11 + .../clientnamespace/second/package-info.java | 11 + .../sub/models/SecondClientEnumType.java | 51 + .../second/sub/models/package-info.java | 11 + .../payload/pageable/PageableAsyncClient.java | 55 +- .../java/payload/pageable/PageableClient.java | 36 +- .../ServerDrivenPaginationsImpl.java | 211 ++++- .../models/LinkResponse.java | 107 --- .../models/LinkResponseLinks.java | 137 --- .../implementation/ResponseClientImpl.java | 16 +- .../response/models/OperationDetails2.java | 22 +- .../proxy-config.json | 2 +- .../proxy-config.json | 2 +- .../client-clientnamespace.properties | 2 + .../operationtemplates/OperationTests.java | 61 ++ .../clientnamespace/NamespaceTests.java | 31 + .../ClientNamespaceSecondClientTestBase.java | 47 + typespec-tests/tsp/lro.tsp | 2 + typespec-tests/tsp/response.tsp | 8 +- 76 files changed, 8004 insertions(+), 349 deletions(-) create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/CheckNameAvailabilitiesClient.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/OperationsClient.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/models/CheckNameAvailabilityResponseInner.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/models/OperationInner.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/CheckNameAvailabilitiesClientImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/CheckNameAvailabilitiesImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/CheckNameAvailabilityResponseImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationsClientImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationsImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/models/OperationListResult.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/ActionType.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilities.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilityReason.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilityRequest.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilityResponse.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/Operation.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/OperationDisplay.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/Operations.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/Origin.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/ExtensionsResourcesClient.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/LocationResourcesClient.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/models/ExtensionsResourceInner.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/models/LocationResourceInner.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ExtensionsResourceImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ExtensionsResourcesClientImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ExtensionsResourcesImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/LocationResourceImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/LocationResourcesClientImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/LocationResourcesImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/models/ExtensionsResourceListResult.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/models/LocationResourceListResult.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/models/ExtensionsResource.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/models/ExtensionsResourceProperties.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/models/ExtensionsResources.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/models/LocationResource.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/models/LocationResourceProperties.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/resources/models/LocationResources.java create mode 100644 typespec-tests/src/main/java/client/clientnamespace/ClientNamespaceFirstAsyncClient.java create mode 100644 typespec-tests/src/main/java/client/clientnamespace/ClientNamespaceFirstClient.java create mode 100644 typespec-tests/src/main/java/client/clientnamespace/ClientNamespaceFirstClientBuilder.java create mode 100644 typespec-tests/src/main/java/client/clientnamespace/first/models/FirstClientResult.java create mode 100644 typespec-tests/src/main/java/client/clientnamespace/first/models/package-info.java create mode 100644 typespec-tests/src/main/java/client/clientnamespace/implementation/ClientNamespaceFirstClientImpl.java create mode 100644 typespec-tests/src/main/java/client/clientnamespace/implementation/ClientNamespaceSecondClientImpl.java create mode 100644 typespec-tests/src/main/java/client/clientnamespace/implementation/package-info.java rename typespec-tests/src/main/java/{payload/pageable/serverdrivenpagination/models => client/clientnamespace}/package-info.java (62%) create mode 100644 typespec-tests/src/main/java/client/clientnamespace/second/ClientNamespaceSecondAsyncClient.java create mode 100644 typespec-tests/src/main/java/client/clientnamespace/second/ClientNamespaceSecondClient.java create mode 100644 typespec-tests/src/main/java/client/clientnamespace/second/ClientNamespaceSecondClientBuilder.java create mode 100644 typespec-tests/src/main/java/client/clientnamespace/second/models/SecondClientResult.java create mode 100644 typespec-tests/src/main/java/client/clientnamespace/second/models/package-info.java create mode 100644 typespec-tests/src/main/java/client/clientnamespace/second/package-info.java create mode 100644 typespec-tests/src/main/java/client/clientnamespace/second/sub/models/SecondClientEnumType.java create mode 100644 typespec-tests/src/main/java/client/clientnamespace/second/sub/models/package-info.java delete mode 100644 typespec-tests/src/main/java/payload/pageable/serverdrivenpagination/models/LinkResponse.java delete mode 100644 typespec-tests/src/main/java/payload/pageable/serverdrivenpagination/models/LinkResponseLinks.java create mode 100644 typespec-tests/src/main/resources/client-clientnamespace.properties create mode 100644 typespec-tests/src/test/java/azure/resourcemanager/operationtemplates/OperationTests.java create mode 100644 typespec-tests/src/test/java/client/clientnamespace/NamespaceTests.java create mode 100644 typespec-tests/src/test/java/client/clientnamespace/generated/ClientNamespaceSecondClientTestBase.java diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/OperationTemplatesManager.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/OperationTemplatesManager.java index ac8c0311ec..1447513233 100644 --- a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/OperationTemplatesManager.java +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/OperationTemplatesManager.java @@ -5,9 +5,13 @@ package azure.resourcemanager.operationtemplates; import azure.resourcemanager.operationtemplates.fluent.OperationTemplatesClient; +import azure.resourcemanager.operationtemplates.implementation.CheckNameAvailabilitiesImpl; import azure.resourcemanager.operationtemplates.implementation.LroesImpl; import azure.resourcemanager.operationtemplates.implementation.OperationTemplatesClientBuilder; +import azure.resourcemanager.operationtemplates.implementation.OperationsImpl; +import azure.resourcemanager.operationtemplates.models.CheckNameAvailabilities; import azure.resourcemanager.operationtemplates.models.Lroes; +import azure.resourcemanager.operationtemplates.models.Operations; import com.azure.core.credential.TokenCredential; import com.azure.core.http.HttpClient; import com.azure.core.http.HttpPipeline; @@ -39,6 +43,10 @@ * Arm Resource Provider management API. */ public final class OperationTemplatesManager { + private Operations operations; + + private CheckNameAvailabilities checkNameAvailabilities; + private Lroes lroes; private final OperationTemplatesClient clientObject; @@ -251,6 +259,31 @@ public OperationTemplatesManager authenticate(TokenCredential credential, AzureP } } + /** + * Gets the resource collection API of Operations. + * + * @return Resource collection API of Operations. + */ + public Operations operations() { + if (this.operations == null) { + this.operations = new OperationsImpl(clientObject.getOperations(), this); + } + return operations; + } + + /** + * Gets the resource collection API of CheckNameAvailabilities. + * + * @return Resource collection API of CheckNameAvailabilities. + */ + public CheckNameAvailabilities checkNameAvailabilities() { + if (this.checkNameAvailabilities == null) { + this.checkNameAvailabilities + = new CheckNameAvailabilitiesImpl(clientObject.getCheckNameAvailabilities(), this); + } + return checkNameAvailabilities; + } + /** * Gets the resource collection API of Lroes. It manages Order. * diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/CheckNameAvailabilitiesClient.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/CheckNameAvailabilitiesClient.java new file mode 100644 index 0000000000..5707564b00 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/CheckNameAvailabilitiesClient.java @@ -0,0 +1,71 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.fluent; + +import azure.resourcemanager.operationtemplates.fluent.models.CheckNameAvailabilityResponseInner; +import azure.resourcemanager.operationtemplates.models.CheckNameAvailabilityRequest; +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; + +/** + * An instance of this class provides access to all the operations defined in CheckNameAvailabilitiesClient. + */ +public interface CheckNameAvailabilitiesClient { + /** + * Implements global CheckNameAvailability operations. + * + * @param body The CheckAvailability request. + * @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 check availability result along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response checkGlobalWithResponse(CheckNameAvailabilityRequest body, + Context context); + + /** + * Implements global CheckNameAvailability operations. + * + * @param body The CheckAvailability request. + * @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 check availability result. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + CheckNameAvailabilityResponseInner checkGlobal(CheckNameAvailabilityRequest body); + + /** + * Implements local CheckNameAvailability operations. + * + * @param location The name of the Azure region. + * @param body The CheckAvailability request. + * @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 check availability result along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response checkLocalWithResponse(String location, + CheckNameAvailabilityRequest body, Context context); + + /** + * Implements local CheckNameAvailability operations. + * + * @param location The name of the Azure region. + * @param body The CheckAvailability request. + * @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 check availability result. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + CheckNameAvailabilityResponseInner checkLocal(String location, CheckNameAvailabilityRequest body); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/OperationTemplatesClient.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/OperationTemplatesClient.java index 523746cba2..21c5e935dd 100644 --- a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/OperationTemplatesClient.java +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/OperationTemplatesClient.java @@ -46,6 +46,20 @@ public interface OperationTemplatesClient { */ Duration getDefaultPollInterval(); + /** + * Gets the OperationsClient object to access its operations. + * + * @return the OperationsClient object. + */ + OperationsClient getOperations(); + + /** + * Gets the CheckNameAvailabilitiesClient object to access its operations. + * + * @return the CheckNameAvailabilitiesClient object. + */ + CheckNameAvailabilitiesClient getCheckNameAvailabilities(); + /** * Gets the LroesClient object to access its operations. * diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/OperationsClient.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/OperationsClient.java new file mode 100644 index 0000000000..86e9ca7219 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/OperationsClient.java @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.fluent; + +import azure.resourcemanager.operationtemplates.fluent.models.OperationInner; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.util.Context; + +/** + * An instance of this class provides access to all the operations defined in OperationsClient. + */ +public interface OperationsClient { + /** + * List the operations for the provider. + * + * @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 list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable list(); + + /** + * List the operations for the provider. + * + * @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 list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable list(Context context); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/models/CheckNameAvailabilityResponseInner.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/models/CheckNameAvailabilityResponseInner.java new file mode 100644 index 0000000000..40eb0dec93 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/models/CheckNameAvailabilityResponseInner.java @@ -0,0 +1,120 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.fluent.models; + +import azure.resourcemanager.operationtemplates.models.CheckNameAvailabilityReason; +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 check availability result. + */ +@Immutable +public final class CheckNameAvailabilityResponseInner implements JsonSerializable { + /* + * Indicates if the resource name is available. + */ + private Boolean nameAvailable; + + /* + * The reason why the given name is not available. + */ + private CheckNameAvailabilityReason reason; + + /* + * Detailed reason why the given name is not available. + */ + private String message; + + /** + * Creates an instance of CheckNameAvailabilityResponseInner class. + */ + private CheckNameAvailabilityResponseInner() { + } + + /** + * Get the nameAvailable property: Indicates if the resource name is available. + * + * @return the nameAvailable value. + */ + public Boolean nameAvailable() { + return this.nameAvailable; + } + + /** + * Get the reason property: The reason why the given name is not available. + * + * @return the reason value. + */ + public CheckNameAvailabilityReason reason() { + return this.reason; + } + + /** + * Get the message property: Detailed reason why the given name is not available. + * + * @return the message value. + */ + public String message() { + return this.message; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeBooleanField("nameAvailable", this.nameAvailable); + jsonWriter.writeStringField("reason", this.reason == null ? null : this.reason.toString()); + jsonWriter.writeStringField("message", this.message); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of CheckNameAvailabilityResponseInner from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of CheckNameAvailabilityResponseInner 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 CheckNameAvailabilityResponseInner. + */ + public static CheckNameAvailabilityResponseInner fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + CheckNameAvailabilityResponseInner deserializedCheckNameAvailabilityResponseInner + = new CheckNameAvailabilityResponseInner(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("nameAvailable".equals(fieldName)) { + deserializedCheckNameAvailabilityResponseInner.nameAvailable + = reader.getNullable(JsonReader::getBoolean); + } else if ("reason".equals(fieldName)) { + deserializedCheckNameAvailabilityResponseInner.reason + = CheckNameAvailabilityReason.fromString(reader.getString()); + } else if ("message".equals(fieldName)) { + deserializedCheckNameAvailabilityResponseInner.message = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedCheckNameAvailabilityResponseInner; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/models/OperationInner.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/models/OperationInner.java new file mode 100644 index 0000000000..4d0862ff01 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/fluent/models/OperationInner.java @@ -0,0 +1,159 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.fluent.models; + +import azure.resourcemanager.operationtemplates.models.ActionType; +import azure.resourcemanager.operationtemplates.models.OperationDisplay; +import azure.resourcemanager.operationtemplates.models.Origin; +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; + +/** + * Details of a REST API operation, returned from the Resource Provider Operations API. + */ +@Immutable +public final class OperationInner implements JsonSerializable { + /* + * The name of the operation, as per Resource-Based Access Control (RBAC). Examples: + * "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action" + */ + private String name; + + /* + * Whether the operation applies to data-plane. This is "true" for data-plane operations and "false" for Azure + * Resource Manager/control-plane operations. + */ + private Boolean isDataAction; + + /* + * Localized display information for this particular operation. + */ + private OperationDisplay display; + + /* + * The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default + * value is "user,system" + */ + private Origin origin; + + /* + * Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + */ + private ActionType actionType; + + /** + * Creates an instance of OperationInner class. + */ + private OperationInner() { + } + + /** + * Get the name property: The name of the operation, as per Resource-Based Access Control (RBAC). Examples: + * "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action". + * + * @return the name value. + */ + public String name() { + return this.name; + } + + /** + * Get the isDataAction property: Whether the operation applies to data-plane. This is "true" for data-plane + * operations and "false" for Azure Resource Manager/control-plane operations. + * + * @return the isDataAction value. + */ + public Boolean isDataAction() { + return this.isDataAction; + } + + /** + * Get the display property: Localized display information for this particular operation. + * + * @return the display value. + */ + public OperationDisplay display() { + return this.display; + } + + /** + * Get the origin property: The intended executor of the operation; as in Resource Based Access Control (RBAC) and + * audit logs UX. Default value is "user,system". + * + * @return the origin value. + */ + public Origin origin() { + return this.origin; + } + + /** + * Get the actionType property: Extensible enum. Indicates the action type. "Internal" refers to actions that are + * for internal only APIs. + * + * @return the actionType value. + */ + public ActionType actionType() { + return this.actionType; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + if (display() != null) { + display().validate(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("display", this.display); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of OperationInner from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of OperationInner 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 OperationInner. + */ + public static OperationInner fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + OperationInner deserializedOperationInner = new OperationInner(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("name".equals(fieldName)) { + deserializedOperationInner.name = reader.getString(); + } else if ("isDataAction".equals(fieldName)) { + deserializedOperationInner.isDataAction = reader.getNullable(JsonReader::getBoolean); + } else if ("display".equals(fieldName)) { + deserializedOperationInner.display = OperationDisplay.fromJson(reader); + } else if ("origin".equals(fieldName)) { + deserializedOperationInner.origin = Origin.fromString(reader.getString()); + } else if ("actionType".equals(fieldName)) { + deserializedOperationInner.actionType = ActionType.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + + return deserializedOperationInner; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/CheckNameAvailabilitiesClientImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/CheckNameAvailabilitiesClientImpl.java new file mode 100644 index 0000000000..513dcd0fc6 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/CheckNameAvailabilitiesClientImpl.java @@ -0,0 +1,310 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.implementation; + +import azure.resourcemanager.operationtemplates.fluent.CheckNameAvailabilitiesClient; +import azure.resourcemanager.operationtemplates.fluent.models.CheckNameAvailabilityResponseInner; +import azure.resourcemanager.operationtemplates.models.CheckNameAvailabilityRequest; +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Post; +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; + +/** + * An instance of this class provides access to all the operations defined in CheckNameAvailabilitiesClient. + */ +public final class CheckNameAvailabilitiesClientImpl implements CheckNameAvailabilitiesClient { + /** + * The proxy service used to perform REST calls. + */ + private final CheckNameAvailabilitiesService service; + + /** + * The service client containing this operation class. + */ + private final OperationTemplatesClientImpl client; + + /** + * Initializes an instance of CheckNameAvailabilitiesClientImpl. + * + * @param client the instance of the service client containing this operation class. + */ + CheckNameAvailabilitiesClientImpl(OperationTemplatesClientImpl client) { + this.service = RestProxy.create(CheckNameAvailabilitiesService.class, client.getHttpPipeline(), + client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for OperationTemplatesClientCheckNameAvailabilities to be used by the + * proxy service to perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "OperationTemplatesCl") + public interface CheckNameAvailabilitiesService { + @Post("/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.OperationTemplates/checkNameAvailability") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> checkGlobal(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") CheckNameAvailabilityRequest body, Context context); + + @Post("/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.OperationTemplates/locations/{location}/checkNameAvailability") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> checkLocal(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("location") String location, @HeaderParam("Content-Type") String contentType, + @HeaderParam("Accept") String accept, @BodyParam("application/json") CheckNameAvailabilityRequest body, + Context context); + } + + /** + * Implements global CheckNameAvailability operations. + * + * @param body The CheckAvailability request. + * @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 check availability result along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> + checkGlobalWithResponseAsync(CheckNameAvailabilityRequest body) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } else { + body.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.checkGlobal(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), contentType, accept, body, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Implements global CheckNameAvailability operations. + * + * @param body The CheckAvailability request. + * @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 check availability result along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> + checkGlobalWithResponseAsync(CheckNameAvailabilityRequest body, Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } else { + body.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.checkGlobal(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), contentType, accept, body, context); + } + + /** + * Implements global CheckNameAvailability operations. + * + * @param body The CheckAvailability request. + * @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 check availability result on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono checkGlobalAsync(CheckNameAvailabilityRequest body) { + return checkGlobalWithResponseAsync(body).flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Implements global CheckNameAvailability operations. + * + * @param body The CheckAvailability request. + * @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 check availability result along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response checkGlobalWithResponse(CheckNameAvailabilityRequest body, + Context context) { + return checkGlobalWithResponseAsync(body, context).block(); + } + + /** + * Implements global CheckNameAvailability operations. + * + * @param body The CheckAvailability request. + * @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 check availability result. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public CheckNameAvailabilityResponseInner checkGlobal(CheckNameAvailabilityRequest body) { + return checkGlobalWithResponse(body, Context.NONE).getValue(); + } + + /** + * Implements local CheckNameAvailability operations. + * + * @param location The name of the Azure region. + * @param body The CheckAvailability request. + * @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 check availability result along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> checkLocalWithResponseAsync(String location, + CheckNameAvailabilityRequest body) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (location == null) { + return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } else { + body.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.checkLocal(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), location, contentType, accept, body, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Implements local CheckNameAvailability operations. + * + * @param location The name of the Azure region. + * @param body The CheckAvailability request. + * @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 check availability result along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> checkLocalWithResponseAsync(String location, + CheckNameAvailabilityRequest body, Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (location == null) { + return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null.")); + } + if (body == null) { + return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null.")); + } else { + body.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.checkLocal(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), location, contentType, accept, body, context); + } + + /** + * Implements local CheckNameAvailability operations. + * + * @param location The name of the Azure region. + * @param body The CheckAvailability request. + * @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 check availability result on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono checkLocalAsync(String location, + CheckNameAvailabilityRequest body) { + return checkLocalWithResponseAsync(location, body).flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Implements local CheckNameAvailability operations. + * + * @param location The name of the Azure region. + * @param body The CheckAvailability request. + * @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 check availability result along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response checkLocalWithResponse(String location, + CheckNameAvailabilityRequest body, Context context) { + return checkLocalWithResponseAsync(location, body, context).block(); + } + + /** + * Implements local CheckNameAvailability operations. + * + * @param location The name of the Azure region. + * @param body The CheckAvailability request. + * @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 check availability result. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public CheckNameAvailabilityResponseInner checkLocal(String location, CheckNameAvailabilityRequest body) { + return checkLocalWithResponse(location, body, Context.NONE).getValue(); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/CheckNameAvailabilitiesImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/CheckNameAvailabilitiesImpl.java new file mode 100644 index 0000000000..bba72824e0 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/CheckNameAvailabilitiesImpl.java @@ -0,0 +1,79 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.implementation; + +import azure.resourcemanager.operationtemplates.fluent.CheckNameAvailabilitiesClient; +import azure.resourcemanager.operationtemplates.fluent.models.CheckNameAvailabilityResponseInner; +import azure.resourcemanager.operationtemplates.models.CheckNameAvailabilities; +import azure.resourcemanager.operationtemplates.models.CheckNameAvailabilityRequest; +import azure.resourcemanager.operationtemplates.models.CheckNameAvailabilityResponse; +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; + +public final class CheckNameAvailabilitiesImpl implements CheckNameAvailabilities { + private static final ClientLogger LOGGER = new ClientLogger(CheckNameAvailabilitiesImpl.class); + + private final CheckNameAvailabilitiesClient innerClient; + + private final azure.resourcemanager.operationtemplates.OperationTemplatesManager serviceManager; + + public CheckNameAvailabilitiesImpl(CheckNameAvailabilitiesClient innerClient, + azure.resourcemanager.operationtemplates.OperationTemplatesManager serviceManager) { + this.innerClient = innerClient; + this.serviceManager = serviceManager; + } + + public Response checkGlobalWithResponse(CheckNameAvailabilityRequest body, + Context context) { + Response inner + = this.serviceClient().checkGlobalWithResponse(body, context); + if (inner != null) { + return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(), + new CheckNameAvailabilityResponseImpl(inner.getValue(), this.manager())); + } else { + return null; + } + } + + public CheckNameAvailabilityResponse checkGlobal(CheckNameAvailabilityRequest body) { + CheckNameAvailabilityResponseInner inner = this.serviceClient().checkGlobal(body); + if (inner != null) { + return new CheckNameAvailabilityResponseImpl(inner, this.manager()); + } else { + return null; + } + } + + public Response checkLocalWithResponse(String location, + CheckNameAvailabilityRequest body, Context context) { + Response inner + = this.serviceClient().checkLocalWithResponse(location, body, context); + if (inner != null) { + return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(), + new CheckNameAvailabilityResponseImpl(inner.getValue(), this.manager())); + } else { + return null; + } + } + + public CheckNameAvailabilityResponse checkLocal(String location, CheckNameAvailabilityRequest body) { + CheckNameAvailabilityResponseInner inner = this.serviceClient().checkLocal(location, body); + if (inner != null) { + return new CheckNameAvailabilityResponseImpl(inner, this.manager()); + } else { + return null; + } + } + + private CheckNameAvailabilitiesClient serviceClient() { + return this.innerClient; + } + + private azure.resourcemanager.operationtemplates.OperationTemplatesManager manager() { + return this.serviceManager; + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/CheckNameAvailabilityResponseImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/CheckNameAvailabilityResponseImpl.java new file mode 100644 index 0000000000..af6750562f --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/CheckNameAvailabilityResponseImpl.java @@ -0,0 +1,41 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.implementation; + +import azure.resourcemanager.operationtemplates.fluent.models.CheckNameAvailabilityResponseInner; +import azure.resourcemanager.operationtemplates.models.CheckNameAvailabilityReason; +import azure.resourcemanager.operationtemplates.models.CheckNameAvailabilityResponse; + +public final class CheckNameAvailabilityResponseImpl implements CheckNameAvailabilityResponse { + private CheckNameAvailabilityResponseInner innerObject; + + private final azure.resourcemanager.operationtemplates.OperationTemplatesManager serviceManager; + + CheckNameAvailabilityResponseImpl(CheckNameAvailabilityResponseInner innerObject, + azure.resourcemanager.operationtemplates.OperationTemplatesManager serviceManager) { + this.innerObject = innerObject; + this.serviceManager = serviceManager; + } + + public Boolean nameAvailable() { + return this.innerModel().nameAvailable(); + } + + public CheckNameAvailabilityReason reason() { + return this.innerModel().reason(); + } + + public String message() { + return this.innerModel().message(); + } + + public CheckNameAvailabilityResponseInner innerModel() { + return this.innerObject; + } + + private azure.resourcemanager.operationtemplates.OperationTemplatesManager manager() { + return this.serviceManager; + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationImpl.java new file mode 100644 index 0000000000..9c65f9a5f5 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationImpl.java @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.implementation; + +import azure.resourcemanager.operationtemplates.fluent.models.OperationInner; +import azure.resourcemanager.operationtemplates.models.ActionType; +import azure.resourcemanager.operationtemplates.models.Operation; +import azure.resourcemanager.operationtemplates.models.OperationDisplay; +import azure.resourcemanager.operationtemplates.models.Origin; + +public final class OperationImpl implements Operation { + private OperationInner innerObject; + + private final azure.resourcemanager.operationtemplates.OperationTemplatesManager serviceManager; + + OperationImpl(OperationInner innerObject, + azure.resourcemanager.operationtemplates.OperationTemplatesManager serviceManager) { + this.innerObject = innerObject; + this.serviceManager = serviceManager; + } + + public String name() { + return this.innerModel().name(); + } + + public Boolean isDataAction() { + return this.innerModel().isDataAction(); + } + + public OperationDisplay display() { + return this.innerModel().display(); + } + + public Origin origin() { + return this.innerModel().origin(); + } + + public ActionType actionType() { + return this.innerModel().actionType(); + } + + public OperationInner innerModel() { + return this.innerObject; + } + + private azure.resourcemanager.operationtemplates.OperationTemplatesManager manager() { + return this.serviceManager; + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationTemplatesClientImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationTemplatesClientImpl.java index aa23fb9452..91aafbc468 100644 --- a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationTemplatesClientImpl.java +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationTemplatesClientImpl.java @@ -4,8 +4,10 @@ package azure.resourcemanager.operationtemplates.implementation; +import azure.resourcemanager.operationtemplates.fluent.CheckNameAvailabilitiesClient; import azure.resourcemanager.operationtemplates.fluent.LroesClient; import azure.resourcemanager.operationtemplates.fluent.OperationTemplatesClient; +import azure.resourcemanager.operationtemplates.fluent.OperationsClient; import com.azure.core.annotation.ServiceClient; import com.azure.core.http.HttpHeaderName; import com.azure.core.http.HttpHeaders; @@ -123,6 +125,34 @@ public Duration getDefaultPollInterval() { return this.defaultPollInterval; } + /** + * The OperationsClient object to access its operations. + */ + private final OperationsClient operations; + + /** + * Gets the OperationsClient object to access its operations. + * + * @return the OperationsClient object. + */ + public OperationsClient getOperations() { + return this.operations; + } + + /** + * The CheckNameAvailabilitiesClient object to access its operations. + */ + private final CheckNameAvailabilitiesClient checkNameAvailabilities; + + /** + * Gets the CheckNameAvailabilitiesClient object to access its operations. + * + * @return the CheckNameAvailabilitiesClient object. + */ + public CheckNameAvailabilitiesClient getCheckNameAvailabilities() { + return this.checkNameAvailabilities; + } + /** * The LroesClient object to access its operations. */ @@ -155,6 +185,8 @@ public LroesClient getLroes() { this.endpoint = endpoint; this.subscriptionId = subscriptionId; this.apiVersion = "2023-12-01-preview"; + this.operations = new OperationsClientImpl(this); + this.checkNameAvailabilities = new CheckNameAvailabilitiesClientImpl(this); this.lroes = new LroesClientImpl(this); } diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationsClientImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationsClientImpl.java new file mode 100644 index 0000000000..006bc7da23 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationsClientImpl.java @@ -0,0 +1,235 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.implementation; + +import azure.resourcemanager.operationtemplates.fluent.OperationsClient; +import azure.resourcemanager.operationtemplates.fluent.models.OperationInner; +import azure.resourcemanager.operationtemplates.implementation.models.OperationListResult; +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.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.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.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; + +/** + * An instance of this class provides access to all the operations defined in OperationsClient. + */ +public final class OperationsClientImpl implements OperationsClient { + /** + * The proxy service used to perform REST calls. + */ + private final OperationsService service; + + /** + * The service client containing this operation class. + */ + private final OperationTemplatesClientImpl client; + + /** + * Initializes an instance of OperationsClientImpl. + * + * @param client the instance of the service client containing this operation class. + */ + OperationsClientImpl(OperationTemplatesClientImpl client) { + this.service + = RestProxy.create(OperationsService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for OperationTemplatesClientOperations to be used by the proxy service to + * perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "OperationTemplatesCl") + public interface OperationsService { + @Headers({ "Content-Type: application/json" }) + @Get("/providers/Azure.ResourceManager.OperationTemplates/operations") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> list(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> listNext(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, Context context); + } + + /** + * List the operations for the provider. + * + * @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 list of REST API operations supported by an Azure Resource Provider along with {@link PagedResponse} on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listSinglePageAsync() { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.list(this.client.getEndpoint(), this.client.getApiVersion(), accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), + res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * List the operations for the provider. + * + * @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 list of REST API operations supported by an Azure Resource Provider along with {@link PagedResponse} on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listSinglePageAsync(Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.list(this.client.getEndpoint(), this.client.getApiVersion(), accept, context) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + res.getValue().value(), res.getValue().nextLink(), null)); + } + + /** + * List the operations for the provider. + * + * @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 list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listAsync() { + return new PagedFlux<>(() -> listSinglePageAsync(), nextLink -> listNextSinglePageAsync(nextLink)); + } + + /** + * List the operations for the provider. + * + * @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 list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listAsync(Context context) { + return new PagedFlux<>(() -> listSinglePageAsync(context), + nextLink -> listNextSinglePageAsync(nextLink, context)); + } + + /** + * List the operations for the provider. + * + * @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 list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable list() { + return new PagedIterable<>(listAsync()); + } + + /** + * List the operations for the provider. + * + * @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 list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable list(Context context) { + return new PagedIterable<>(listAsync(context)); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @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 list of REST API operations supported by an Azure Resource Provider along with {@link PagedResponse} on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listNextSinglePageAsync(String nextLink) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.listNext(nextLink, this.client.getEndpoint(), accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), + res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @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 list of REST API operations supported by an Azure Resource Provider along with {@link PagedResponse} on + * successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listNextSinglePageAsync(String nextLink, Context context) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.listNext(nextLink, this.client.getEndpoint(), accept, context) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + res.getValue().value(), res.getValue().nextLink(), null)); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationsImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationsImpl.java new file mode 100644 index 0000000000..387ffe7c33 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/OperationsImpl.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.implementation; + +import azure.resourcemanager.operationtemplates.fluent.OperationsClient; +import azure.resourcemanager.operationtemplates.fluent.models.OperationInner; +import azure.resourcemanager.operationtemplates.models.Operation; +import azure.resourcemanager.operationtemplates.models.Operations; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.util.Context; +import com.azure.core.util.logging.ClientLogger; + +public final class OperationsImpl implements Operations { + private static final ClientLogger LOGGER = new ClientLogger(OperationsImpl.class); + + private final OperationsClient innerClient; + + private final azure.resourcemanager.operationtemplates.OperationTemplatesManager serviceManager; + + public OperationsImpl(OperationsClient innerClient, + azure.resourcemanager.operationtemplates.OperationTemplatesManager serviceManager) { + this.innerClient = innerClient; + this.serviceManager = serviceManager; + } + + public PagedIterable list() { + PagedIterable inner = this.serviceClient().list(); + return ResourceManagerUtils.mapPage(inner, inner1 -> new OperationImpl(inner1, this.manager())); + } + + public PagedIterable list(Context context) { + PagedIterable inner = this.serviceClient().list(context); + return ResourceManagerUtils.mapPage(inner, inner1 -> new OperationImpl(inner1, this.manager())); + } + + private OperationsClient serviceClient() { + return this.innerClient; + } + + private azure.resourcemanager.operationtemplates.OperationTemplatesManager manager() { + return this.serviceManager; + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/models/OperationListResult.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/models/OperationListResult.java new file mode 100644 index 0000000000..d7a93edbc8 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/implementation/models/OperationListResult.java @@ -0,0 +1,113 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.implementation.models; + +import azure.resourcemanager.operationtemplates.fluent.models.OperationInner; +import com.azure.core.annotation.Immutable; +import com.azure.core.util.logging.ClientLogger; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.List; + +/** + * A list of REST API operations supported by an Azure Resource Provider. It contains an URL link to get the next set of + * results. + */ +@Immutable +public final class OperationListResult implements JsonSerializable { + /* + * The Operation items on this page + */ + private List value; + + /* + * The link to the next page of items + */ + private String nextLink; + + /** + * Creates an instance of OperationListResult class. + */ + private OperationListResult() { + } + + /** + * Get the value property: The Operation items on this page. + * + * @return the value value. + */ + public List value() { + return this.value; + } + + /** + * Get the nextLink property: The link to the next page of items. + * + * @return the nextLink value. + */ + public String nextLink() { + return this.nextLink; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + if (value() == null) { + throw LOGGER.atError() + .log(new IllegalArgumentException("Missing required property value in model OperationListResult")); + } else { + value().forEach(e -> e.validate()); + } + } + + private static final ClientLogger LOGGER = new ClientLogger(OperationListResult.class); + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("value", this.value, (writer, element) -> writer.writeJson(element)); + jsonWriter.writeStringField("nextLink", this.nextLink); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of OperationListResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of OperationListResult 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 OperationListResult. + */ + public static OperationListResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + OperationListResult deserializedOperationListResult = new OperationListResult(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + List value = reader.readArray(reader1 -> OperationInner.fromJson(reader1)); + deserializedOperationListResult.value = value; + } else if ("nextLink".equals(fieldName)) { + deserializedOperationListResult.nextLink = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedOperationListResult; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/ActionType.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/ActionType.java new file mode 100644 index 0000000000..4f43f52a48 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/ActionType.java @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * Extensible enum. Indicates the action type. "Internal" refers to actions that are for internal only APIs. + */ +public final class ActionType extends ExpandableStringEnum { + /** + * Actions are for internal-only APIs. + */ + public static final ActionType INTERNAL = fromString("Internal"); + + /** + * Creates a new instance of ActionType value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public ActionType() { + } + + /** + * Creates or finds a ActionType from its string representation. + * + * @param name a name to look for. + * @return the corresponding ActionType. + */ + public static ActionType fromString(String name) { + return fromString(name, ActionType.class); + } + + /** + * Gets known ActionType values. + * + * @return known ActionType values. + */ + public static Collection values() { + return values(ActionType.class); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilities.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilities.java new file mode 100644 index 0000000000..a4daf29895 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilities.java @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.models; + +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; + +/** + * Resource collection API of CheckNameAvailabilities. + */ +public interface CheckNameAvailabilities { + /** + * Implements global CheckNameAvailability operations. + * + * @param body The CheckAvailability request. + * @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 check availability result along with {@link Response}. + */ + Response checkGlobalWithResponse(CheckNameAvailabilityRequest body, Context context); + + /** + * Implements global CheckNameAvailability operations. + * + * @param body The CheckAvailability request. + * @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 check availability result. + */ + CheckNameAvailabilityResponse checkGlobal(CheckNameAvailabilityRequest body); + + /** + * Implements local CheckNameAvailability operations. + * + * @param location The name of the Azure region. + * @param body The CheckAvailability request. + * @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 check availability result along with {@link Response}. + */ + Response checkLocalWithResponse(String location, CheckNameAvailabilityRequest body, + Context context); + + /** + * Implements local CheckNameAvailability operations. + * + * @param location The name of the Azure region. + * @param body The CheckAvailability request. + * @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 check availability result. + */ + CheckNameAvailabilityResponse checkLocal(String location, CheckNameAvailabilityRequest body); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilityReason.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilityReason.java new file mode 100644 index 0000000000..1e2fc96ba7 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilityReason.java @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * Possible reasons for a name not being available. + */ +public final class CheckNameAvailabilityReason extends ExpandableStringEnum { + /** + * Name is invalid. + */ + public static final CheckNameAvailabilityReason INVALID = fromString("Invalid"); + + /** + * Name already exists. + */ + public static final CheckNameAvailabilityReason ALREADY_EXISTS = fromString("AlreadyExists"); + + /** + * Creates a new instance of CheckNameAvailabilityReason value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public CheckNameAvailabilityReason() { + } + + /** + * Creates or finds a CheckNameAvailabilityReason from its string representation. + * + * @param name a name to look for. + * @return the corresponding CheckNameAvailabilityReason. + */ + public static CheckNameAvailabilityReason fromString(String name) { + return fromString(name, CheckNameAvailabilityReason.class); + } + + /** + * Gets known CheckNameAvailabilityReason values. + * + * @return known CheckNameAvailabilityReason values. + */ + public static Collection values() { + return values(CheckNameAvailabilityReason.class); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilityRequest.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilityRequest.java new file mode 100644 index 0000000000..1b24b23f5a --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilityRequest.java @@ -0,0 +1,121 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.models; + +import com.azure.core.annotation.Fluent; +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 check availability request body. + */ +@Fluent +public final class CheckNameAvailabilityRequest implements JsonSerializable { + /* + * The name of the resource for which availability needs to be checked. + */ + private String name; + + /* + * The resource type. + */ + private String type; + + /** + * Creates an instance of CheckNameAvailabilityRequest class. + */ + public CheckNameAvailabilityRequest() { + } + + /** + * Get the name property: The name of the resource for which availability needs to be checked. + * + * @return the name value. + */ + public String name() { + return this.name; + } + + /** + * Set the name property: The name of the resource for which availability needs to be checked. + * + * @param name the name value to set. + * @return the CheckNameAvailabilityRequest object itself. + */ + public CheckNameAvailabilityRequest withName(String name) { + this.name = name; + return this; + } + + /** + * Get the type property: The resource type. + * + * @return the type value. + */ + public String type() { + return this.type; + } + + /** + * Set the type property: The resource type. + * + * @param type the type value to set. + * @return the CheckNameAvailabilityRequest object itself. + */ + public CheckNameAvailabilityRequest withType(String type) { + this.type = type; + return this; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("name", this.name); + jsonWriter.writeStringField("type", this.type); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of CheckNameAvailabilityRequest from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of CheckNameAvailabilityRequest 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 CheckNameAvailabilityRequest. + */ + public static CheckNameAvailabilityRequest fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + CheckNameAvailabilityRequest deserializedCheckNameAvailabilityRequest = new CheckNameAvailabilityRequest(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("name".equals(fieldName)) { + deserializedCheckNameAvailabilityRequest.name = reader.getString(); + } else if ("type".equals(fieldName)) { + deserializedCheckNameAvailabilityRequest.type = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedCheckNameAvailabilityRequest; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilityResponse.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilityResponse.java new file mode 100644 index 0000000000..46c6eb9876 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/CheckNameAvailabilityResponse.java @@ -0,0 +1,40 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.models; + +import azure.resourcemanager.operationtemplates.fluent.models.CheckNameAvailabilityResponseInner; + +/** + * An immutable client-side representation of CheckNameAvailabilityResponse. + */ +public interface CheckNameAvailabilityResponse { + /** + * Gets the nameAvailable property: Indicates if the resource name is available. + * + * @return the nameAvailable value. + */ + Boolean nameAvailable(); + + /** + * Gets the reason property: The reason why the given name is not available. + * + * @return the reason value. + */ + CheckNameAvailabilityReason reason(); + + /** + * Gets the message property: Detailed reason why the given name is not available. + * + * @return the message value. + */ + String message(); + + /** + * Gets the inner azure.resourcemanager.operationtemplates.fluent.models.CheckNameAvailabilityResponseInner object. + * + * @return the inner object. + */ + CheckNameAvailabilityResponseInner innerModel(); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/Operation.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/Operation.java new file mode 100644 index 0000000000..b38f9e5b43 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/Operation.java @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.models; + +import azure.resourcemanager.operationtemplates.fluent.models.OperationInner; + +/** + * An immutable client-side representation of Operation. + */ +public interface Operation { + /** + * Gets the name property: The name of the operation, as per Resource-Based Access Control (RBAC). Examples: + * "Microsoft.Compute/virtualMachines/write", "Microsoft.Compute/virtualMachines/capture/action". + * + * @return the name value. + */ + String name(); + + /** + * Gets the isDataAction property: Whether the operation applies to data-plane. This is "true" for data-plane + * operations and "false" for Azure Resource Manager/control-plane operations. + * + * @return the isDataAction value. + */ + Boolean isDataAction(); + + /** + * Gets the display property: Localized display information for this particular operation. + * + * @return the display value. + */ + OperationDisplay display(); + + /** + * Gets the origin property: The intended executor of the operation; as in Resource Based Access Control (RBAC) and + * audit logs UX. Default value is "user,system". + * + * @return the origin value. + */ + Origin origin(); + + /** + * Gets the actionType property: Extensible enum. Indicates the action type. "Internal" refers to actions that are + * for internal only APIs. + * + * @return the actionType value. + */ + ActionType actionType(); + + /** + * Gets the inner azure.resourcemanager.operationtemplates.fluent.models.OperationInner object. + * + * @return the inner object. + */ + OperationInner innerModel(); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/OperationDisplay.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/OperationDisplay.java new file mode 100644 index 0000000000..ecc35e1cb5 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/OperationDisplay.java @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.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; + +/** + * Localized display information for and operation. + */ +@Immutable +public final class OperationDisplay implements JsonSerializable { + /* + * The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring Insights" or + * "Microsoft Compute". + */ + private String provider; + + /* + * The localized friendly name of the resource type related to this operation. E.g. "Virtual Machines" or + * "Job Schedule Collections". + */ + private String resource; + + /* + * The concise, localized friendly name for the operation; suitable for dropdowns. E.g. + * "Create or Update Virtual Machine", "Restart Virtual Machine". + */ + private String operation; + + /* + * The short, localized friendly description of the operation; suitable for tool tips and detailed views. + */ + private String description; + + /** + * Creates an instance of OperationDisplay class. + */ + private OperationDisplay() { + } + + /** + * Get the provider property: The localized friendly form of the resource provider name, e.g. "Microsoft Monitoring + * Insights" or "Microsoft Compute". + * + * @return the provider value. + */ + public String provider() { + return this.provider; + } + + /** + * Get the resource property: The localized friendly name of the resource type related to this operation. E.g. + * "Virtual Machines" or "Job Schedule Collections". + * + * @return the resource value. + */ + public String resource() { + return this.resource; + } + + /** + * Get the operation property: The concise, localized friendly name for the operation; suitable for dropdowns. E.g. + * "Create or Update Virtual Machine", "Restart Virtual Machine". + * + * @return the operation value. + */ + public String operation() { + return this.operation; + } + + /** + * Get the description property: The short, localized friendly description of the operation; suitable for tool tips + * and detailed views. + * + * @return the description value. + */ + public String description() { + return this.description; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of OperationDisplay from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of OperationDisplay 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 OperationDisplay. + */ + public static OperationDisplay fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + OperationDisplay deserializedOperationDisplay = new OperationDisplay(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("provider".equals(fieldName)) { + deserializedOperationDisplay.provider = reader.getString(); + } else if ("resource".equals(fieldName)) { + deserializedOperationDisplay.resource = reader.getString(); + } else if ("operation".equals(fieldName)) { + deserializedOperationDisplay.operation = reader.getString(); + } else if ("description".equals(fieldName)) { + deserializedOperationDisplay.description = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedOperationDisplay; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/Operations.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/Operations.java new file mode 100644 index 0000000000..64f9736ec0 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/Operations.java @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.models; + +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.util.Context; + +/** + * Resource collection API of Operations. + */ +public interface Operations { + /** + * List the operations for the provider. + * + * @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 list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + PagedIterable list(); + + /** + * List the operations for the provider. + * + * @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 list of REST API operations supported by an Azure Resource Provider as paginated response with + * {@link PagedIterable}. + */ + PagedIterable list(Context context); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/Origin.java b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/Origin.java new file mode 100644 index 0000000000..71894245ff --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/operationtemplates/models/Origin.java @@ -0,0 +1,57 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.operationtemplates.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * The intended executor of the operation; as in Resource Based Access Control (RBAC) and audit logs UX. Default value + * is "user,system". + */ +public final class Origin extends ExpandableStringEnum { + /** + * Indicates the operation is initiated by a user. + */ + public static final Origin USER = fromString("user"); + + /** + * Indicates the operation is initiated by a system. + */ + public static final Origin SYSTEM = fromString("system"); + + /** + * Indicates the operation is initiated by a user or system. + */ + public static final Origin USER_SYSTEM = fromString("user,system"); + + /** + * Creates a new instance of Origin value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public Origin() { + } + + /** + * Creates or finds a Origin from its string representation. + * + * @param name a name to look for. + * @return the corresponding Origin. + */ + public static Origin fromString(String name) { + return fromString(name, Origin.class); + } + + /** + * Gets known Origin values. + * + * @return known Origin values. + */ + public static Collection values() { + return values(Origin.class); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/ResourcesManager.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/ResourcesManager.java index 5e919d9b0b..3a3021d71b 100644 --- a/typespec-tests/src/main/java/azure/resourcemanager/resources/ResourcesManager.java +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/ResourcesManager.java @@ -5,10 +5,14 @@ package azure.resourcemanager.resources; import azure.resourcemanager.resources.fluent.ResourcesClient; +import azure.resourcemanager.resources.implementation.ExtensionsResourcesImpl; +import azure.resourcemanager.resources.implementation.LocationResourcesImpl; import azure.resourcemanager.resources.implementation.NestedsImpl; import azure.resourcemanager.resources.implementation.ResourcesClientBuilder; import azure.resourcemanager.resources.implementation.SingletonsImpl; import azure.resourcemanager.resources.implementation.TopLevelsImpl; +import azure.resourcemanager.resources.models.ExtensionsResources; +import azure.resourcemanager.resources.models.LocationResources; import azure.resourcemanager.resources.models.Nesteds; import azure.resourcemanager.resources.models.Singletons; import azure.resourcemanager.resources.models.TopLevels; @@ -49,6 +53,10 @@ public final class ResourcesManager { private Singletons singletons; + private ExtensionsResources extensionsResources; + + private LocationResources locationResources; + private final ResourcesClient clientObject; private ResourcesManager(HttpPipeline httpPipeline, AzureProfile profile, Duration defaultPollInterval) { @@ -295,6 +303,30 @@ public Singletons singletons() { return singletons; } + /** + * Gets the resource collection API of ExtensionsResources. It manages ExtensionsResource. + * + * @return Resource collection API of ExtensionsResources. + */ + public ExtensionsResources extensionsResources() { + if (this.extensionsResources == null) { + this.extensionsResources = new ExtensionsResourcesImpl(clientObject.getExtensionsResources(), this); + } + return extensionsResources; + } + + /** + * Gets the resource collection API of LocationResources. It manages LocationResource. + * + * @return Resource collection API of LocationResources. + */ + public LocationResources locationResources() { + if (this.locationResources == null) { + this.locationResources = new LocationResourcesImpl(clientObject.getLocationResources(), this); + } + return locationResources; + } + /** * Gets wrapped service client ResourcesClient providing direct access to the underlying auto-generated API * implementation, based on Azure REST API. diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/ExtensionsResourcesClient.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/ExtensionsResourcesClient.java new file mode 100644 index 0000000000..eaf7ba259f --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/ExtensionsResourcesClient.java @@ -0,0 +1,194 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.fluent; + +import azure.resourcemanager.resources.fluent.models.ExtensionsResourceInner; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.Response; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.Context; +import com.azure.core.util.polling.SyncPoller; + +/** + * An instance of this class provides access to all the operations defined in ExtensionsResourcesClient. + */ +public interface ExtensionsResourcesClient { + /** + * Get a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 ExtensionsResource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response getWithResponse(String resourceUri, String extensionsResourceName, + Context context); + + /** + * Get a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 ExtensionsResource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + ExtensionsResourceInner get(String resourceUri, String extensionsResourceName); + + /** + * Create a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 the {@link SyncPoller} for polling of concrete extension resource types can be created by aliasing this + * type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, ExtensionsResourceInner> beginCreateOrUpdate(String resourceUri, + String extensionsResourceName, ExtensionsResourceInner resource); + + /** + * Create a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 the {@link SyncPoller} for polling of concrete extension resource types can be created by aliasing this + * type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, ExtensionsResourceInner> beginCreateOrUpdate(String resourceUri, + String extensionsResourceName, ExtensionsResourceInner resource, Context context); + + /** + * Create a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 extension resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + ExtensionsResourceInner createOrUpdate(String resourceUri, String extensionsResourceName, + ExtensionsResourceInner resource); + + /** + * Create a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 extension resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + ExtensionsResourceInner createOrUpdate(String resourceUri, String extensionsResourceName, + ExtensionsResourceInner resource, Context context); + + /** + * Update a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @param properties The resource properties to be updated. + * @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 extension resource types can be created by aliasing this type using a specific property type + * along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response updateWithResponse(String resourceUri, String extensionsResourceName, + ExtensionsResourceInner properties, Context context); + + /** + * Update a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @param properties The resource properties to be updated. + * @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 extension resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + ExtensionsResourceInner update(String resourceUri, String extensionsResourceName, + ExtensionsResourceInner properties); + + /** + * Delete a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 deleteWithResponse(String resourceUri, String extensionsResourceName, Context context); + + /** + * Delete a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 delete(String resourceUri, String extensionsResourceName); + + /** + * List ExtensionsResource resources by parent. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @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 response of a ExtensionsResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable listByScope(String resourceUri); + + /** + * List ExtensionsResource resources by parent. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @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 response of a ExtensionsResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable listByScope(String resourceUri, Context context); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/LocationResourcesClient.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/LocationResourcesClient.java new file mode 100644 index 0000000000..ecc05282b4 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/LocationResourcesClient.java @@ -0,0 +1,157 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.fluent; + +import azure.resourcemanager.resources.fluent.models.LocationResourceInner; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; + +/** + * An instance of this class provides access to all the operations defined in LocationResourcesClient. + */ +public interface LocationResourcesClient { + /** + * Get a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 LocationResource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response getWithResponse(String location, String locationResourceName, Context context); + + /** + * Get a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 LocationResource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + LocationResourceInner get(String location, String locationResourceName); + + /** + * Create a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 createOrUpdateWithResponse(String location, String locationResourceName, + LocationResourceInner resource, Context context); + + /** + * Create a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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) + LocationResourceInner createOrUpdate(String location, String locationResourceName, LocationResourceInner resource); + + /** + * Update a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @param properties The resource properties to be updated. + * @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 updateWithResponse(String location, String locationResourceName, + LocationResourceInner properties, Context context); + + /** + * Update a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @param properties The resource properties to be updated. + * @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) + LocationResourceInner update(String location, String locationResourceName, LocationResourceInner properties); + + /** + * Delete a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 deleteWithResponse(String location, String locationResourceName, Context context); + + /** + * Delete a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 delete(String location, String locationResourceName); + + /** + * List LocationResource resources by SubscriptionLocationResource. + * + * @param location The name of the Azure region. + * @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 response of a LocationResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable listByLocation(String location); + + /** + * List LocationResource resources by SubscriptionLocationResource. + * + * @param location The name of the Azure region. + * @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 response of a LocationResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + PagedIterable listByLocation(String location, Context context); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/ResourcesClient.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/ResourcesClient.java index 7d5b6d2029..4cdff9c6d1 100644 --- a/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/ResourcesClient.java +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/ResourcesClient.java @@ -66,4 +66,18 @@ public interface ResourcesClient { * @return the SingletonsClient object. */ SingletonsClient getSingletons(); + + /** + * Gets the ExtensionsResourcesClient object to access its operations. + * + * @return the ExtensionsResourcesClient object. + */ + ExtensionsResourcesClient getExtensionsResources(); + + /** + * Gets the LocationResourcesClient object to access its operations. + * + * @return the LocationResourcesClient object. + */ + LocationResourcesClient getLocationResources(); } diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/models/ExtensionsResourceInner.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/models/ExtensionsResourceInner.java new file mode 100644 index 0000000000..d0ad2ee07d --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/models/ExtensionsResourceInner.java @@ -0,0 +1,166 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.fluent.models; + +import azure.resourcemanager.resources.models.ExtensionsResourceProperties; +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; + +/** + * Concrete extension resource types can be created by aliasing this type using a specific property type. + */ +@Fluent +public final class ExtensionsResourceInner extends ProxyResource { + /* + * The resource-specific properties for this resource. + */ + private ExtensionsResourceProperties 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 ExtensionsResourceInner class. + */ + public ExtensionsResourceInner() { + } + + /** + * Get the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + public ExtensionsResourceProperties properties() { + return this.properties; + } + + /** + * Set the properties property: The resource-specific properties for this resource. + * + * @param properties the properties value to set. + * @return the ExtensionsResourceInner object itself. + */ + public ExtensionsResourceInner withProperties(ExtensionsResourceProperties 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; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + if (properties() != null) { + properties().validate(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("properties", this.properties); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ExtensionsResourceInner from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ExtensionsResourceInner 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 ExtensionsResourceInner. + */ + public static ExtensionsResourceInner fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ExtensionsResourceInner deserializedExtensionsResourceInner = new ExtensionsResourceInner(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedExtensionsResourceInner.id = reader.getString(); + } else if ("name".equals(fieldName)) { + deserializedExtensionsResourceInner.name = reader.getString(); + } else if ("type".equals(fieldName)) { + deserializedExtensionsResourceInner.type = reader.getString(); + } else if ("properties".equals(fieldName)) { + deserializedExtensionsResourceInner.properties = ExtensionsResourceProperties.fromJson(reader); + } else if ("systemData".equals(fieldName)) { + deserializedExtensionsResourceInner.systemData = SystemData.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedExtensionsResourceInner; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/models/LocationResourceInner.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/models/LocationResourceInner.java new file mode 100644 index 0000000000..35d942a12f --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/fluent/models/LocationResourceInner.java @@ -0,0 +1,166 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.fluent.models; + +import azure.resourcemanager.resources.models.LocationResourceProperties; +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; + +/** + * Concrete proxy resource types can be created by aliasing this type using a specific property type. + */ +@Fluent +public final class LocationResourceInner extends ProxyResource { + /* + * The resource-specific properties for this resource. + */ + private LocationResourceProperties 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 LocationResourceInner class. + */ + public LocationResourceInner() { + } + + /** + * Get the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + public LocationResourceProperties properties() { + return this.properties; + } + + /** + * Set the properties property: The resource-specific properties for this resource. + * + * @param properties the properties value to set. + * @return the LocationResourceInner object itself. + */ + public LocationResourceInner withProperties(LocationResourceProperties 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; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + if (properties() != null) { + properties().validate(); + } + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("properties", this.properties); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of LocationResourceInner from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of LocationResourceInner 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 LocationResourceInner. + */ + public static LocationResourceInner fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + LocationResourceInner deserializedLocationResourceInner = new LocationResourceInner(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedLocationResourceInner.id = reader.getString(); + } else if ("name".equals(fieldName)) { + deserializedLocationResourceInner.name = reader.getString(); + } else if ("type".equals(fieldName)) { + deserializedLocationResourceInner.type = reader.getString(); + } else if ("properties".equals(fieldName)) { + deserializedLocationResourceInner.properties = LocationResourceProperties.fromJson(reader); + } else if ("systemData".equals(fieldName)) { + deserializedLocationResourceInner.systemData = SystemData.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedLocationResourceInner; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ExtensionsResourceImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ExtensionsResourceImpl.java new file mode 100644 index 0000000000..feda030392 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ExtensionsResourceImpl.java @@ -0,0 +1,128 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.implementation; + +import azure.resourcemanager.resources.fluent.models.ExtensionsResourceInner; +import azure.resourcemanager.resources.models.ExtensionsResource; +import azure.resourcemanager.resources.models.ExtensionsResourceProperties; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; + +public final class ExtensionsResourceImpl + implements ExtensionsResource, ExtensionsResource.Definition, ExtensionsResource.Update { + private ExtensionsResourceInner innerObject; + + private final azure.resourcemanager.resources.ResourcesManager serviceManager; + + public String id() { + return this.innerModel().id(); + } + + public String name() { + return this.innerModel().name(); + } + + public String type() { + return this.innerModel().type(); + } + + public ExtensionsResourceProperties properties() { + return this.innerModel().properties(); + } + + public SystemData systemData() { + return this.innerModel().systemData(); + } + + public ExtensionsResourceInner innerModel() { + return this.innerObject; + } + + private azure.resourcemanager.resources.ResourcesManager manager() { + return this.serviceManager; + } + + private String resourceUri; + + private String extensionsResourceName; + + public ExtensionsResourceImpl withExistingResourceUri(String resourceUri) { + this.resourceUri = resourceUri; + return this; + } + + public ExtensionsResource create() { + this.innerObject = serviceManager.serviceClient() + .getExtensionsResources() + .createOrUpdate(resourceUri, extensionsResourceName, this.innerModel(), Context.NONE); + return this; + } + + public ExtensionsResource create(Context context) { + this.innerObject = serviceManager.serviceClient() + .getExtensionsResources() + .createOrUpdate(resourceUri, extensionsResourceName, this.innerModel(), context); + return this; + } + + ExtensionsResourceImpl(String name, azure.resourcemanager.resources.ResourcesManager serviceManager) { + this.innerObject = new ExtensionsResourceInner(); + this.serviceManager = serviceManager; + this.extensionsResourceName = name; + } + + public ExtensionsResourceImpl update() { + return this; + } + + public ExtensionsResource apply() { + this.innerObject = serviceManager.serviceClient() + .getExtensionsResources() + .updateWithResponse(resourceUri, extensionsResourceName, this.innerModel(), Context.NONE) + .getValue(); + return this; + } + + public ExtensionsResource apply(Context context) { + this.innerObject = serviceManager.serviceClient() + .getExtensionsResources() + .updateWithResponse(resourceUri, extensionsResourceName, this.innerModel(), context) + .getValue(); + return this; + } + + ExtensionsResourceImpl(ExtensionsResourceInner innerObject, + azure.resourcemanager.resources.ResourcesManager serviceManager) { + this.innerObject = innerObject; + this.serviceManager = serviceManager; + this.resourceUri = ResourceManagerUtils.getValueFromIdByParameterName(innerObject.id(), + "/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}", + "resourceUri"); + this.extensionsResourceName = ResourceManagerUtils.getValueFromIdByParameterName(innerObject.id(), + "/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}", + "extensionsResourceName"); + } + + public ExtensionsResource refresh() { + this.innerObject = serviceManager.serviceClient() + .getExtensionsResources() + .getWithResponse(resourceUri, extensionsResourceName, Context.NONE) + .getValue(); + return this; + } + + public ExtensionsResource refresh(Context context) { + this.innerObject = serviceManager.serviceClient() + .getExtensionsResources() + .getWithResponse(resourceUri, extensionsResourceName, context) + .getValue(); + return this; + } + + public ExtensionsResourceImpl withProperties(ExtensionsResourceProperties properties) { + this.innerModel().withProperties(properties); + return this; + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ExtensionsResourcesClientImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ExtensionsResourcesClientImpl.java new file mode 100644 index 0000000000..b6f93e1215 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ExtensionsResourcesClientImpl.java @@ -0,0 +1,885 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.implementation; + +import azure.resourcemanager.resources.fluent.ExtensionsResourcesClient; +import azure.resourcemanager.resources.fluent.models.ExtensionsResourceInner; +import azure.resourcemanager.resources.implementation.models.ExtensionsResourceListResult; +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.Patch; +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.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.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.polling.SyncPoller; +import java.nio.ByteBuffer; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in ExtensionsResourcesClient. + */ +public final class ExtensionsResourcesClientImpl implements ExtensionsResourcesClient { + /** + * The proxy service used to perform REST calls. + */ + private final ExtensionsResourcesService service; + + /** + * The service client containing this operation class. + */ + private final ResourcesClientImpl client; + + /** + * Initializes an instance of ExtensionsResourcesClientImpl. + * + * @param client the instance of the service client containing this operation class. + */ + ExtensionsResourcesClientImpl(ResourcesClientImpl client) { + this.service = RestProxy.create(ExtensionsResourcesService.class, client.getHttpPipeline(), + client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for ResourcesClientExtensionsResources to be used by the proxy service to + * perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "ResourcesClientExten") + public interface ExtensionsResourcesService { + @Headers({ "Content-Type: application/json" }) + @Get("/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> get(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, + @PathParam(value = "resourceUri", encoded = true) String resourceUri, + @PathParam("extensionsResourceName") String extensionsResourceName, @HeaderParam("Accept") String accept, + Context context); + + @Put("/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono>> createOrUpdate(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, + @PathParam(value = "resourceUri", encoded = true) String resourceUri, + @PathParam("extensionsResourceName") String extensionsResourceName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") ExtensionsResourceInner resource, Context context); + + @Patch("/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> update(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, + @PathParam(value = "resourceUri", encoded = true) String resourceUri, + @PathParam("extensionsResourceName") String extensionsResourceName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") ExtensionsResourceInner properties, Context context); + + @Headers({ "Content-Type: application/json" }) + @Delete("/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}") + @ExpectedResponses({ 200, 204 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> delete(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, + @PathParam(value = "resourceUri", encoded = true) String resourceUri, + @PathParam("extensionsResourceName") String extensionsResourceName, @HeaderParam("Accept") String accept, + Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> listByScope(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, + @PathParam(value = "resourceUri", encoded = true) String resourceUri, @HeaderParam("Accept") String accept, + Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> listByScopeNext( + @PathParam(value = "nextLink", encoded = true) String nextLink, @HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, Context context); + } + + /** + * Get a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 ExtensionsResource along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> getWithResponseAsync(String resourceUri, + String extensionsResourceName) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (resourceUri == null) { + return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null.")); + } + if (extensionsResourceName == null) { + return Mono.error( + new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.get(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri, + extensionsResourceName, accept, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 ExtensionsResource along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> getWithResponseAsync(String resourceUri, + String extensionsResourceName, Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (resourceUri == null) { + return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null.")); + } + if (extensionsResourceName == null) { + return Mono.error( + new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.get(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri, extensionsResourceName, + accept, context); + } + + /** + * Get a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 ExtensionsResource on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono getAsync(String resourceUri, String extensionsResourceName) { + return getWithResponseAsync(resourceUri, extensionsResourceName) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Get a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 ExtensionsResource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getWithResponse(String resourceUri, String extensionsResourceName, + Context context) { + return getWithResponseAsync(resourceUri, extensionsResourceName, context).block(); + } + + /** + * Get a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 ExtensionsResource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public ExtensionsResourceInner get(String resourceUri, String extensionsResourceName) { + return getWithResponse(resourceUri, extensionsResourceName, Context.NONE).getValue(); + } + + /** + * Create a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 extension 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>> createOrUpdateWithResponseAsync(String resourceUri, + String extensionsResourceName, ExtensionsResourceInner resource) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (resourceUri == null) { + return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null.")); + } + if (extensionsResourceName == null) { + return Mono.error( + new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null.")); + } + if (resource == null) { + return Mono.error(new IllegalArgumentException("Parameter resource is required and cannot be null.")); + } else { + resource.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), this.client.getApiVersion(), + resourceUri, extensionsResourceName, contentType, accept, resource, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Create a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 extension 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>> createOrUpdateWithResponseAsync(String resourceUri, + String extensionsResourceName, ExtensionsResourceInner resource, Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (resourceUri == null) { + return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null.")); + } + if (extensionsResourceName == null) { + return Mono.error( + new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null.")); + } + if (resource == null) { + return Mono.error(new IllegalArgumentException("Parameter resource is required and cannot be null.")); + } else { + resource.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.createOrUpdate(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri, + extensionsResourceName, contentType, accept, resource, context); + } + + /** + * Create a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 the {@link PollerFlux} for polling of concrete extension resource types can be created by aliasing this + * type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, ExtensionsResourceInner> + beginCreateOrUpdateAsync(String resourceUri, String extensionsResourceName, ExtensionsResourceInner resource) { + Mono>> mono + = createOrUpdateWithResponseAsync(resourceUri, extensionsResourceName, resource); + return this.client.getLroResult(mono, + this.client.getHttpPipeline(), ExtensionsResourceInner.class, ExtensionsResourceInner.class, + this.client.getContext()); + } + + /** + * Create a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 the {@link PollerFlux} for polling of concrete extension resource types can be created by aliasing this + * type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, ExtensionsResourceInner> beginCreateOrUpdateAsync( + String resourceUri, String extensionsResourceName, ExtensionsResourceInner resource, Context context) { + context = this.client.mergeContext(context); + Mono>> mono + = createOrUpdateWithResponseAsync(resourceUri, extensionsResourceName, resource, context); + return this.client.getLroResult(mono, + this.client.getHttpPipeline(), ExtensionsResourceInner.class, ExtensionsResourceInner.class, context); + } + + /** + * Create a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 the {@link SyncPoller} for polling of concrete extension resource types can be created by aliasing this + * type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, ExtensionsResourceInner> + beginCreateOrUpdate(String resourceUri, String extensionsResourceName, ExtensionsResourceInner resource) { + return this.beginCreateOrUpdateAsync(resourceUri, extensionsResourceName, resource).getSyncPoller(); + } + + /** + * Create a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 the {@link SyncPoller} for polling of concrete extension resource types can be created by aliasing this + * type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, ExtensionsResourceInner> beginCreateOrUpdate( + String resourceUri, String extensionsResourceName, ExtensionsResourceInner resource, Context context) { + return this.beginCreateOrUpdateAsync(resourceUri, extensionsResourceName, resource, context).getSyncPoller(); + } + + /** + * Create a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 extension 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 createOrUpdateAsync(String resourceUri, String extensionsResourceName, + ExtensionsResourceInner resource) { + return beginCreateOrUpdateAsync(resourceUri, extensionsResourceName, resource).last() + .flatMap(this.client::getLroFinalResultOrError); + } + + /** + * Create a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 extension 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 createOrUpdateAsync(String resourceUri, String extensionsResourceName, + ExtensionsResourceInner resource, Context context) { + return beginCreateOrUpdateAsync(resourceUri, extensionsResourceName, resource, context).last() + .flatMap(this.client::getLroFinalResultOrError); + } + + /** + * Create a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 extension resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public ExtensionsResourceInner createOrUpdate(String resourceUri, String extensionsResourceName, + ExtensionsResourceInner resource) { + return createOrUpdateAsync(resourceUri, extensionsResourceName, resource).block(); + } + + /** + * Create a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 extension resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public ExtensionsResourceInner createOrUpdate(String resourceUri, String extensionsResourceName, + ExtensionsResourceInner resource, Context context) { + return createOrUpdateAsync(resourceUri, extensionsResourceName, resource, context).block(); + } + + /** + * Update a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @param properties The resource properties to be updated. + * @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 extension 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> updateWithResponseAsync(String resourceUri, + String extensionsResourceName, ExtensionsResourceInner properties) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (resourceUri == null) { + return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null.")); + } + if (extensionsResourceName == null) { + return Mono.error( + new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null.")); + } + if (properties == null) { + return Mono.error(new IllegalArgumentException("Parameter properties is required and cannot be null.")); + } else { + properties.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.update(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri, + extensionsResourceName, contentType, accept, properties, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Update a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @param properties The resource properties to be updated. + * @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 extension 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> updateWithResponseAsync(String resourceUri, + String extensionsResourceName, ExtensionsResourceInner properties, Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (resourceUri == null) { + return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null.")); + } + if (extensionsResourceName == null) { + return Mono.error( + new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null.")); + } + if (properties == null) { + return Mono.error(new IllegalArgumentException("Parameter properties is required and cannot be null.")); + } else { + properties.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.update(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri, + extensionsResourceName, contentType, accept, properties, context); + } + + /** + * Update a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @param properties The resource properties to be updated. + * @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 extension 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 updateAsync(String resourceUri, String extensionsResourceName, + ExtensionsResourceInner properties) { + return updateWithResponseAsync(resourceUri, extensionsResourceName, properties) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Update a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @param properties The resource properties to be updated. + * @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 extension resource types can be created by aliasing this type using a specific property type + * along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response updateWithResponse(String resourceUri, String extensionsResourceName, + ExtensionsResourceInner properties, Context context) { + return updateWithResponseAsync(resourceUri, extensionsResourceName, properties, context).block(); + } + + /** + * Update a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @param properties The resource properties to be updated. + * @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 extension resource types can be created by aliasing this type using a specific property type. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public ExtensionsResourceInner update(String resourceUri, String extensionsResourceName, + ExtensionsResourceInner properties) { + return updateWithResponse(resourceUri, extensionsResourceName, properties, Context.NONE).getValue(); + } + + /** + * Delete a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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> deleteWithResponseAsync(String resourceUri, String extensionsResourceName) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (resourceUri == null) { + return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null.")); + } + if (extensionsResourceName == null) { + return Mono.error( + new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.delete(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri, + extensionsResourceName, accept, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Delete a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> deleteWithResponseAsync(String resourceUri, String extensionsResourceName, + Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (resourceUri == null) { + return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null.")); + } + if (extensionsResourceName == null) { + return Mono.error( + new IllegalArgumentException("Parameter extensionsResourceName is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.delete(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri, + extensionsResourceName, accept, context); + } + + /** + * Delete a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 deleteAsync(String resourceUri, String extensionsResourceName) { + return deleteWithResponseAsync(resourceUri, extensionsResourceName).flatMap(ignored -> Mono.empty()); + } + + /** + * Delete a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 deleteWithResponse(String resourceUri, String extensionsResourceName, Context context) { + return deleteWithResponseAsync(resourceUri, extensionsResourceName, context).block(); + } + + /** + * Delete a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 delete(String resourceUri, String extensionsResourceName) { + deleteWithResponse(resourceUri, extensionsResourceName, Context.NONE); + } + + /** + * List ExtensionsResource resources by parent. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @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 response of a ExtensionsResource list operation along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listByScopeSinglePageAsync(String resourceUri) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (resourceUri == null) { + return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.listByScope(this.client.getEndpoint(), this.client.getApiVersion(), + resourceUri, accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), + res.getStatusCode(), res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * List ExtensionsResource resources by parent. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @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 response of a ExtensionsResource list operation along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listByScopeSinglePageAsync(String resourceUri, + Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (resourceUri == null) { + return Mono.error(new IllegalArgumentException("Parameter resourceUri is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.listByScope(this.client.getEndpoint(), this.client.getApiVersion(), resourceUri, accept, context) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + res.getValue().value(), res.getValue().nextLink(), null)); + } + + /** + * List ExtensionsResource resources by parent. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @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 response of a ExtensionsResource list operation as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listByScopeAsync(String resourceUri) { + return new PagedFlux<>(() -> listByScopeSinglePageAsync(resourceUri), + nextLink -> listByScopeNextSinglePageAsync(nextLink)); + } + + /** + * List ExtensionsResource resources by parent. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @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 response of a ExtensionsResource list operation as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listByScopeAsync(String resourceUri, Context context) { + return new PagedFlux<>(() -> listByScopeSinglePageAsync(resourceUri, context), + nextLink -> listByScopeNextSinglePageAsync(nextLink, context)); + } + + /** + * List ExtensionsResource resources by parent. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @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 response of a ExtensionsResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listByScope(String resourceUri) { + return new PagedIterable<>(listByScopeAsync(resourceUri)); + } + + /** + * List ExtensionsResource resources by parent. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @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 response of a ExtensionsResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listByScope(String resourceUri, Context context) { + return new PagedIterable<>(listByScopeAsync(resourceUri, context)); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @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 response of a ExtensionsResource list operation along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listByScopeNextSinglePageAsync(String nextLink) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.listByScopeNext(nextLink, this.client.getEndpoint(), accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), + res.getStatusCode(), res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @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 response of a ExtensionsResource list operation along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listByScopeNextSinglePageAsync(String nextLink, + Context context) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.listByScopeNext(nextLink, this.client.getEndpoint(), accept, context) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + res.getValue().value(), res.getValue().nextLink(), null)); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ExtensionsResourcesImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ExtensionsResourcesImpl.java new file mode 100644 index 0000000000..aa268931b3 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ExtensionsResourcesImpl.java @@ -0,0 +1,153 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.implementation; + +import azure.resourcemanager.resources.fluent.ExtensionsResourcesClient; +import azure.resourcemanager.resources.fluent.models.ExtensionsResourceInner; +import azure.resourcemanager.resources.models.ExtensionsResource; +import azure.resourcemanager.resources.models.ExtensionsResources; +import com.azure.core.http.rest.PagedIterable; +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; + +public final class ExtensionsResourcesImpl implements ExtensionsResources { + private static final ClientLogger LOGGER = new ClientLogger(ExtensionsResourcesImpl.class); + + private final ExtensionsResourcesClient innerClient; + + private final azure.resourcemanager.resources.ResourcesManager serviceManager; + + public ExtensionsResourcesImpl(ExtensionsResourcesClient innerClient, + azure.resourcemanager.resources.ResourcesManager serviceManager) { + this.innerClient = innerClient; + this.serviceManager = serviceManager; + } + + public Response getWithResponse(String resourceUri, String extensionsResourceName, + Context context) { + Response inner + = this.serviceClient().getWithResponse(resourceUri, extensionsResourceName, context); + if (inner != null) { + return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(), + new ExtensionsResourceImpl(inner.getValue(), this.manager())); + } else { + return null; + } + } + + public ExtensionsResource get(String resourceUri, String extensionsResourceName) { + ExtensionsResourceInner inner = this.serviceClient().get(resourceUri, extensionsResourceName); + if (inner != null) { + return new ExtensionsResourceImpl(inner, this.manager()); + } else { + return null; + } + } + + public Response deleteByResourceGroupWithResponse(String resourceUri, String extensionsResourceName, + Context context) { + return this.serviceClient().deleteWithResponse(resourceUri, extensionsResourceName, context); + } + + public void deleteByResourceGroup(String resourceUri, String extensionsResourceName) { + this.serviceClient().delete(resourceUri, extensionsResourceName); + } + + public PagedIterable listByScope(String resourceUri) { + PagedIterable inner = this.serviceClient().listByScope(resourceUri); + return ResourceManagerUtils.mapPage(inner, inner1 -> new ExtensionsResourceImpl(inner1, this.manager())); + } + + public PagedIterable listByScope(String resourceUri, Context context) { + PagedIterable inner = this.serviceClient().listByScope(resourceUri, context); + return ResourceManagerUtils.mapPage(inner, inner1 -> new ExtensionsResourceImpl(inner1, this.manager())); + } + + public ExtensionsResource getById(String id) { + String resourceUri = ResourceManagerUtils.getValueFromIdByParameterName(id, + "/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}", + "resourceUri"); + if (resourceUri == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceUri'.", id))); + } + String extensionsResourceName = ResourceManagerUtils.getValueFromIdByParameterName(id, + "/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}", + "extensionsResourceName"); + if (extensionsResourceName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'extensionsResources'.", id))); + } + return this.getWithResponse(resourceUri, extensionsResourceName, Context.NONE).getValue(); + } + + public Response getByIdWithResponse(String id, Context context) { + String resourceUri = ResourceManagerUtils.getValueFromIdByParameterName(id, + "/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}", + "resourceUri"); + if (resourceUri == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceUri'.", id))); + } + String extensionsResourceName = ResourceManagerUtils.getValueFromIdByParameterName(id, + "/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}", + "extensionsResourceName"); + if (extensionsResourceName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'extensionsResources'.", id))); + } + return this.getWithResponse(resourceUri, extensionsResourceName, context); + } + + public void deleteById(String id) { + String resourceUri = ResourceManagerUtils.getValueFromIdByParameterName(id, + "/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}", + "resourceUri"); + if (resourceUri == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceUri'.", id))); + } + String extensionsResourceName = ResourceManagerUtils.getValueFromIdByParameterName(id, + "/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}", + "extensionsResourceName"); + if (extensionsResourceName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'extensionsResources'.", id))); + } + this.deleteByResourceGroupWithResponse(resourceUri, extensionsResourceName, Context.NONE); + } + + public Response deleteByIdWithResponse(String id, Context context) { + String resourceUri = ResourceManagerUtils.getValueFromIdByParameterName(id, + "/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}", + "resourceUri"); + if (resourceUri == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceUri'.", id))); + } + String extensionsResourceName = ResourceManagerUtils.getValueFromIdByParameterName(id, + "/{resourceUri}/providers/Azure.ResourceManager.Resources/extensionsResources/{extensionsResourceName}", + "extensionsResourceName"); + if (extensionsResourceName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'extensionsResources'.", id))); + } + return this.deleteByResourceGroupWithResponse(resourceUri, extensionsResourceName, context); + } + + private ExtensionsResourcesClient serviceClient() { + return this.innerClient; + } + + private azure.resourcemanager.resources.ResourcesManager manager() { + return this.serviceManager; + } + + public ExtensionsResourceImpl define(String name) { + return new ExtensionsResourceImpl(name, this.manager()); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/LocationResourceImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/LocationResourceImpl.java new file mode 100644 index 0000000000..1961ee412f --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/LocationResourceImpl.java @@ -0,0 +1,126 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.implementation; + +import azure.resourcemanager.resources.fluent.models.LocationResourceInner; +import azure.resourcemanager.resources.models.LocationResource; +import azure.resourcemanager.resources.models.LocationResourceProperties; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; + +public final class LocationResourceImpl + implements LocationResource, LocationResource.Definition, LocationResource.Update { + private LocationResourceInner innerObject; + + private final azure.resourcemanager.resources.ResourcesManager serviceManager; + + public String id() { + return this.innerModel().id(); + } + + public String name() { + return this.innerModel().name(); + } + + public String type() { + return this.innerModel().type(); + } + + public LocationResourceProperties properties() { + return this.innerModel().properties(); + } + + public SystemData systemData() { + return this.innerModel().systemData(); + } + + public LocationResourceInner innerModel() { + return this.innerObject; + } + + private azure.resourcemanager.resources.ResourcesManager manager() { + return this.serviceManager; + } + + private String location; + + private String locationResourceName; + + public LocationResourceImpl withExistingLocation(String location) { + this.location = location; + return this; + } + + public LocationResource create() { + this.innerObject = serviceManager.serviceClient() + .getLocationResources() + .createOrUpdateWithResponse(location, locationResourceName, this.innerModel(), Context.NONE) + .getValue(); + return this; + } + + public LocationResource create(Context context) { + this.innerObject = serviceManager.serviceClient() + .getLocationResources() + .createOrUpdateWithResponse(location, locationResourceName, this.innerModel(), context) + .getValue(); + return this; + } + + LocationResourceImpl(String name, azure.resourcemanager.resources.ResourcesManager serviceManager) { + this.innerObject = new LocationResourceInner(); + this.serviceManager = serviceManager; + this.locationResourceName = name; + } + + public LocationResourceImpl update() { + return this; + } + + public LocationResource apply() { + this.innerObject = serviceManager.serviceClient() + .getLocationResources() + .updateWithResponse(location, locationResourceName, this.innerModel(), Context.NONE) + .getValue(); + return this; + } + + public LocationResource apply(Context context) { + this.innerObject = serviceManager.serviceClient() + .getLocationResources() + .updateWithResponse(location, locationResourceName, this.innerModel(), context) + .getValue(); + return this; + } + + LocationResourceImpl(LocationResourceInner innerObject, + azure.resourcemanager.resources.ResourcesManager serviceManager) { + this.innerObject = innerObject; + this.serviceManager = serviceManager; + this.location = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "locations"); + this.locationResourceName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "locationResources"); + } + + public LocationResource refresh() { + this.innerObject = serviceManager.serviceClient() + .getLocationResources() + .getWithResponse(location, locationResourceName, Context.NONE) + .getValue(); + return this; + } + + public LocationResource refresh(Context context) { + this.innerObject = serviceManager.serviceClient() + .getLocationResources() + .getWithResponse(location, locationResourceName, context) + .getValue(); + return this; + } + + public LocationResourceImpl withProperties(LocationResourceProperties properties) { + this.innerModel().withProperties(properties); + return this; + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/LocationResourcesClientImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/LocationResourcesClientImpl.java new file mode 100644 index 0000000000..a9dfcf6d0a --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/LocationResourcesClientImpl.java @@ -0,0 +1,813 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.implementation; + +import azure.resourcemanager.resources.fluent.LocationResourcesClient; +import azure.resourcemanager.resources.fluent.models.LocationResourceInner; +import azure.resourcemanager.resources.implementation.models.LocationResourceListResult; +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.Patch; +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.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.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; + +/** + * An instance of this class provides access to all the operations defined in LocationResourcesClient. + */ +public final class LocationResourcesClientImpl implements LocationResourcesClient { + /** + * The proxy service used to perform REST calls. + */ + private final LocationResourcesService service; + + /** + * The service client containing this operation class. + */ + private final ResourcesClientImpl client; + + /** + * Initializes an instance of LocationResourcesClientImpl. + * + * @param client the instance of the service client containing this operation class. + */ + LocationResourcesClientImpl(ResourcesClientImpl client) { + this.service + = RestProxy.create(LocationResourcesService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for ResourcesClientLocationResources to be used by the proxy service to + * perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "ResourcesClientLocat") + public interface LocationResourcesService { + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.Resources/locations/{location}/locationResources/{locationResourceName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> get(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("location") String location, @PathParam("locationResourceName") String locationResourceName, + @HeaderParam("Accept") String accept, Context context); + + @Put("/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.Resources/locations/{location}/locationResources/{locationResourceName}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> createOrUpdate(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("location") String location, @PathParam("locationResourceName") String locationResourceName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") LocationResourceInner resource, Context context); + + @Patch("/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.Resources/locations/{location}/locationResources/{locationResourceName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> update(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("location") String location, @PathParam("locationResourceName") String locationResourceName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") LocationResourceInner properties, Context context); + + @Headers({ "Content-Type: application/json" }) + @Delete("/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.Resources/locations/{location}/locationResources/{locationResourceName}") + @ExpectedResponses({ 200, 204 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> delete(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("location") String location, @PathParam("locationResourceName") String locationResourceName, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.Resources/locations/{location}/locationResources") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> listByLocation(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("location") String location, @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> listByLocationNext( + @PathParam(value = "nextLink", encoded = true) String nextLink, @HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, Context context); + } + + /** + * Get a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 LocationResource along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> getWithResponseAsync(String location, String locationResourceName) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (location == null) { + return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null.")); + } + if (locationResourceName == null) { + return Mono + .error(new IllegalArgumentException("Parameter locationResourceName is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.get(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), location, locationResourceName, accept, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 LocationResource along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> getWithResponseAsync(String location, String locationResourceName, + Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (location == null) { + return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null.")); + } + if (locationResourceName == null) { + return Mono + .error(new IllegalArgumentException("Parameter locationResourceName is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.get(this.client.getEndpoint(), this.client.getApiVersion(), this.client.getSubscriptionId(), + location, locationResourceName, accept, context); + } + + /** + * Get a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 LocationResource on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono getAsync(String location, String locationResourceName) { + return getWithResponseAsync(location, locationResourceName).flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Get a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 LocationResource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getWithResponse(String location, String locationResourceName, + Context context) { + return getWithResponseAsync(location, locationResourceName, context).block(); + } + + /** + * Get a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 LocationResource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public LocationResourceInner get(String location, String locationResourceName) { + return getWithResponse(location, locationResourceName, Context.NONE).getValue(); + } + + /** + * Create a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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> createOrUpdateWithResponseAsync(String location, + String locationResourceName, LocationResourceInner resource) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (location == null) { + return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null.")); + } + if (locationResourceName == null) { + return Mono + .error(new IllegalArgumentException("Parameter locationResourceName is required and cannot be null.")); + } + if (resource == null) { + return Mono.error(new IllegalArgumentException("Parameter resource is required and cannot be null.")); + } else { + resource.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), location, locationResourceName, contentType, accept, resource, + context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Create a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> createOrUpdateWithResponseAsync(String location, + String locationResourceName, LocationResourceInner resource, Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (location == null) { + return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null.")); + } + if (locationResourceName == null) { + return Mono + .error(new IllegalArgumentException("Parameter locationResourceName is required and cannot be null.")); + } + if (resource == null) { + return Mono.error(new IllegalArgumentException("Parameter resource is required and cannot be null.")); + } else { + resource.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.createOrUpdate(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), location, locationResourceName, contentType, accept, resource, context); + } + + /** + * Create a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 createOrUpdateAsync(String location, String locationResourceName, + LocationResourceInner resource) { + return createOrUpdateWithResponseAsync(location, locationResourceName, resource) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Create a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 createOrUpdateWithResponse(String location, String locationResourceName, + LocationResourceInner resource, Context context) { + return createOrUpdateWithResponseAsync(location, locationResourceName, resource, context).block(); + } + + /** + * Create a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 LocationResourceInner createOrUpdate(String location, String locationResourceName, + LocationResourceInner resource) { + return createOrUpdateWithResponse(location, locationResourceName, resource, Context.NONE).getValue(); + } + + /** + * Update a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @param properties The resource properties to be updated. + * @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> updateWithResponseAsync(String location, String locationResourceName, + LocationResourceInner properties) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (location == null) { + return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null.")); + } + if (locationResourceName == null) { + return Mono + .error(new IllegalArgumentException("Parameter locationResourceName is required and cannot be null.")); + } + if (properties == null) { + return Mono.error(new IllegalArgumentException("Parameter properties is required and cannot be null.")); + } else { + properties.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.update(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), location, locationResourceName, contentType, accept, properties, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Update a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @param properties The resource properties to be updated. + * @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} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> updateWithResponseAsync(String location, String locationResourceName, + LocationResourceInner properties, Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (location == null) { + return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null.")); + } + if (locationResourceName == null) { + return Mono + .error(new IllegalArgumentException("Parameter locationResourceName is required and cannot be null.")); + } + if (properties == null) { + return Mono.error(new IllegalArgumentException("Parameter properties is required and cannot be null.")); + } else { + properties.validate(); + } + final String contentType = "application/json"; + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.update(this.client.getEndpoint(), this.client.getApiVersion(), this.client.getSubscriptionId(), + location, locationResourceName, contentType, accept, properties, context); + } + + /** + * Update a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @param properties The resource properties to be updated. + * @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 updateAsync(String location, String locationResourceName, + LocationResourceInner properties) { + return updateWithResponseAsync(location, locationResourceName, properties) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Update a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @param properties The resource properties to be updated. + * @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 updateWithResponse(String location, String locationResourceName, + LocationResourceInner properties, Context context) { + return updateWithResponseAsync(location, locationResourceName, properties, context).block(); + } + + /** + * Update a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @param properties The resource properties to be updated. + * @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 LocationResourceInner update(String location, String locationResourceName, + LocationResourceInner properties) { + return updateWithResponse(location, locationResourceName, properties, Context.NONE).getValue(); + } + + /** + * Delete a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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> deleteWithResponseAsync(String location, String locationResourceName) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (location == null) { + return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null.")); + } + if (locationResourceName == null) { + return Mono + .error(new IllegalArgumentException("Parameter locationResourceName is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.delete(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), location, locationResourceName, accept, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Delete a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> deleteWithResponseAsync(String location, String locationResourceName, + Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (location == null) { + return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null.")); + } + if (locationResourceName == null) { + return Mono + .error(new IllegalArgumentException("Parameter locationResourceName is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.delete(this.client.getEndpoint(), this.client.getApiVersion(), this.client.getSubscriptionId(), + location, locationResourceName, accept, context); + } + + /** + * Delete a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 deleteAsync(String location, String locationResourceName) { + return deleteWithResponseAsync(location, locationResourceName).flatMap(ignored -> Mono.empty()); + } + + /** + * Delete a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 deleteWithResponse(String location, String locationResourceName, Context context) { + return deleteWithResponseAsync(location, locationResourceName, context).block(); + } + + /** + * Delete a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 delete(String location, String locationResourceName) { + deleteWithResponse(location, locationResourceName, Context.NONE); + } + + /** + * List LocationResource resources by SubscriptionLocationResource. + * + * @param location The name of the Azure region. + * @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 response of a LocationResource list operation along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listByLocationSinglePageAsync(String location) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (location == null) { + return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.listByLocation(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), location, accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), + res.getStatusCode(), res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * List LocationResource resources by SubscriptionLocationResource. + * + * @param location The name of the Azure region. + * @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 response of a LocationResource list operation along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listByLocationSinglePageAsync(String location, Context context) { + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + if (this.client.getSubscriptionId() == null) { + return Mono.error(new IllegalArgumentException( + "Parameter this.client.getSubscriptionId() is required and cannot be null.")); + } + if (location == null) { + return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service + .listByLocation(this.client.getEndpoint(), this.client.getApiVersion(), this.client.getSubscriptionId(), + location, accept, context) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + res.getValue().value(), res.getValue().nextLink(), null)); + } + + /** + * List LocationResource resources by SubscriptionLocationResource. + * + * @param location The name of the Azure region. + * @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 response of a LocationResource list operation as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listByLocationAsync(String location) { + return new PagedFlux<>(() -> listByLocationSinglePageAsync(location), + nextLink -> listByLocationNextSinglePageAsync(nextLink)); + } + + /** + * List LocationResource resources by SubscriptionLocationResource. + * + * @param location The name of the Azure region. + * @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 response of a LocationResource list operation as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + private PagedFlux listByLocationAsync(String location, Context context) { + return new PagedFlux<>(() -> listByLocationSinglePageAsync(location, context), + nextLink -> listByLocationNextSinglePageAsync(nextLink, context)); + } + + /** + * List LocationResource resources by SubscriptionLocationResource. + * + * @param location The name of the Azure region. + * @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 response of a LocationResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listByLocation(String location) { + return new PagedIterable<>(listByLocationAsync(location)); + } + + /** + * List LocationResource resources by SubscriptionLocationResource. + * + * @param location The name of the Azure region. + * @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 response of a LocationResource list operation as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listByLocation(String location, Context context) { + return new PagedIterable<>(listByLocationAsync(location, context)); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @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 response of a LocationResource list operation along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listByLocationNextSinglePageAsync(String nextLink) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.listByLocationNext(nextLink, this.client.getEndpoint(), accept, context)) + .>map(res -> new PagedResponseBase<>(res.getRequest(), + res.getStatusCode(), res.getHeaders(), res.getValue().value(), res.getValue().nextLink(), null)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Get the next page of items. + * + * @param nextLink The URL to get the next list of items. + * @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 response of a LocationResource list operation along with {@link PagedResponse} on successful + * completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listByLocationNextSinglePageAsync(String nextLink, + Context context) { + if (nextLink == null) { + return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null.")); + } + if (this.client.getEndpoint() == null) { + return Mono.error( + new IllegalArgumentException("Parameter this.client.getEndpoint() is required and cannot be null.")); + } + final String accept = "application/json"; + context = this.client.mergeContext(context); + return service.listByLocationNext(nextLink, this.client.getEndpoint(), accept, context) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + res.getValue().value(), res.getValue().nextLink(), null)); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/LocationResourcesImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/LocationResourcesImpl.java new file mode 100644 index 0000000000..59faad49dd --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/LocationResourcesImpl.java @@ -0,0 +1,136 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.implementation; + +import azure.resourcemanager.resources.fluent.LocationResourcesClient; +import azure.resourcemanager.resources.fluent.models.LocationResourceInner; +import azure.resourcemanager.resources.models.LocationResource; +import azure.resourcemanager.resources.models.LocationResources; +import com.azure.core.http.rest.PagedIterable; +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; + +public final class LocationResourcesImpl implements LocationResources { + private static final ClientLogger LOGGER = new ClientLogger(LocationResourcesImpl.class); + + private final LocationResourcesClient innerClient; + + private final azure.resourcemanager.resources.ResourcesManager serviceManager; + + public LocationResourcesImpl(LocationResourcesClient innerClient, + azure.resourcemanager.resources.ResourcesManager serviceManager) { + this.innerClient = innerClient; + this.serviceManager = serviceManager; + } + + public Response getWithResponse(String location, String locationResourceName, Context context) { + Response inner + = this.serviceClient().getWithResponse(location, locationResourceName, context); + if (inner != null) { + return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(), + new LocationResourceImpl(inner.getValue(), this.manager())); + } else { + return null; + } + } + + public LocationResource get(String location, String locationResourceName) { + LocationResourceInner inner = this.serviceClient().get(location, locationResourceName); + if (inner != null) { + return new LocationResourceImpl(inner, this.manager()); + } else { + return null; + } + } + + public Response deleteByResourceGroupWithResponse(String location, String locationResourceName, + Context context) { + return this.serviceClient().deleteWithResponse(location, locationResourceName, context); + } + + public void deleteByResourceGroup(String location, String locationResourceName) { + this.serviceClient().delete(location, locationResourceName); + } + + public PagedIterable listByLocation(String location) { + PagedIterable inner = this.serviceClient().listByLocation(location); + return ResourceManagerUtils.mapPage(inner, inner1 -> new LocationResourceImpl(inner1, this.manager())); + } + + public PagedIterable listByLocation(String location, Context context) { + PagedIterable inner = this.serviceClient().listByLocation(location, context); + return ResourceManagerUtils.mapPage(inner, inner1 -> new LocationResourceImpl(inner1, this.manager())); + } + + public LocationResource getById(String id) { + String location = ResourceManagerUtils.getValueFromIdByName(id, "locations"); + if (location == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'locations'.", id))); + } + String locationResourceName = ResourceManagerUtils.getValueFromIdByName(id, "locationResources"); + if (locationResourceName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'locationResources'.", id))); + } + return this.getWithResponse(location, locationResourceName, Context.NONE).getValue(); + } + + public Response getByIdWithResponse(String id, Context context) { + String location = ResourceManagerUtils.getValueFromIdByName(id, "locations"); + if (location == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'locations'.", id))); + } + String locationResourceName = ResourceManagerUtils.getValueFromIdByName(id, "locationResources"); + if (locationResourceName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'locationResources'.", id))); + } + return this.getWithResponse(location, locationResourceName, context); + } + + public void deleteById(String id) { + String location = ResourceManagerUtils.getValueFromIdByName(id, "locations"); + if (location == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'locations'.", id))); + } + String locationResourceName = ResourceManagerUtils.getValueFromIdByName(id, "locationResources"); + if (locationResourceName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'locationResources'.", id))); + } + this.deleteByResourceGroupWithResponse(location, locationResourceName, Context.NONE); + } + + public Response deleteByIdWithResponse(String id, Context context) { + String location = ResourceManagerUtils.getValueFromIdByName(id, "locations"); + if (location == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'locations'.", id))); + } + String locationResourceName = ResourceManagerUtils.getValueFromIdByName(id, "locationResources"); + if (locationResourceName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'locationResources'.", id))); + } + return this.deleteByResourceGroupWithResponse(location, locationResourceName, context); + } + + private LocationResourcesClient serviceClient() { + return this.innerClient; + } + + private azure.resourcemanager.resources.ResourcesManager manager() { + return this.serviceManager; + } + + public LocationResourceImpl define(String name) { + return new LocationResourceImpl(name, this.manager()); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ResourcesClientImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ResourcesClientImpl.java index f7562d1b2c..a8c7113952 100644 --- a/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ResourcesClientImpl.java +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/ResourcesClientImpl.java @@ -4,6 +4,8 @@ package azure.resourcemanager.resources.implementation; +import azure.resourcemanager.resources.fluent.ExtensionsResourcesClient; +import azure.resourcemanager.resources.fluent.LocationResourcesClient; import azure.resourcemanager.resources.fluent.NestedsClient; import azure.resourcemanager.resources.fluent.ResourcesClient; import azure.resourcemanager.resources.fluent.SingletonsClient; @@ -167,6 +169,34 @@ public SingletonsClient getSingletons() { return this.singletons; } + /** + * The ExtensionsResourcesClient object to access its operations. + */ + private final ExtensionsResourcesClient extensionsResources; + + /** + * Gets the ExtensionsResourcesClient object to access its operations. + * + * @return the ExtensionsResourcesClient object. + */ + public ExtensionsResourcesClient getExtensionsResources() { + return this.extensionsResources; + } + + /** + * The LocationResourcesClient object to access its operations. + */ + private final LocationResourcesClient locationResources; + + /** + * Gets the LocationResourcesClient object to access its operations. + * + * @return the LocationResourcesClient object. + */ + public LocationResourcesClient getLocationResources() { + return this.locationResources; + } + /** * Initializes an instance of ResourcesClient client. * @@ -188,6 +218,8 @@ public SingletonsClient getSingletons() { this.topLevels = new TopLevelsClientImpl(this); this.nesteds = new NestedsClientImpl(this); this.singletons = new SingletonsClientImpl(this); + this.extensionsResources = new ExtensionsResourcesClientImpl(this); + this.locationResources = new LocationResourcesClientImpl(this); } /** diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/models/ExtensionsResourceListResult.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/models/ExtensionsResourceListResult.java new file mode 100644 index 0000000000..cea9f3ab43 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/models/ExtensionsResourceListResult.java @@ -0,0 +1,114 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.implementation.models; + +import azure.resourcemanager.resources.fluent.models.ExtensionsResourceInner; +import com.azure.core.annotation.Immutable; +import com.azure.core.util.logging.ClientLogger; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.List; + +/** + * The response of a ExtensionsResource list operation. + */ +@Immutable +public final class ExtensionsResourceListResult implements JsonSerializable { + /* + * The ExtensionsResource items on this page + */ + private List value; + + /* + * The link to the next page of items + */ + private String nextLink; + + /** + * Creates an instance of ExtensionsResourceListResult class. + */ + private ExtensionsResourceListResult() { + } + + /** + * Get the value property: The ExtensionsResource items on this page. + * + * @return the value value. + */ + public List value() { + return this.value; + } + + /** + * Get the nextLink property: The link to the next page of items. + * + * @return the nextLink value. + */ + public String nextLink() { + return this.nextLink; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + if (value() == null) { + throw LOGGER.atError() + .log(new IllegalArgumentException( + "Missing required property value in model ExtensionsResourceListResult")); + } else { + value().forEach(e -> e.validate()); + } + } + + private static final ClientLogger LOGGER = new ClientLogger(ExtensionsResourceListResult.class); + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("value", this.value, (writer, element) -> writer.writeJson(element)); + jsonWriter.writeStringField("nextLink", this.nextLink); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ExtensionsResourceListResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ExtensionsResourceListResult 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 ExtensionsResourceListResult. + */ + public static ExtensionsResourceListResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ExtensionsResourceListResult deserializedExtensionsResourceListResult = new ExtensionsResourceListResult(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + List value + = reader.readArray(reader1 -> ExtensionsResourceInner.fromJson(reader1)); + deserializedExtensionsResourceListResult.value = value; + } else if ("nextLink".equals(fieldName)) { + deserializedExtensionsResourceListResult.nextLink = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedExtensionsResourceListResult; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/models/LocationResourceListResult.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/models/LocationResourceListResult.java new file mode 100644 index 0000000000..a832b48337 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/implementation/models/LocationResourceListResult.java @@ -0,0 +1,114 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.implementation.models; + +import azure.resourcemanager.resources.fluent.models.LocationResourceInner; +import com.azure.core.annotation.Immutable; +import com.azure.core.util.logging.ClientLogger; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.List; + +/** + * The response of a LocationResource list operation. + */ +@Immutable +public final class LocationResourceListResult implements JsonSerializable { + /* + * The LocationResource items on this page + */ + private List value; + + /* + * The link to the next page of items + */ + private String nextLink; + + /** + * Creates an instance of LocationResourceListResult class. + */ + private LocationResourceListResult() { + } + + /** + * Get the value property: The LocationResource items on this page. + * + * @return the value value. + */ + public List value() { + return this.value; + } + + /** + * Get the nextLink property: The link to the next page of items. + * + * @return the nextLink value. + */ + public String nextLink() { + return this.nextLink; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + if (value() == null) { + throw LOGGER.atError() + .log(new IllegalArgumentException( + "Missing required property value in model LocationResourceListResult")); + } else { + value().forEach(e -> e.validate()); + } + } + + private static final ClientLogger LOGGER = new ClientLogger(LocationResourceListResult.class); + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeArrayField("value", this.value, (writer, element) -> writer.writeJson(element)); + jsonWriter.writeStringField("nextLink", this.nextLink); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of LocationResourceListResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of LocationResourceListResult 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 LocationResourceListResult. + */ + public static LocationResourceListResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + LocationResourceListResult deserializedLocationResourceListResult = new LocationResourceListResult(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("value".equals(fieldName)) { + List value + = reader.readArray(reader1 -> LocationResourceInner.fromJson(reader1)); + deserializedLocationResourceListResult.value = value; + } else if ("nextLink".equals(fieldName)) { + deserializedLocationResourceListResult.nextLink = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedLocationResourceListResult; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/models/ExtensionsResource.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/models/ExtensionsResource.java new file mode 100644 index 0000000000..a0889b1477 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/models/ExtensionsResource.java @@ -0,0 +1,180 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.models; + +import azure.resourcemanager.resources.fluent.models.ExtensionsResourceInner; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; + +/** + * An immutable client-side representation of ExtensionsResource. + */ +public interface ExtensionsResource { + /** + * 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. + */ + ExtensionsResourceProperties properties(); + + /** + * Gets the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + SystemData systemData(); + + /** + * Gets the inner azure.resourcemanager.resources.fluent.models.ExtensionsResourceInner object. + * + * @return the inner object. + */ + ExtensionsResourceInner innerModel(); + + /** + * The entirety of the ExtensionsResource definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithScope, DefinitionStages.WithCreate { + } + + /** + * The ExtensionsResource definition stages. + */ + interface DefinitionStages { + /** + * The first stage of the ExtensionsResource definition. + */ + interface Blank extends WithScope { + } + + /** + * The stage of the ExtensionsResource definition allowing to specify parent resource. + */ + interface WithScope { + /** + * Specifies resourceUri. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @return the next definition stage. + */ + WithCreate withExistingResourceUri(String resourceUri); + } + + /** + * The stage of the ExtensionsResource 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. + */ + ExtensionsResource create(); + + /** + * Executes the create request. + * + * @param context The context to associate with this operation. + * @return the created resource. + */ + ExtensionsResource create(Context context); + } + + /** + * The stage of the ExtensionsResource 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(ExtensionsResourceProperties properties); + } + } + + /** + * Begins update for the ExtensionsResource resource. + * + * @return the stage of resource update. + */ + ExtensionsResource.Update update(); + + /** + * The template for ExtensionsResource update. + */ + interface Update extends UpdateStages.WithProperties { + /** + * Executes the update request. + * + * @return the updated resource. + */ + ExtensionsResource apply(); + + /** + * Executes the update request. + * + * @param context The context to associate with this operation. + * @return the updated resource. + */ + ExtensionsResource apply(Context context); + } + + /** + * The ExtensionsResource update stages. + */ + interface UpdateStages { + /** + * The stage of the ExtensionsResource update 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. + */ + Update withProperties(ExtensionsResourceProperties properties); + } + } + + /** + * Refreshes the resource to sync with Azure. + * + * @return the refreshed resource. + */ + ExtensionsResource refresh(); + + /** + * Refreshes the resource to sync with Azure. + * + * @param context The context to associate with this operation. + * @return the refreshed resource. + */ + ExtensionsResource refresh(Context context); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/models/ExtensionsResourceProperties.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/models/ExtensionsResourceProperties.java new file mode 100644 index 0000000000..085c694e08 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/models/ExtensionsResourceProperties.java @@ -0,0 +1,110 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.models; + +import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * ExtensionsResource properties. + */ +@Fluent +public final class ExtensionsResourceProperties implements JsonSerializable { + /* + * The description of the resource. + */ + private String description; + + /* + * The status of the last operation. + */ + private ProvisioningState provisioningState; + + /** + * Creates an instance of ExtensionsResourceProperties class. + */ + public ExtensionsResourceProperties() { + } + + /** + * Get the description property: The description of the resource. + * + * @return the description value. + */ + public String description() { + return this.description; + } + + /** + * Set the description property: The description of the resource. + * + * @param description the description value to set. + * @return the ExtensionsResourceProperties object itself. + */ + public ExtensionsResourceProperties withDescription(String description) { + this.description = description; + return this; + } + + /** + * Get the provisioningState property: The status of the last operation. + * + * @return the provisioningState value. + */ + public ProvisioningState provisioningState() { + return this.provisioningState; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("description", this.description); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ExtensionsResourceProperties from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ExtensionsResourceProperties 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 ExtensionsResourceProperties. + */ + public static ExtensionsResourceProperties fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + ExtensionsResourceProperties deserializedExtensionsResourceProperties = new ExtensionsResourceProperties(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("description".equals(fieldName)) { + deserializedExtensionsResourceProperties.description = reader.getString(); + } else if ("provisioningState".equals(fieldName)) { + deserializedExtensionsResourceProperties.provisioningState + = ProvisioningState.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + + return deserializedExtensionsResourceProperties; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/models/ExtensionsResources.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/models/ExtensionsResources.java new file mode 100644 index 0000000000..89169d9680 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/models/ExtensionsResources.java @@ -0,0 +1,140 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.models; + +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; + +/** + * Resource collection API of ExtensionsResources. + */ +public interface ExtensionsResources { + /** + * Get a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 ExtensionsResource along with {@link Response}. + */ + Response getWithResponse(String resourceUri, String extensionsResourceName, Context context); + + /** + * Get a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 ExtensionsResource. + */ + ExtensionsResource get(String resourceUri, String extensionsResourceName); + + /** + * Delete a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 deleteByResourceGroupWithResponse(String resourceUri, String extensionsResourceName, + Context context); + + /** + * Delete a ExtensionsResource. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @param extensionsResourceName The name of the ExtensionsResource. + * @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 deleteByResourceGroup(String resourceUri, String extensionsResourceName); + + /** + * List ExtensionsResource resources by parent. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @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 response of a ExtensionsResource list operation as paginated response with {@link PagedIterable}. + */ + PagedIterable listByScope(String resourceUri); + + /** + * List ExtensionsResource resources by parent. + * + * @param resourceUri The fully qualified Azure Resource manager identifier of the resource. + * @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 response of a ExtensionsResource list operation as paginated response with {@link PagedIterable}. + */ + PagedIterable listByScope(String resourceUri, Context context); + + /** + * Get a ExtensionsResource. + * + * @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 ExtensionsResource along with {@link Response}. + */ + ExtensionsResource getById(String id); + + /** + * Get a ExtensionsResource. + * + * @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 ExtensionsResource along with {@link Response}. + */ + Response getByIdWithResponse(String id, Context context); + + /** + * Delete a ExtensionsResource. + * + * @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 deleteById(String id); + + /** + * Delete a ExtensionsResource. + * + * @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 deleteByIdWithResponse(String id, Context context); + + /** + * Begins definition for a new ExtensionsResource resource. + * + * @param name resource name. + * @return the first stage of the new ExtensionsResource definition. + */ + ExtensionsResource.DefinitionStages.Blank define(String name); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/models/LocationResource.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/models/LocationResource.java new file mode 100644 index 0000000000..437d9311d1 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/models/LocationResource.java @@ -0,0 +1,181 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.models; + +import azure.resourcemanager.resources.fluent.models.LocationResourceInner; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; + +/** + * An immutable client-side representation of LocationResource. + */ +public interface LocationResource { + /** + * 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. + */ + LocationResourceProperties properties(); + + /** + * Gets the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + SystemData systemData(); + + /** + * Gets the inner azure.resourcemanager.resources.fluent.models.LocationResourceInner object. + * + * @return the inner object. + */ + LocationResourceInner innerModel(); + + /** + * The entirety of the LocationResource definition. + */ + interface Definition + extends DefinitionStages.Blank, DefinitionStages.WithParentResource, DefinitionStages.WithCreate { + } + + /** + * The LocationResource definition stages. + */ + interface DefinitionStages { + /** + * The first stage of the LocationResource definition. + */ + interface Blank extends WithParentResource { + } + + /** + * The stage of the LocationResource definition allowing to specify parent resource. + */ + interface WithParentResource { + /** + * Specifies location. + * + * @param location The name of the Azure region. + * @return the next definition stage. + */ + WithCreate withExistingLocation(String location); + } + + /** + * The stage of the LocationResource 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. + */ + LocationResource create(); + + /** + * Executes the create request. + * + * @param context The context to associate with this operation. + * @return the created resource. + */ + LocationResource create(Context context); + } + + /** + * The stage of the LocationResource 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(LocationResourceProperties properties); + } + } + + /** + * Begins update for the LocationResource resource. + * + * @return the stage of resource update. + */ + LocationResource.Update update(); + + /** + * The template for LocationResource update. + */ + interface Update extends UpdateStages.WithProperties { + /** + * Executes the update request. + * + * @return the updated resource. + */ + LocationResource apply(); + + /** + * Executes the update request. + * + * @param context The context to associate with this operation. + * @return the updated resource. + */ + LocationResource apply(Context context); + } + + /** + * The LocationResource update stages. + */ + interface UpdateStages { + /** + * The stage of the LocationResource update 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. + */ + Update withProperties(LocationResourceProperties properties); + } + } + + /** + * Refreshes the resource to sync with Azure. + * + * @return the refreshed resource. + */ + LocationResource refresh(); + + /** + * Refreshes the resource to sync with Azure. + * + * @param context The context to associate with this operation. + * @return the refreshed resource. + */ + LocationResource refresh(Context context); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/models/LocationResourceProperties.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/models/LocationResourceProperties.java new file mode 100644 index 0000000000..5e1a15f3c7 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/models/LocationResourceProperties.java @@ -0,0 +1,110 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.models; + +import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Location resource properties. + */ +@Fluent +public final class LocationResourceProperties implements JsonSerializable { + /* + * The description of the resource. + */ + private String description; + + /* + * The status of the last operation. + */ + private ProvisioningState provisioningState; + + /** + * Creates an instance of LocationResourceProperties class. + */ + public LocationResourceProperties() { + } + + /** + * Get the description property: The description of the resource. + * + * @return the description value. + */ + public String description() { + return this.description; + } + + /** + * Set the description property: The description of the resource. + * + * @param description the description value to set. + * @return the LocationResourceProperties object itself. + */ + public LocationResourceProperties withDescription(String description) { + this.description = description; + return this; + } + + /** + * Get the provisioningState property: The status of the last operation. + * + * @return the provisioningState value. + */ + public ProvisioningState provisioningState() { + return this.provisioningState; + } + + /** + * Validates the instance. + * + * @throws IllegalArgumentException thrown if the instance is not valid. + */ + public void validate() { + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("description", this.description); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of LocationResourceProperties from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of LocationResourceProperties 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 LocationResourceProperties. + */ + public static LocationResourceProperties fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + LocationResourceProperties deserializedLocationResourceProperties = new LocationResourceProperties(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("description".equals(fieldName)) { + deserializedLocationResourceProperties.description = reader.getString(); + } else if ("provisioningState".equals(fieldName)) { + deserializedLocationResourceProperties.provisioningState + = ProvisioningState.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + + return deserializedLocationResourceProperties; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/resources/models/LocationResources.java b/typespec-tests/src/main/java/azure/resourcemanager/resources/models/LocationResources.java new file mode 100644 index 0000000000..d80a2171f3 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/resources/models/LocationResources.java @@ -0,0 +1,139 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.resources.models; + +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; + +/** + * Resource collection API of LocationResources. + */ +public interface LocationResources { + /** + * Get a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 LocationResource along with {@link Response}. + */ + Response getWithResponse(String location, String locationResourceName, Context context); + + /** + * Get a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 LocationResource. + */ + LocationResource get(String location, String locationResourceName); + + /** + * Delete a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 deleteByResourceGroupWithResponse(String location, String locationResourceName, Context context); + + /** + * Delete a LocationResource. + * + * @param location The name of the Azure region. + * @param locationResourceName The name of the LocationResource. + * @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 deleteByResourceGroup(String location, String locationResourceName); + + /** + * List LocationResource resources by SubscriptionLocationResource. + * + * @param location The name of the Azure region. + * @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 response of a LocationResource list operation as paginated response with {@link PagedIterable}. + */ + PagedIterable listByLocation(String location); + + /** + * List LocationResource resources by SubscriptionLocationResource. + * + * @param location The name of the Azure region. + * @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 response of a LocationResource list operation as paginated response with {@link PagedIterable}. + */ + PagedIterable listByLocation(String location, Context context); + + /** + * Get a LocationResource. + * + * @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 LocationResource along with {@link Response}. + */ + LocationResource getById(String id); + + /** + * Get a LocationResource. + * + * @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 LocationResource along with {@link Response}. + */ + Response getByIdWithResponse(String id, Context context); + + /** + * Delete a LocationResource. + * + * @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 deleteById(String id); + + /** + * Delete a LocationResource. + * + * @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 deleteByIdWithResponse(String id, Context context); + + /** + * Begins definition for a new LocationResource resource. + * + * @param name resource name. + * @return the first stage of the new LocationResource definition. + */ + LocationResource.DefinitionStages.Blank define(String name); +} diff --git a/typespec-tests/src/main/java/client/clientnamespace/ClientNamespaceFirstAsyncClient.java b/typespec-tests/src/main/java/client/clientnamespace/ClientNamespaceFirstAsyncClient.java new file mode 100644 index 0000000000..6e716aaaf6 --- /dev/null +++ b/typespec-tests/src/main/java/client/clientnamespace/ClientNamespaceFirstAsyncClient.java @@ -0,0 +1,84 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package client.clientnamespace; + +import client.clientnamespace.first.models.FirstClientResult; +import client.clientnamespace.implementation.ClientNamespaceFirstClientImpl; +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; + +/** + * Initializes a new instance of the asynchronous ClientNamespaceFirstClient type. + */ +@ServiceClient(builder = ClientNamespaceFirstClientBuilder.class, isAsync = true) +public final class ClientNamespaceFirstAsyncClient { + @Generated + private final ClientNamespaceFirstClientImpl serviceClient; + + /** + * Initializes an instance of ClientNamespaceFirstAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + ClientNamespaceFirstAsyncClient(ClientNamespaceFirstClientImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The getFirst operation. + *

Response Body Schema

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

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getFirstWithResponse(RequestOptions requestOptions) { + return this.serviceClient.getFirstWithResponse(requestOptions); + } + + /** + * The getFirst operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public FirstClientResult getFirst() { + // Generated convenience method for getFirstWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getFirstWithResponse(requestOptions).getValue().toObject(FirstClientResult.class); + } +} diff --git a/typespec-tests/src/main/java/client/clientnamespace/ClientNamespaceFirstClientBuilder.java b/typespec-tests/src/main/java/client/clientnamespace/ClientNamespaceFirstClientBuilder.java new file mode 100644 index 0000000000..574990ffcc --- /dev/null +++ b/typespec-tests/src/main/java/client/clientnamespace/ClientNamespaceFirstClientBuilder.java @@ -0,0 +1,287 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package client.clientnamespace; + +import client.clientnamespace.implementation.ClientNamespaceFirstClientImpl; +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.client.traits.ConfigurationTrait; +import com.azure.core.client.traits.EndpointTrait; +import com.azure.core.client.traits.HttpTrait; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; +import com.azure.core.http.policy.AddHeadersPolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.ClientOptions; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.builder.ClientBuilderUtil; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.serializer.JacksonAdapter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * A builder for creating a new instance of the ClientNamespaceFirstClient type. + */ +@ServiceClientBuilder(serviceClients = { ClientNamespaceFirstClient.class, ClientNamespaceFirstAsyncClient.class }) +public final class ClientNamespaceFirstClientBuilder implements HttpTrait, + ConfigurationTrait, EndpointTrait { + @Generated + private static final String SDK_NAME = "name"; + + @Generated + private static final String SDK_VERSION = "version"; + + @Generated + private static final Map PROPERTIES = CoreUtils.getProperties("client-clientnamespace.properties"); + + @Generated + private final List pipelinePolicies; + + /** + * Create an instance of the ClientNamespaceFirstClientBuilder. + */ + @Generated + public ClientNamespaceFirstClientBuilder() { + this.pipelinePolicies = new ArrayList<>(); + } + + /* + * The HTTP pipeline to send requests through. + */ + @Generated + private HttpPipeline pipeline; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceFirstClientBuilder pipeline(HttpPipeline pipeline) { + if (this.pipeline != null && pipeline == null) { + LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured."); + } + this.pipeline = pipeline; + return this; + } + + /* + * The HTTP client used to send the request. + */ + @Generated + private HttpClient httpClient; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceFirstClientBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /* + * The logging configuration for HTTP requests and responses. + */ + @Generated + private HttpLogOptions httpLogOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceFirstClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = httpLogOptions; + return this; + } + + /* + * The client options such as application ID and custom headers to set on a request. + */ + @Generated + private ClientOptions clientOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceFirstClientBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + return this; + } + + /* + * The retry options to configure retry policy for failed requests. + */ + @Generated + private RetryOptions retryOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceFirstClientBuilder retryOptions(RetryOptions retryOptions) { + this.retryOptions = retryOptions; + return this; + } + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceFirstClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { + Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null."); + pipelinePolicies.add(customPolicy); + return this; + } + + /* + * The configuration store that is used during construction of the service client. + */ + @Generated + private Configuration configuration; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceFirstClientBuilder configuration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + /* + * The service endpoint + */ + @Generated + private String endpoint; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceFirstClientBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * The retry policy that will attempt to retry failed requests, if applicable. + */ + @Generated + private RetryPolicy retryPolicy; + + /** + * Sets The retry policy that will attempt to retry failed requests, if applicable. + * + * @param retryPolicy the retryPolicy value. + * @return the ClientNamespaceFirstClientBuilder. + */ + @Generated + public ClientNamespaceFirstClientBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + + /** + * Builds an instance of ClientNamespaceFirstClientImpl with the provided parameters. + * + * @return an instance of ClientNamespaceFirstClientImpl. + */ + @Generated + private ClientNamespaceFirstClientImpl buildInnerClient() { + this.validateClient(); + HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); + String localEndpoint = (endpoint != null) ? endpoint : "http://localhost:3000"; + ClientNamespaceFirstClientImpl client = new ClientNamespaceFirstClientImpl(localPipeline, + JacksonAdapter.createDefaultSerializerAdapter(), localEndpoint); + return client; + } + + @Generated + private void validateClient() { + // This method is invoked from 'buildInnerClient'/'buildClient' method. + // Developer can customize this method, to validate that the necessary conditions are met for the new client. + } + + @Generated + private HttpPipeline createHttpPipeline() { + Configuration buildConfiguration + = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; + HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions; + ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions; + List policies = new ArrayList<>(); + String clientName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName"); + String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); + String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions); + policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + policies.add(new RequestIdPolicy()); + policies.add(new AddHeadersFromContextPolicy()); + HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(localClientOptions); + if (headers != null) { + policies.add(new AddHeadersPolicy(headers)); + } + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); + policies.add(new AddDatePolicy()); + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(localHttpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) + .httpClient(httpClient) + .clientOptions(localClientOptions) + .build(); + return httpPipeline; + } + + /** + * Builds an instance of ClientNamespaceFirstAsyncClient class. + * + * @return an instance of ClientNamespaceFirstAsyncClient. + */ + @Generated + public ClientNamespaceFirstAsyncClient buildAsyncClient() { + return new ClientNamespaceFirstAsyncClient(buildInnerClient()); + } + + /** + * Builds an instance of ClientNamespaceFirstClient class. + * + * @return an instance of ClientNamespaceFirstClient. + */ + @Generated + public ClientNamespaceFirstClient buildClient() { + return new ClientNamespaceFirstClient(buildInnerClient()); + } + + private static final ClientLogger LOGGER = new ClientLogger(ClientNamespaceFirstClientBuilder.class); +} diff --git a/typespec-tests/src/main/java/client/clientnamespace/first/models/FirstClientResult.java b/typespec-tests/src/main/java/client/clientnamespace/first/models/FirstClientResult.java new file mode 100644 index 0000000000..13834159eb --- /dev/null +++ b/typespec-tests/src/main/java/client/clientnamespace/first/models/FirstClientResult.java @@ -0,0 +1,83 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package client.clientnamespace.first.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The FirstClientResult model. + */ +@Immutable +public final class FirstClientResult implements JsonSerializable { + /* + * The name property. + */ + @Generated + private final String name; + + /** + * Creates an instance of FirstClientResult class. + * + * @param name the name value to set. + */ + @Generated + private FirstClientResult(String name) { + this.name = name; + } + + /** + * Get the name property: The name property. + * + * @return the name value. + */ + @Generated + public String getName() { + return this.name; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("name", this.name); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of FirstClientResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of FirstClientResult 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 FirstClientResult. + */ + @Generated + public static FirstClientResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + String name = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("name".equals(fieldName)) { + name = reader.getString(); + } else { + reader.skipChildren(); + } + } + return new FirstClientResult(name); + }); + } +} diff --git a/typespec-tests/src/main/java/client/clientnamespace/first/models/package-info.java b/typespec-tests/src/main/java/client/clientnamespace/first/models/package-info.java new file mode 100644 index 0000000000..390a58aee3 --- /dev/null +++ b/typespec-tests/src/main/java/client/clientnamespace/first/models/package-info.java @@ -0,0 +1,11 @@ +// 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 ClientNamespace. + * Illustrates the clientNamespace cases. + * + */ +package client.clientnamespace.first.models; diff --git a/typespec-tests/src/main/java/client/clientnamespace/implementation/ClientNamespaceFirstClientImpl.java b/typespec-tests/src/main/java/client/clientnamespace/implementation/ClientNamespaceFirstClientImpl.java new file mode 100644 index 0000000000..76360560b2 --- /dev/null +++ b/typespec-tests/src/main/java/client/clientnamespace/implementation/ClientNamespaceFirstClientImpl.java @@ -0,0 +1,196 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package client.clientnamespace.implementation; + +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.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.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; +import reactor.core.publisher.Mono; + +/** + * Initializes a new instance of the ClientNamespaceFirstClient type. + */ +public final class ClientNamespaceFirstClientImpl { + /** + * The proxy service used to perform REST calls. + */ + private final ClientNamespaceFirstClientService service; + + /** + * Service host. + */ + private final String endpoint; + + /** + * Gets Service host. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** + * The HTTP pipeline to send requests through. + */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The serializer to serialize an object into a string. + */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + public SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * Initializes an instance of ClientNamespaceFirstClient client. + * + * @param endpoint Service host. + */ + public ClientNamespaceFirstClientImpl(String endpoint) { + this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(), + JacksonAdapter.createDefaultSerializerAdapter(), endpoint); + } + + /** + * Initializes an instance of ClientNamespaceFirstClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param endpoint Service host. + */ + public ClientNamespaceFirstClientImpl(HttpPipeline httpPipeline, String endpoint) { + this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint); + } + + /** + * Initializes an instance of ClientNamespaceFirstClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param endpoint Service host. + */ + public ClientNamespaceFirstClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, + String endpoint) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.endpoint = endpoint; + this.service + = RestProxy.create(ClientNamespaceFirstClientService.class, this.httpPipeline, this.getSerializerAdapter()); + } + + /** + * The interface defining all the services for ClientNamespaceFirstClient to be used by the proxy service to perform + * REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "ClientNamespaceFirst") + public interface ClientNamespaceFirstClientService { + @Get("/client/client-namespace/first") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getFirst(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/client/client-namespace/first") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response getFirstSync(@HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + } + + /** + * The getFirst operation. + *

Response Body Schema

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

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getFirstWithResponse(RequestOptions requestOptions) { + final String accept = "application/json"; + return service.getFirstSync(this.getEndpoint(), accept, requestOptions, Context.NONE); + } +} diff --git a/typespec-tests/src/main/java/client/clientnamespace/implementation/ClientNamespaceSecondClientImpl.java b/typespec-tests/src/main/java/client/clientnamespace/implementation/ClientNamespaceSecondClientImpl.java new file mode 100644 index 0000000000..1de49de1e8 --- /dev/null +++ b/typespec-tests/src/main/java/client/clientnamespace/implementation/ClientNamespaceSecondClientImpl.java @@ -0,0 +1,196 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package client.clientnamespace.implementation; + +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.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.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; +import reactor.core.publisher.Mono; + +/** + * Initializes a new instance of the ClientNamespaceSecondClient type. + */ +public final class ClientNamespaceSecondClientImpl { + /** + * The proxy service used to perform REST calls. + */ + private final ClientNamespaceSecondClientService service; + + /** + * Service host. + */ + private final String endpoint; + + /** + * Gets Service host. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** + * The HTTP pipeline to send requests through. + */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The serializer to serialize an object into a string. + */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + public SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * Initializes an instance of ClientNamespaceSecondClient client. + * + * @param endpoint Service host. + */ + public ClientNamespaceSecondClientImpl(String endpoint) { + this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(), + JacksonAdapter.createDefaultSerializerAdapter(), endpoint); + } + + /** + * Initializes an instance of ClientNamespaceSecondClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param endpoint Service host. + */ + public ClientNamespaceSecondClientImpl(HttpPipeline httpPipeline, String endpoint) { + this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint); + } + + /** + * Initializes an instance of ClientNamespaceSecondClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param endpoint Service host. + */ + public ClientNamespaceSecondClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, + String endpoint) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.endpoint = endpoint; + this.service = RestProxy.create(ClientNamespaceSecondClientService.class, this.httpPipeline, + this.getSerializerAdapter()); + } + + /** + * The interface defining all the services for ClientNamespaceSecondClient to be used by the proxy service to + * perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "ClientNamespaceSecon") + public interface ClientNamespaceSecondClientService { + @Get("/client/client-namespace/second") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getSecond(@HostParam("endpoint") String endpoint, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/client/client-namespace/second") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response getSecondSync(@HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + } + + /** + * The getSecond operation. + *

Response Body Schema

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

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     type: String(second) (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getSecondWithResponse(RequestOptions requestOptions) { + final String accept = "application/json"; + return service.getSecondSync(this.getEndpoint(), accept, requestOptions, Context.NONE); + } +} diff --git a/typespec-tests/src/main/java/client/clientnamespace/implementation/package-info.java b/typespec-tests/src/main/java/client/clientnamespace/implementation/package-info.java new file mode 100644 index 0000000000..cd067e55ce --- /dev/null +++ b/typespec-tests/src/main/java/client/clientnamespace/implementation/package-info.java @@ -0,0 +1,11 @@ +// 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 ClientNamespace. + * Illustrates the clientNamespace cases. + * + */ +package client.clientnamespace.implementation; diff --git a/typespec-tests/src/main/java/payload/pageable/serverdrivenpagination/models/package-info.java b/typespec-tests/src/main/java/client/clientnamespace/package-info.java similarity index 62% rename from typespec-tests/src/main/java/payload/pageable/serverdrivenpagination/models/package-info.java rename to typespec-tests/src/main/java/client/clientnamespace/package-info.java index c88442bcae..32ea24a8ff 100644 --- a/typespec-tests/src/main/java/payload/pageable/serverdrivenpagination/models/package-info.java +++ b/typespec-tests/src/main/java/client/clientnamespace/package-info.java @@ -4,8 +4,8 @@ /** * - * Package containing the data models for Pageable. - * Test for pageable payload. + * Package containing the classes for ClientNamespace. + * Illustrates the clientNamespace cases. * */ -package payload.pageable.serverdrivenpagination.models; +package client.clientnamespace; diff --git a/typespec-tests/src/main/java/client/clientnamespace/second/ClientNamespaceSecondAsyncClient.java b/typespec-tests/src/main/java/client/clientnamespace/second/ClientNamespaceSecondAsyncClient.java new file mode 100644 index 0000000000..8416dc8451 --- /dev/null +++ b/typespec-tests/src/main/java/client/clientnamespace/second/ClientNamespaceSecondAsyncClient.java @@ -0,0 +1,84 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package client.clientnamespace.second; + +import client.clientnamespace.implementation.ClientNamespaceSecondClientImpl; +import client.clientnamespace.second.models.SecondClientResult; +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; + +/** + * Initializes a new instance of the asynchronous ClientNamespaceSecondClient type. + */ +@ServiceClient(builder = ClientNamespaceSecondClientBuilder.class, isAsync = true) +public final class ClientNamespaceSecondAsyncClient { + @Generated + private final ClientNamespaceSecondClientImpl serviceClient; + + /** + * Initializes an instance of ClientNamespaceSecondAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + ClientNamespaceSecondAsyncClient(ClientNamespaceSecondClientImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The getSecond operation. + *

Response Body Schema

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

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     type: String(second) (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getSecondWithResponse(RequestOptions requestOptions) { + return this.serviceClient.getSecondWithResponse(requestOptions); + } + + /** + * The getSecond operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the response. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public SecondClientResult getSecond() { + // Generated convenience method for getSecondWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getSecondWithResponse(requestOptions).getValue().toObject(SecondClientResult.class); + } +} diff --git a/typespec-tests/src/main/java/client/clientnamespace/second/ClientNamespaceSecondClientBuilder.java b/typespec-tests/src/main/java/client/clientnamespace/second/ClientNamespaceSecondClientBuilder.java new file mode 100644 index 0000000000..d5866430aa --- /dev/null +++ b/typespec-tests/src/main/java/client/clientnamespace/second/ClientNamespaceSecondClientBuilder.java @@ -0,0 +1,287 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package client.clientnamespace.second; + +import client.clientnamespace.implementation.ClientNamespaceSecondClientImpl; +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.client.traits.ConfigurationTrait; +import com.azure.core.client.traits.EndpointTrait; +import com.azure.core.client.traits.HttpTrait; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; +import com.azure.core.http.policy.AddHeadersPolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.ClientOptions; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.builder.ClientBuilderUtil; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.serializer.JacksonAdapter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; + +/** + * A builder for creating a new instance of the ClientNamespaceSecondClient type. + */ +@ServiceClientBuilder(serviceClients = { ClientNamespaceSecondClient.class, ClientNamespaceSecondAsyncClient.class }) +public final class ClientNamespaceSecondClientBuilder implements HttpTrait, + ConfigurationTrait, EndpointTrait { + @Generated + private static final String SDK_NAME = "name"; + + @Generated + private static final String SDK_VERSION = "version"; + + @Generated + private static final Map PROPERTIES = CoreUtils.getProperties("client-clientnamespace.properties"); + + @Generated + private final List pipelinePolicies; + + /** + * Create an instance of the ClientNamespaceSecondClientBuilder. + */ + @Generated + public ClientNamespaceSecondClientBuilder() { + this.pipelinePolicies = new ArrayList<>(); + } + + /* + * The HTTP pipeline to send requests through. + */ + @Generated + private HttpPipeline pipeline; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceSecondClientBuilder pipeline(HttpPipeline pipeline) { + if (this.pipeline != null && pipeline == null) { + LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured."); + } + this.pipeline = pipeline; + return this; + } + + /* + * The HTTP client used to send the request. + */ + @Generated + private HttpClient httpClient; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceSecondClientBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /* + * The logging configuration for HTTP requests and responses. + */ + @Generated + private HttpLogOptions httpLogOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceSecondClientBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = httpLogOptions; + return this; + } + + /* + * The client options such as application ID and custom headers to set on a request. + */ + @Generated + private ClientOptions clientOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceSecondClientBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + return this; + } + + /* + * The retry options to configure retry policy for failed requests. + */ + @Generated + private RetryOptions retryOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceSecondClientBuilder retryOptions(RetryOptions retryOptions) { + this.retryOptions = retryOptions; + return this; + } + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceSecondClientBuilder addPolicy(HttpPipelinePolicy customPolicy) { + Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null."); + pipelinePolicies.add(customPolicy); + return this; + } + + /* + * The configuration store that is used during construction of the service client. + */ + @Generated + private Configuration configuration; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceSecondClientBuilder configuration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + /* + * The service endpoint + */ + @Generated + private String endpoint; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public ClientNamespaceSecondClientBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * The retry policy that will attempt to retry failed requests, if applicable. + */ + @Generated + private RetryPolicy retryPolicy; + + /** + * Sets The retry policy that will attempt to retry failed requests, if applicable. + * + * @param retryPolicy the retryPolicy value. + * @return the ClientNamespaceSecondClientBuilder. + */ + @Generated + public ClientNamespaceSecondClientBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + + /** + * Builds an instance of ClientNamespaceSecondClientImpl with the provided parameters. + * + * @return an instance of ClientNamespaceSecondClientImpl. + */ + @Generated + private ClientNamespaceSecondClientImpl buildInnerClient() { + this.validateClient(); + HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); + String localEndpoint = (endpoint != null) ? endpoint : "http://localhost:3000"; + ClientNamespaceSecondClientImpl client = new ClientNamespaceSecondClientImpl(localPipeline, + JacksonAdapter.createDefaultSerializerAdapter(), localEndpoint); + return client; + } + + @Generated + private void validateClient() { + // This method is invoked from 'buildInnerClient'/'buildClient' method. + // Developer can customize this method, to validate that the necessary conditions are met for the new client. + } + + @Generated + private HttpPipeline createHttpPipeline() { + Configuration buildConfiguration + = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; + HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions; + ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions; + List policies = new ArrayList<>(); + String clientName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName"); + String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); + String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions); + policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + policies.add(new RequestIdPolicy()); + policies.add(new AddHeadersFromContextPolicy()); + HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(localClientOptions); + if (headers != null) { + policies.add(new AddHeadersPolicy(headers)); + } + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); + policies.add(new AddDatePolicy()); + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(localHttpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) + .httpClient(httpClient) + .clientOptions(localClientOptions) + .build(); + return httpPipeline; + } + + /** + * Builds an instance of ClientNamespaceSecondAsyncClient class. + * + * @return an instance of ClientNamespaceSecondAsyncClient. + */ + @Generated + public ClientNamespaceSecondAsyncClient buildAsyncClient() { + return new ClientNamespaceSecondAsyncClient(buildInnerClient()); + } + + /** + * Builds an instance of ClientNamespaceSecondClient class. + * + * @return an instance of ClientNamespaceSecondClient. + */ + @Generated + public ClientNamespaceSecondClient buildClient() { + return new ClientNamespaceSecondClient(buildInnerClient()); + } + + private static final ClientLogger LOGGER = new ClientLogger(ClientNamespaceSecondClientBuilder.class); +} diff --git a/typespec-tests/src/main/java/client/clientnamespace/second/models/SecondClientResult.java b/typespec-tests/src/main/java/client/clientnamespace/second/models/SecondClientResult.java new file mode 100644 index 0000000000..5e0324070d --- /dev/null +++ b/typespec-tests/src/main/java/client/clientnamespace/second/models/SecondClientResult.java @@ -0,0 +1,84 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package client.clientnamespace.second.models; + +import client.clientnamespace.second.sub.models.SecondClientEnumType; +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The SecondClientResult model. + */ +@Immutable +public final class SecondClientResult implements JsonSerializable { + /* + * The type property. + */ + @Generated + private final SecondClientEnumType type; + + /** + * Creates an instance of SecondClientResult class. + * + * @param type the type value to set. + */ + @Generated + private SecondClientResult(SecondClientEnumType type) { + this.type = type; + } + + /** + * Get the type property: The type property. + * + * @return the type value. + */ + @Generated + public SecondClientEnumType getType() { + return this.type; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("type", this.type == null ? null : this.type.toString()); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SecondClientResult from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SecondClientResult 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 SecondClientResult. + */ + @Generated + public static SecondClientResult fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + SecondClientEnumType type = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("type".equals(fieldName)) { + type = SecondClientEnumType.fromString(reader.getString()); + } else { + reader.skipChildren(); + } + } + return new SecondClientResult(type); + }); + } +} diff --git a/typespec-tests/src/main/java/client/clientnamespace/second/models/package-info.java b/typespec-tests/src/main/java/client/clientnamespace/second/models/package-info.java new file mode 100644 index 0000000000..4c5d7b940a --- /dev/null +++ b/typespec-tests/src/main/java/client/clientnamespace/second/models/package-info.java @@ -0,0 +1,11 @@ +// 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 ClientNamespace. + * Illustrates the clientNamespace cases. + * + */ +package client.clientnamespace.second.models; diff --git a/typespec-tests/src/main/java/client/clientnamespace/second/package-info.java b/typespec-tests/src/main/java/client/clientnamespace/second/package-info.java new file mode 100644 index 0000000000..cd4f158ff5 --- /dev/null +++ b/typespec-tests/src/main/java/client/clientnamespace/second/package-info.java @@ -0,0 +1,11 @@ +// 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 ClientNamespaceSecondClient. + * Illustrates the clientNamespace cases. + * + */ +package client.clientnamespace.second; diff --git a/typespec-tests/src/main/java/client/clientnamespace/second/sub/models/SecondClientEnumType.java b/typespec-tests/src/main/java/client/clientnamespace/second/sub/models/SecondClientEnumType.java new file mode 100644 index 0000000000..ba7b1afaf5 --- /dev/null +++ b/typespec-tests/src/main/java/client/clientnamespace/second/sub/models/SecondClientEnumType.java @@ -0,0 +1,51 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package client.clientnamespace.second.sub.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * Defines values for SecondClientEnumType. + */ +public final class SecondClientEnumType extends ExpandableStringEnum { + /** + * Static value second for SecondClientEnumType. + */ + @Generated + public static final SecondClientEnumType SECOND = fromString("second"); + + /** + * Creates a new instance of SecondClientEnumType value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Generated + @Deprecated + public SecondClientEnumType() { + } + + /** + * Creates or finds a SecondClientEnumType from its string representation. + * + * @param name a name to look for. + * @return the corresponding SecondClientEnumType. + */ + @Generated + public static SecondClientEnumType fromString(String name) { + return fromString(name, SecondClientEnumType.class); + } + + /** + * Gets known SecondClientEnumType values. + * + * @return known SecondClientEnumType values. + */ + @Generated + public static Collection values() { + return values(SecondClientEnumType.class); + } +} diff --git a/typespec-tests/src/main/java/client/clientnamespace/second/sub/models/package-info.java b/typespec-tests/src/main/java/client/clientnamespace/second/sub/models/package-info.java new file mode 100644 index 0000000000..9082e6ae77 --- /dev/null +++ b/typespec-tests/src/main/java/client/clientnamespace/second/sub/models/package-info.java @@ -0,0 +1,11 @@ +// 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 ClientNamespace. + * Illustrates the clientNamespace cases. + * + */ +package client.clientnamespace.second.sub.models; diff --git a/typespec-tests/src/main/java/payload/pageable/PageableAsyncClient.java b/typespec-tests/src/main/java/payload/pageable/PageableAsyncClient.java index d1feec3d6e..6d82dee186 100644 --- a/typespec-tests/src/main/java/payload/pageable/PageableAsyncClient.java +++ b/typespec-tests/src/main/java/payload/pageable/PageableAsyncClient.java @@ -12,13 +12,15 @@ import com.azure.core.exception.HttpResponseException; import com.azure.core.exception.ResourceModifiedException; import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; import com.azure.core.http.rest.RequestOptions; -import com.azure.core.http.rest.Response; import com.azure.core.util.BinaryData; -import com.azure.core.util.FluxUtil; +import java.util.stream.Collectors; import payload.pageable.implementation.ServerDrivenPaginationsImpl; -import payload.pageable.serverdrivenpagination.models.LinkResponse; -import reactor.core.publisher.Mono; +import payload.pageable.models.Pet; +import reactor.core.publisher.Flux; /** * Initializes a new instance of the asynchronous PageableClient type. @@ -45,18 +47,8 @@ public final class PageableAsyncClient { *
      * {@code
      * {
-     *     pets (Required): [
-     *          (Required){
-     *             id: String (Required)
-     *             name: String (Required)
-     *         }
-     *     ]
-     *     links (Required): {
-     *         next: String (Optional)
-     *         prev: String (Optional)
-     *         first: String (Optional)
-     *         last: String (Optional)
-     *     }
+     *     id: String (Required)
+     *     name: String (Required)
      * }
      * }
      * 
@@ -66,12 +58,12 @@ public final class PageableAsyncClient { * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. - * @return the response body along with {@link Response} on successful completion of {@link Mono}. + * @return the paginated response with {@link PagedFlux}. */ @Generated - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> linkWithResponse(RequestOptions requestOptions) { - return this.serviceClient.linkWithResponseAsync(requestOptions); + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux link(RequestOptions requestOptions) { + return this.serviceClient.linkAsync(requestOptions); } /** @@ -82,14 +74,25 @@ public Mono> linkWithResponse(RequestOptions requestOptions * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the response body on successful completion of {@link Mono}. + * @return the paginated response with {@link PagedFlux}. */ @Generated - @ServiceMethod(returns = ReturnType.SINGLE) - public Mono link() { - // Generated convenience method for linkWithResponse + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux link() { + // Generated convenience method for link RequestOptions requestOptions = new RequestOptions(); - return linkWithResponse(requestOptions).flatMap(FluxUtil::toMono) - .map(protocolMethodData -> protocolMethodData.toObject(LinkResponse.class)); + PagedFlux pagedFluxResponse = link(requestOptions); + return PagedFlux.create(() -> (continuationTokenParam, pageSizeParam) -> { + Flux> flux = (continuationTokenParam == null) + ? pagedFluxResponse.byPage().take(1) + : pagedFluxResponse.byPage(continuationTokenParam).take(1); + return flux.map(pagedResponse -> new PagedResponseBase(pagedResponse.getRequest(), + pagedResponse.getStatusCode(), pagedResponse.getHeaders(), + pagedResponse.getValue() + .stream() + .map(protocolMethodData -> protocolMethodData.toObject(Pet.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); } } diff --git a/typespec-tests/src/main/java/payload/pageable/PageableClient.java b/typespec-tests/src/main/java/payload/pageable/PageableClient.java index df73ffa91f..19145b72e6 100644 --- a/typespec-tests/src/main/java/payload/pageable/PageableClient.java +++ b/typespec-tests/src/main/java/payload/pageable/PageableClient.java @@ -12,11 +12,11 @@ import com.azure.core.exception.HttpResponseException; import com.azure.core.exception.ResourceModifiedException; import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.PagedIterable; import com.azure.core.http.rest.RequestOptions; -import com.azure.core.http.rest.Response; import com.azure.core.util.BinaryData; import payload.pageable.implementation.ServerDrivenPaginationsImpl; -import payload.pageable.serverdrivenpagination.models.LinkResponse; +import payload.pageable.models.Pet; /** * Initializes a new instance of the synchronous PageableClient type. @@ -43,18 +43,8 @@ public final class PageableClient { *
      * {@code
      * {
-     *     pets (Required): [
-     *          (Required){
-     *             id: String (Required)
-     *             name: String (Required)
-     *         }
-     *     ]
-     *     links (Required): {
-     *         next: String (Optional)
-     *         prev: String (Optional)
-     *         first: String (Optional)
-     *         last: String (Optional)
-     *     }
+     *     id: String (Required)
+     *     name: String (Required)
      * }
      * }
      * 
@@ -64,12 +54,12 @@ public final class PageableClient { * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. - * @return the response body along with {@link Response}. + * @return the paginated response with {@link PagedIterable}. */ @Generated - @ServiceMethod(returns = ReturnType.SINGLE) - public Response linkWithResponse(RequestOptions requestOptions) { - return this.serviceClient.linkWithResponse(requestOptions); + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable link(RequestOptions requestOptions) { + return this.serviceClient.link(requestOptions); } /** @@ -80,13 +70,13 @@ public Response linkWithResponse(RequestOptions requestOptions) { * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. - * @return the response. + * @return the paginated response with {@link PagedIterable}. */ @Generated - @ServiceMethod(returns = ReturnType.SINGLE) - public LinkResponse link() { - // Generated convenience method for linkWithResponse + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable link() { + // Generated convenience method for link RequestOptions requestOptions = new RequestOptions(); - return linkWithResponse(requestOptions).getValue().toObject(LinkResponse.class); + return serviceClient.link(requestOptions).mapPage(bodyItemValue -> bodyItemValue.toObject(Pet.class)); } } diff --git a/typespec-tests/src/main/java/payload/pageable/implementation/ServerDrivenPaginationsImpl.java b/typespec-tests/src/main/java/payload/pageable/implementation/ServerDrivenPaginationsImpl.java index a02e2a572e..c1fee2867d 100644 --- a/typespec-tests/src/main/java/payload/pageable/implementation/ServerDrivenPaginationsImpl.java +++ b/typespec-tests/src/main/java/payload/pageable/implementation/ServerDrivenPaginationsImpl.java @@ -9,6 +9,7 @@ import com.azure.core.annotation.HeaderParam; import com.azure.core.annotation.Host; import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; import com.azure.core.annotation.ReturnType; import com.azure.core.annotation.ServiceInterface; import com.azure.core.annotation.ServiceMethod; @@ -17,12 +18,19 @@ import com.azure.core.exception.HttpResponseException; import com.azure.core.exception.ResourceModifiedException; import com.azure.core.exception.ResourceNotFoundException; +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.http.rest.RequestOptions; import com.azure.core.http.rest.Response; import com.azure.core.http.rest.RestProxy; import com.azure.core.util.BinaryData; import com.azure.core.util.Context; import com.azure.core.util.FluxUtil; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; import reactor.core.publisher.Mono; /** @@ -74,6 +82,26 @@ Mono> link(@HostParam("endpoint") String endpoint, @HeaderP @UnexpectedResponseExceptionType(HttpResponseException.class) Response linkSync(@HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> linkNext(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions, + Context context); + + @Get("{nextLink}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response linkNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions, + Context context); } /** @@ -83,18 +111,8 @@ Response linkSync(@HostParam("endpoint") String endpoint, @HeaderPar *
      * {@code
      * {
-     *     pets (Required): [
-     *          (Required){
-     *             id: String (Required)
-     *             name: String (Required)
-     *         }
-     *     ]
-     *     links (Required): {
-     *         next: String (Optional)
-     *         prev: String (Optional)
-     *         first: String (Optional)
-     *         last: String (Optional)
-     *     }
+     *     id: String (Required)
+     *     name: String (Required)
      * }
      * }
      * 
@@ -104,13 +122,71 @@ Response linkSync(@HostParam("endpoint") String endpoint, @HeaderPar * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. - * @return the response body along with {@link Response} on successful completion of {@link Mono}. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> linkWithResponseAsync(RequestOptions requestOptions) { + private Mono> linkSinglePageAsync(RequestOptions requestOptions) { final String accept = "application/json"; - return FluxUtil - .withContext(context -> service.link(this.client.getEndpoint(), accept, requestOptions, context)); + return FluxUtil.withContext(context -> service.link(this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null)); + } + + /** + * The link operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux linkAsync(RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedFlux<>(() -> linkSinglePageAsync(requestOptions), + nextLink -> linkNextSinglePageAsync(nextLink, requestOptionsForNextPage)); + } + + /** + * The link operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse linkSinglePage(RequestOptions requestOptions) { + final String accept = "application/json"; + Response res = service.linkSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null); } /** @@ -120,32 +196,105 @@ public Mono> linkWithResponseAsync(RequestOptions requestOp *
      * {@code
      * {
-     *     pets (Required): [
-     *          (Required){
-     *             id: String (Required)
-     *             name: String (Required)
-     *         }
-     *     ]
-     *     links (Required): {
-     *         next: String (Optional)
-     *         prev: String (Optional)
-     *         first: String (Optional)
-     *         last: String (Optional)
-     *     }
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable link(RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedIterable<>(() -> linkSinglePage(requestOptions), + nextLink -> linkNextSinglePage(nextLink, requestOptionsForNextPage)); + } + + /** + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
+     * }
+     * }
+     * 
+ * + * @param nextLink The URL to get the next list of items. + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> linkNextSinglePageAsync(String nextLink, RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext( + context -> service.linkNext(nextLink, this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null)); + } + + /** + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     name: String (Required)
      * }
      * }
      * 
* + * @param nextLink The URL to get the next list of items. * @param requestOptions The options to configure the HTTP request before HTTP client sends it. * @throws HttpResponseException thrown if the request is rejected by server. * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. - * @return the response body along with {@link Response}. + * @return the response body along with {@link PagedResponse}. */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response linkWithResponse(RequestOptions requestOptions) { + private PagedResponse linkNextSinglePage(String nextLink, RequestOptions requestOptions) { final String accept = "application/json"; - return service.linkSync(this.client.getEndpoint(), accept, requestOptions, Context.NONE); + Response res + = service.linkNextSync(nextLink, this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "pets"), getNextLink(res.getValue(), "next"), null); + } + + private List getValues(BinaryData binaryData, String path) { + try { + Map obj = binaryData.toObject(Map.class); + List values = (List) obj.get(path); + return values.stream().map(BinaryData::fromObject).collect(Collectors.toList()); + } catch (RuntimeException e) { + return null; + } + } + + private String getNextLink(BinaryData binaryData, String path) { + try { + Map obj = binaryData.toObject(Map.class); + return (String) obj.get(path); + } catch (RuntimeException e) { + return null; + } } } diff --git a/typespec-tests/src/main/java/payload/pageable/serverdrivenpagination/models/LinkResponse.java b/typespec-tests/src/main/java/payload/pageable/serverdrivenpagination/models/LinkResponse.java deleted file mode 100644 index d2311b73ba..0000000000 --- a/typespec-tests/src/main/java/payload/pageable/serverdrivenpagination/models/LinkResponse.java +++ /dev/null @@ -1,107 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) TypeSpec Code Generator. - -package payload.pageable.serverdrivenpagination.models; - -import com.azure.core.annotation.Generated; -import com.azure.core.annotation.Immutable; -import com.azure.json.JsonReader; -import com.azure.json.JsonSerializable; -import com.azure.json.JsonToken; -import com.azure.json.JsonWriter; -import java.io.IOException; -import java.util.List; -import payload.pageable.models.Pet; - -/** - * The LinkResponse model. - */ -@Immutable -public final class LinkResponse implements JsonSerializable { - /* - * The pets property. - */ - @Generated - private final List pets; - - /* - * The links property. - */ - @Generated - private final LinkResponseLinks links; - - /** - * Creates an instance of LinkResponse class. - * - * @param pets the pets value to set. - * @param links the links value to set. - */ - @Generated - private LinkResponse(List pets, LinkResponseLinks links) { - this.pets = pets; - this.links = links; - } - - /** - * Get the pets property: The pets property. - * - * @return the pets value. - */ - @Generated - public List getPets() { - return this.pets; - } - - /** - * Get the links property: The links property. - * - * @return the links value. - */ - @Generated - public LinkResponseLinks getLinks() { - return this.links; - } - - /** - * {@inheritDoc} - */ - @Generated - @Override - public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { - jsonWriter.writeStartObject(); - jsonWriter.writeArrayField("pets", this.pets, (writer, element) -> writer.writeJson(element)); - jsonWriter.writeJsonField("links", this.links); - return jsonWriter.writeEndObject(); - } - - /** - * Reads an instance of LinkResponse from the JsonReader. - * - * @param jsonReader The JsonReader being read. - * @return An instance of LinkResponse 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 LinkResponse. - */ - @Generated - public static LinkResponse fromJson(JsonReader jsonReader) throws IOException { - return jsonReader.readObject(reader -> { - List pets = null; - LinkResponseLinks links = null; - while (reader.nextToken() != JsonToken.END_OBJECT) { - String fieldName = reader.getFieldName(); - reader.nextToken(); - - if ("pets".equals(fieldName)) { - pets = reader.readArray(reader1 -> Pet.fromJson(reader1)); - } else if ("links".equals(fieldName)) { - links = LinkResponseLinks.fromJson(reader); - } else { - reader.skipChildren(); - } - } - return new LinkResponse(pets, links); - }); - } -} diff --git a/typespec-tests/src/main/java/payload/pageable/serverdrivenpagination/models/LinkResponseLinks.java b/typespec-tests/src/main/java/payload/pageable/serverdrivenpagination/models/LinkResponseLinks.java deleted file mode 100644 index e2b4673b81..0000000000 --- a/typespec-tests/src/main/java/payload/pageable/serverdrivenpagination/models/LinkResponseLinks.java +++ /dev/null @@ -1,137 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -// Code generated by Microsoft (R) TypeSpec Code Generator. - -package payload.pageable.serverdrivenpagination.models; - -import com.azure.core.annotation.Generated; -import com.azure.core.annotation.Immutable; -import com.azure.json.JsonReader; -import com.azure.json.JsonSerializable; -import com.azure.json.JsonToken; -import com.azure.json.JsonWriter; -import java.io.IOException; - -/** - * The LinkResponseLinks model. - */ -@Immutable -public final class LinkResponseLinks implements JsonSerializable { - /* - * The next property. - */ - @Generated - private String next; - - /* - * The prev property. - */ - @Generated - private String prev; - - /* - * The first property. - */ - @Generated - private String first; - - /* - * The last property. - */ - @Generated - private String last; - - /** - * Creates an instance of LinkResponseLinks class. - */ - @Generated - private LinkResponseLinks() { - } - - /** - * Get the next property: The next property. - * - * @return the next value. - */ - @Generated - public String getNext() { - return this.next; - } - - /** - * Get the prev property: The prev property. - * - * @return the prev value. - */ - @Generated - public String getPrev() { - return this.prev; - } - - /** - * Get the first property: The first property. - * - * @return the first value. - */ - @Generated - public String getFirst() { - return this.first; - } - - /** - * Get the last property: The last property. - * - * @return the last value. - */ - @Generated - public String getLast() { - return this.last; - } - - /** - * {@inheritDoc} - */ - @Generated - @Override - public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { - jsonWriter.writeStartObject(); - jsonWriter.writeStringField("next", this.next); - jsonWriter.writeStringField("prev", this.prev); - jsonWriter.writeStringField("first", this.first); - jsonWriter.writeStringField("last", this.last); - return jsonWriter.writeEndObject(); - } - - /** - * Reads an instance of LinkResponseLinks from the JsonReader. - * - * @param jsonReader The JsonReader being read. - * @return An instance of LinkResponseLinks 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 LinkResponseLinks. - */ - @Generated - public static LinkResponseLinks fromJson(JsonReader jsonReader) throws IOException { - return jsonReader.readObject(reader -> { - LinkResponseLinks deserializedLinkResponseLinks = new LinkResponseLinks(); - while (reader.nextToken() != JsonToken.END_OBJECT) { - String fieldName = reader.getFieldName(); - reader.nextToken(); - - if ("next".equals(fieldName)) { - deserializedLinkResponseLinks.next = reader.getString(); - } else if ("prev".equals(fieldName)) { - deserializedLinkResponseLinks.prev = reader.getString(); - } else if ("first".equals(fieldName)) { - deserializedLinkResponseLinks.first = reader.getString(); - } else if ("last".equals(fieldName)) { - deserializedLinkResponseLinks.last = reader.getString(); - } else { - reader.skipChildren(); - } - } - - return deserializedLinkResponseLinks; - }); - } -} diff --git a/typespec-tests/src/main/java/tsptest/response/implementation/ResponseClientImpl.java b/typespec-tests/src/main/java/tsptest/response/implementation/ResponseClientImpl.java index bc830682ec..e3f19e6c3f 100644 --- a/typespec-tests/src/main/java/tsptest/response/implementation/ResponseClientImpl.java +++ b/typespec-tests/src/main/java/tsptest/response/implementation/ResponseClientImpl.java @@ -1025,7 +1025,7 @@ public PollerFlux beginLroInvalidResultAsync(BinaryData ? requestOptions.getContext() : Context.NONE) .setServiceVersion(this.getServiceVersion().getVersion()), - "lroResult"), + "lro_result"), TypeReference.createInstance(BinaryData.class), TypeReference.createInstance(BinaryData.class)); } @@ -1063,7 +1063,7 @@ public SyncPoller beginLroInvalidResult(BinaryData reque ? requestOptions.getContext() : Context.NONE) .setServiceVersion(this.getServiceVersion().getVersion()), - "lroResult"), + "lro_result"), TypeReference.createInstance(BinaryData.class), TypeReference.createInstance(BinaryData.class)); } @@ -1102,7 +1102,7 @@ public PollerFlux beginLroInvalidResultWithModelAsy ? requestOptions.getContext() : Context.NONE) .setServiceVersion(this.getServiceVersion().getVersion()), - "lroResult"), + "lro_result"), TypeReference.createInstance(OperationDetails2.class), TypeReference.createInstance(Resource.class)); } @@ -1141,7 +1141,7 @@ public SyncPoller beginLroInvalidResultWithModel(Bi ? requestOptions.getContext() : Context.NONE) .setServiceVersion(this.getServiceVersion().getVersion()), - "lroResult"), + "lro_result"), TypeReference.createInstance(OperationDetails2.class), TypeReference.createInstance(Resource.class)); } @@ -1167,7 +1167,7 @@ private Mono> listStringsSinglePageAsync(RequestOption final String accept = "application/json"; return FluxUtil.withContext(context -> service.listStrings(this.getEndpoint(), accept, requestOptions, context)) .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null)); + getValues(res.getValue(), "items_value"), getNextLink(res.getValue(), "next_link"), null)); } /** @@ -1218,7 +1218,7 @@ private PagedResponse listStringsSinglePage(RequestOptions requestOp final String accept = "application/json"; Response res = service.listStringsSync(this.getEndpoint(), accept, requestOptions, Context.NONE); return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null); + getValues(res.getValue(), "items_value"), getNextLink(res.getValue(), "next_link"), null); } /** @@ -1482,7 +1482,7 @@ private Mono> listStringsNextSinglePageAsync(String ne .withContext( context -> service.listStringsNext(nextLink, this.getEndpoint(), accept, requestOptions, context)) .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null)); + getValues(res.getValue(), "items_value"), getNextLink(res.getValue(), "next_link"), null)); } /** @@ -1509,7 +1509,7 @@ private PagedResponse listStringsNextSinglePage(String nextLink, Req Response res = service.listStringsNextSync(nextLink, this.getEndpoint(), accept, requestOptions, Context.NONE); return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), - getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null); + getValues(res.getValue(), "items_value"), getNextLink(res.getValue(), "next_link"), null); } private List getValues(BinaryData binaryData, String path) { diff --git a/typespec-tests/src/main/java/tsptest/response/models/OperationDetails2.java b/typespec-tests/src/main/java/tsptest/response/models/OperationDetails2.java index 5a8ad36677..c5707130ba 100644 --- a/typespec-tests/src/main/java/tsptest/response/models/OperationDetails2.java +++ b/typespec-tests/src/main/java/tsptest/response/models/OperationDetails2.java @@ -37,10 +37,10 @@ public final class OperationDetails2 implements JsonSerializable constructor = OperationTemplatesManager.class + .getDeclaredConstructor(HttpPipeline.class, AzureProfile.class, Duration.class); + setAccessible(constructor); + return constructor.newInstance(ArmUtils.createTestHttpPipeline(), ArmUtils.getAzureProfile(), + Duration.ofMillis(1)); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + private static void setAccessible(final AccessibleObject accessibleObject) { + // avoid bug in Java8 + Runnable runnable = () -> accessibleObject.setAccessible(true); + runnable.run(); + } +} diff --git a/typespec-tests/src/test/java/client/clientnamespace/NamespaceTests.java b/typespec-tests/src/test/java/client/clientnamespace/NamespaceTests.java new file mode 100644 index 0000000000..af0be67cd1 --- /dev/null +++ b/typespec-tests/src/test/java/client/clientnamespace/NamespaceTests.java @@ -0,0 +1,31 @@ +package client.clientnamespace; + +import client.clientnamespace.first.models.FirstClientResult; +import client.clientnamespace.second.ClientNamespaceSecondClient; +import client.clientnamespace.second.ClientNamespaceSecondClientBuilder; +import client.clientnamespace.second.models.SecondClientResult; +import client.clientnamespace.second.sub.models.SecondClientEnumType; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class NamespaceTests { + + @Test + public void test() { + FirstClientResult firstClientResult = new ClientNamespaceFirstClientBuilder().buildClient().getFirst(); + + SecondClientResult secondClientResult = new ClientNamespaceSecondClientBuilder().buildClient().getSecond(); + + // assert Java package name is expected + Assertions.assertEquals("client.clientnamespace.ClientNamespaceFirstClient", + ClientNamespaceFirstClient.class.getName()); + Assertions.assertEquals("client.clientnamespace.second.ClientNamespaceSecondClient", + ClientNamespaceSecondClient.class.getName()); + Assertions.assertEquals("client.clientnamespace.first.models.FirstClientResult", + FirstClientResult.class.getName()); + Assertions.assertEquals("client.clientnamespace.second.models.SecondClientResult", + SecondClientResult.class.getName()); + Assertions.assertEquals("client.clientnamespace.second.sub.models.SecondClientEnumType", + SecondClientEnumType.class.getName()); + } +} diff --git a/typespec-tests/src/test/java/client/clientnamespace/generated/ClientNamespaceSecondClientTestBase.java b/typespec-tests/src/test/java/client/clientnamespace/generated/ClientNamespaceSecondClientTestBase.java new file mode 100644 index 0000000000..c1ff3693a7 --- /dev/null +++ b/typespec-tests/src/test/java/client/clientnamespace/generated/ClientNamespaceSecondClientTestBase.java @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package client.clientnamespace.generated; + +// The Java test files under 'generated' package are generated for your reference. +// If you wish to modify these files, please copy them out of the 'generated' package, and modify there. +// See https://aka.ms/azsdk/dpg/java/tests for guide on adding a test. + +import client.clientnamespace.ClientNamespaceFirstClient; +import client.clientnamespace.ClientNamespaceFirstClientBuilder; +import client.clientnamespace.second.ClientNamespaceSecondClient; +import client.clientnamespace.second.ClientNamespaceSecondClientBuilder; +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.test.TestMode; +import com.azure.core.test.TestProxyTestBase; +import com.azure.core.util.Configuration; + +class ClientNamespaceSecondClientTestBase extends TestProxyTestBase { + protected ClientNamespaceSecondClient clientNamespaceSecondClient; + + protected ClientNamespaceFirstClient clientNamespaceFirstClient; + + @Override + protected void beforeTest() { + ClientNamespaceSecondClientBuilder clientNamespaceSecondClientbuilder = new ClientNamespaceSecondClientBuilder() + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "http://localhost:3000")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.RECORD) { + clientNamespaceSecondClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + clientNamespaceSecondClient = clientNamespaceSecondClientbuilder.buildClient(); + + ClientNamespaceFirstClientBuilder clientNamespaceFirstClientbuilder = new ClientNamespaceFirstClientBuilder() + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "http://localhost:3000")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.RECORD) { + clientNamespaceFirstClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + clientNamespaceFirstClient = clientNamespaceFirstClientbuilder.buildClient(); + + } +} diff --git a/typespec-tests/tsp/lro.tsp b/typespec-tests/tsp/lro.tsp index 0f25690a40..41bb4f5597 100644 --- a/typespec-tests/tsp/lro.tsp +++ b/typespec-tests/tsp/lro.tsp @@ -1,10 +1,12 @@ import "@azure-tools/typespec-azure-core"; +import "@azure-tools/typespec-client-generator-core"; using TypeSpec.Rest; using TypeSpec.Http; using TypeSpec.Versioning; using Azure.Core; using Azure.Core.Traits; +using Azure.ClientGenerator.Core; @service({ title: "LongRunning", diff --git a/typespec-tests/tsp/response.tsp b/typespec-tests/tsp/response.tsp index 4a1e50427f..39615bb5e9 100644 --- a/typespec-tests/tsp/response.tsp +++ b/typespec-tests/tsp/response.tsp @@ -78,16 +78,22 @@ model OperationDetails2 { error?: Azure.Core.Foundations.Error; @lroResult + @clientName("longRunningResult", "java") + @encodedName("application/json", "lro_result") lroResult?: Resource; } @pagedResult model StringsList { @items + @clientName("items", "java") + @encodedName("application/json", "items_value") value: string[]; @nextLink - nextLink?: string; + @clientName("nextLink", "java") + @encodedName("application/json", "next_link") + next?: string; } @pagedResult