diff --git a/eng/versioning/version_client.txt b/eng/versioning/version_client.txt index b04d701dd93c..841e61d8b3bd 100644 --- a/eng/versioning/version_client.txt +++ b/eng/versioning/version_client.txt @@ -256,6 +256,7 @@ com.azure.spring:spring-cloud-azure-stream-binder-servicebus-core;5.22.0;5.23.0- com.azure.spring:spring-cloud-azure-stream-binder-servicebus;5.22.0;5.23.0-beta.1 com.azure.spring:spring-cloud-azure-testcontainers;5.22.0;5.23.0-beta.1 com.azure:azure-spring-data-cosmos;5.22.0;5.23.0-beta.1 +com.azure:azure-contoso-widgetmanager;1.0.0-beta.1;1.0.0-beta.1 com.azure.resourcemanager:azure-resourcemanager;2.50.0;2.51.0-beta.1 com.azure.resourcemanager:azure-resourcemanager-appplatform;2.50.0;2.51.0-beta.1 com.azure.resourcemanager:azure-resourcemanager-appservice;2.50.0;2.51.0-beta.1 diff --git a/pom.xml b/pom.xml index 59226c65adf6..d8b92ebe78dc 100644 --- a/pom.xml +++ b/pom.xml @@ -56,6 +56,7 @@ sdk/containerregistry sdk/containerservicefleet sdk/contentsafety + sdk/contosowidgetmanager sdk/core sdk/core-v2 sdk/cosmos diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/CHANGELOG.md b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/CHANGELOG.md new file mode 100644 index 000000000000..9e6ba8507db7 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/CHANGELOG.md @@ -0,0 +1,16 @@ +# Release History + +## 1.0.0-beta.1 (Unreleased) + +- Azure WidgetManager client library for Java. This package contains Microsoft Azure WidgetManager client library. + +### Features Added + +### Breaking Changes + +### Bugs Fixed + +### Other Changes +### Features Added + +- Initial release for the azure-contoso-widgetmanager Java SDK. diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/README.md b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/README.md new file mode 100644 index 000000000000..3cdbd1ce8230 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/README.md @@ -0,0 +1,78 @@ +# Azure WidgetManager client library for Java + +Azure WidgetManager client library for Java. + +This package contains Microsoft Azure WidgetManager client library. + +## Documentation + +Various documentation is available to help you get started + +- [API reference documentation][docs] +- [Product documentation][product_documentation] + +## Getting started + +### Prerequisites + +- [Java Development Kit (JDK)][jdk] with version 8 or above +- [Azure Subscription][azure_subscription] + +### Adding the package to your product + +[//]: # ({x-version-update-start;com.azure:azure-contoso-widgetmanager;current}) +```xml + + com.azure + azure-contoso-widgetmanager + 1.0.0-beta.1 + +``` +[//]: # ({x-version-update-end}) + +### Authentication + +[Azure Identity][azure_identity] package provides the default implementation for authenticating the client. + +## Key concepts + +## Examples + +```java com.azure.contoso.widgetmanager.readme +``` + +### Service API versions + +The client library targets the latest service API version by default. +The service client builder accepts an optional service API version parameter to specify which API version to communicate. + +#### Select a service API version + +You have the flexibility to explicitly select a supported service API version when initializing a service client via the service client builder. +This ensures that the client can communicate with services using the specified API version. + +When selecting an API version, it is important to verify that there are no breaking changes compared to the latest API version. +If there are significant differences, API calls may fail due to incompatibility. + +Always ensure that the chosen API version is fully supported and operational for your specific use case and that it aligns with the service's versioning policy. + +## Troubleshooting + +## Next steps + +## Contributing + +For details on contributing to this repository, see the [contributing guide](https://github.com/Azure/azure-sdk-for-java/blob/main/CONTRIBUTING.md). + +1. Fork it +1. Create your feature branch (`git checkout -b my-new-feature`) +1. Commit your changes (`git commit -am 'Add some feature'`) +1. Push to the branch (`git push origin my-new-feature`) +1. Create new Pull Request + + +[product_documentation]: https://azure.microsoft.com/services/ +[docs]: https://azure.github.io/azure-sdk-for-java/ +[jdk]: https://learn.microsoft.com/azure/developer/java/fundamentals/ +[azure_subscription]: https://azure.microsoft.com/free/ +[azure_identity]: https://github.com/Azure/azure-sdk-for-java/blob/main/sdk/identity/azure-identity diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/assets.json b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/assets.json new file mode 100644 index 000000000000..1212b5827a4c --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/assets.json @@ -0,0 +1 @@ +{"AssetsRepo":"Azure/azure-sdk-assets","AssetsRepoPrefixPath":"java","TagPrefix":"java/contosowidgetmanager/azure-contoso-widgetmanager","Tag":""} \ No newline at end of file diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/pom.xml b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/pom.xml new file mode 100644 index 000000000000..212bea32f734 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + com.azure + azure-client-sdk-parent + 1.7.0 + ../../parents/azure-client-sdk-parent + + + com.azure + azure-contoso-widgetmanager + 1.0.0-beta.1 + jar + + Microsoft Azure SDK for WidgetManager + This package contains Microsoft Azure WidgetManager client library. + https://github.com/Azure/azure-sdk-for-java + + + + The MIT License (MIT) + http://opensource.org/licenses/MIT + repo + + + + + https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + + microsoft + Microsoft + + + + UTF-8 + + + + com.azure + azure-core + 1.55.3 + + + com.azure + azure-core-http-netty + 1.15.11 + + + com.azure + azure-core-test + 1.27.0-beta.8 + test + + + com.azure + azure-identity + 1.15.4 + test + + + diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/WidgetManagerAsyncClient.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/WidgetManagerAsyncClient.java new file mode 100644 index 000000000000..1ac78e7fda28 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/WidgetManagerAsyncClient.java @@ -0,0 +1,368 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager; + +import com.azure.contoso.widgetmanager.implementation.JsonMergePatchHelper; +import com.azure.contoso.widgetmanager.implementation.WidgetsImpl; +import com.azure.contoso.widgetmanager.models.ResourceOperationStatusWidgetSuiteWidgetSuiteError; +import com.azure.contoso.widgetmanager.models.WidgetSuite; +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.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 com.azure.core.util.polling.PollOperationDetails; +import com.azure.core.util.polling.PollerFlux; +import java.util.stream.Collectors; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * Initializes a new instance of the asynchronous WidgetManagerClient type. + */ +@ServiceClient(builder = WidgetManagerClientBuilder.class, isAsync = true) +public final class WidgetManagerAsyncClient { + @Generated + private final WidgetsImpl serviceClient; + + /** + * Initializes an instance of WidgetManagerAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + WidgetManagerAsyncClient(WidgetsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Fetch a Widget by name. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @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 a widget along with {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getWidgetWithResponse(String widgetName, RequestOptions requestOptions) { + return this.serviceClient.getWidgetWithResponseAsync(widgetName, requestOptions); + } + + /** + * Gets status of a Widget operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     *     result (Optional): {
+     *         name: String (Required)
+     *         manufacturerId: String (Optional, Required on create)
+     *         sharedModel (Optional): {
+     *             tag: String (Optional, Required on create)
+     *             createdAt: OffsetDateTime (Optional, Required on create)
+     *         }
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @param operationId The unique ID of the operation. + * @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 status of a Widget operation along with {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getWidgetOperationStatusWithResponse(String widgetName, String operationId, + RequestOptions requestOptions) { + return this.serviceClient.getWidgetOperationStatusWithResponseAsync(widgetName, operationId, requestOptions); + } + + /** + * Creates or updates a Widget asynchronously. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @param resource The resource instance. + * @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 {@link PollerFlux} for polling of a widget. + */ + @Generated + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux beginCreateOrUpdateWidget(String widgetName, BinaryData resource, + RequestOptions requestOptions) { + return this.serviceClient.beginCreateOrUpdateWidgetAsync(widgetName, resource, requestOptions); + } + + /** + * Delete a Widget asynchronously. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @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 {@link PollerFlux} for polling of provides status details for long running operations. + */ + @Generated + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux beginDeleteWidget(String widgetName, RequestOptions requestOptions) { + return this.serviceClient.beginDeleteWidgetAsync(widgetName, requestOptions); + } + + /** + * List Widget resources. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @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 paged collection of WidgetSuite items as paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWidgets(RequestOptions requestOptions) { + return this.serviceClient.listWidgetsAsync(requestOptions); + } + + /** + * Fetch a Widget by name. + * + * @param widgetName The widget name. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a widget on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getWidget(String widgetName) { + // Generated convenience method for getWidgetWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getWidgetWithResponse(widgetName, requestOptions).flatMap(FluxUtil::toMono) + .map(protocolMethodData -> protocolMethodData.toObject(WidgetSuite.class)); + } + + /** + * Gets status of a Widget operation. + * + * @param widgetName The widget name. + * @param operationId The unique ID of the operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return status of a Widget operation on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono getWidgetOperationStatus(String widgetName, + String operationId) { + // Generated convenience method for getWidgetOperationStatusWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getWidgetOperationStatusWithResponse(widgetName, operationId, requestOptions).flatMap(FluxUtil::toMono) + .map(protocolMethodData -> protocolMethodData + .toObject(ResourceOperationStatusWidgetSuiteWidgetSuiteError.class)); + } + + /** + * Creates or updates a Widget asynchronously. + * + * @param widgetName The widget name. + * @param resource The resource instance. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of a widget. + */ + @Generated + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux beginCreateOrUpdateWidget(String widgetName, + WidgetSuite resource) { + // Generated convenience method for beginCreateOrUpdateWidgetWithModel + RequestOptions requestOptions = new RequestOptions(); + JsonMergePatchHelper.getWidgetSuiteAccessor().prepareModelForJsonMergePatch(resource, true); + BinaryData resourceInBinaryData = BinaryData.fromObject(resource); + // BinaryData.fromObject() will not fire serialization, use getLength() to fire serialization. + resourceInBinaryData.getLength(); + JsonMergePatchHelper.getWidgetSuiteAccessor().prepareModelForJsonMergePatch(resource, false); + return serviceClient.beginCreateOrUpdateWidgetWithModelAsync(widgetName, resourceInBinaryData, requestOptions); + } + + /** + * Delete a Widget asynchronously. + * + * @param widgetName The widget name. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of provides status details for long running operations. + */ + @Generated + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux beginDeleteWidget(String widgetName) { + // Generated convenience method for beginDeleteWidgetWithModel + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.beginDeleteWidgetWithModelAsync(widgetName, requestOptions); + } + + /** + * List Widget resources. + * + * @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 paged collection of WidgetSuite items as paginated response with {@link PagedFlux}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWidgets() { + // Generated convenience method for listWidgets + RequestOptions requestOptions = new RequestOptions(); + PagedFlux pagedFluxResponse = listWidgets(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(WidgetSuite.class)) + .collect(Collectors.toList()), + pagedResponse.getContinuationToken(), null)); + }); + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/WidgetManagerClient.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/WidgetManagerClient.java new file mode 100644 index 000000000000..0b1352da3acd --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/WidgetManagerClient.java @@ -0,0 +1,349 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager; + +import com.azure.contoso.widgetmanager.implementation.JsonMergePatchHelper; +import com.azure.contoso.widgetmanager.implementation.WidgetsImpl; +import com.azure.contoso.widgetmanager.models.ResourceOperationStatusWidgetSuiteWidgetSuiteError; +import com.azure.contoso.widgetmanager.models.WidgetSuite; +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.PagedIterable; +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.polling.PollOperationDetails; +import com.azure.core.util.polling.SyncPoller; + +/** + * Initializes a new instance of the synchronous WidgetManagerClient type. + */ +@ServiceClient(builder = WidgetManagerClientBuilder.class) +public final class WidgetManagerClient { + @Generated + private final WidgetsImpl serviceClient; + + /** + * Initializes an instance of WidgetManagerClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + WidgetManagerClient(WidgetsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * Fetch a Widget by name. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @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 a widget along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getWidgetWithResponse(String widgetName, RequestOptions requestOptions) { + return this.serviceClient.getWidgetWithResponse(widgetName, requestOptions); + } + + /** + * Gets status of a Widget operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     *     result (Optional): {
+     *         name: String (Required)
+     *         manufacturerId: String (Optional, Required on create)
+     *         sharedModel (Optional): {
+     *             tag: String (Optional, Required on create)
+     *             createdAt: OffsetDateTime (Optional, Required on create)
+     *         }
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @param operationId The unique ID of the operation. + * @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 status of a Widget operation along with {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getWidgetOperationStatusWithResponse(String widgetName, String operationId, + RequestOptions requestOptions) { + return this.serviceClient.getWidgetOperationStatusWithResponse(widgetName, operationId, requestOptions); + } + + /** + * Creates or updates a Widget asynchronously. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @param resource The resource instance. + * @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 {@link SyncPoller} for polling of a widget. + */ + @Generated + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller beginCreateOrUpdateWidget(String widgetName, BinaryData resource, + RequestOptions requestOptions) { + return this.serviceClient.beginCreateOrUpdateWidget(widgetName, resource, requestOptions); + } + + /** + * Delete a Widget asynchronously. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @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 {@link SyncPoller} for polling of provides status details for long running operations. + */ + @Generated + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller beginDeleteWidget(String widgetName, RequestOptions requestOptions) { + return this.serviceClient.beginDeleteWidget(widgetName, requestOptions); + } + + /** + * List Widget resources. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @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 paged collection of WidgetSuite items as paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWidgets(RequestOptions requestOptions) { + return this.serviceClient.listWidgets(requestOptions); + } + + /** + * Fetch a Widget by name. + * + * @param widgetName The widget name. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return a widget. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public WidgetSuite getWidget(String widgetName) { + // Generated convenience method for getWidgetWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getWidgetWithResponse(widgetName, requestOptions).getValue().toObject(WidgetSuite.class); + } + + /** + * Gets status of a Widget operation. + * + * @param widgetName The widget name. + * @param operationId The unique ID of the operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return status of a Widget operation. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public ResourceOperationStatusWidgetSuiteWidgetSuiteError getWidgetOperationStatus(String widgetName, + String operationId) { + // Generated convenience method for getWidgetOperationStatusWithResponse + RequestOptions requestOptions = new RequestOptions(); + return getWidgetOperationStatusWithResponse(widgetName, operationId, requestOptions).getValue() + .toObject(ResourceOperationStatusWidgetSuiteWidgetSuiteError.class); + } + + /** + * Creates or updates a Widget asynchronously. + * + * @param widgetName The widget name. + * @param resource The resource instance. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of a widget. + */ + @Generated + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller beginCreateOrUpdateWidget(String widgetName, + WidgetSuite resource) { + // Generated convenience method for beginCreateOrUpdateWidgetWithModel + RequestOptions requestOptions = new RequestOptions(); + JsonMergePatchHelper.getWidgetSuiteAccessor().prepareModelForJsonMergePatch(resource, true); + BinaryData resourceInBinaryData = BinaryData.fromObject(resource); + // BinaryData.fromObject() will not fire serialization, use getLength() to fire serialization. + resourceInBinaryData.getLength(); + JsonMergePatchHelper.getWidgetSuiteAccessor().prepareModelForJsonMergePatch(resource, false); + return serviceClient.beginCreateOrUpdateWidgetWithModel(widgetName, resourceInBinaryData, requestOptions); + } + + /** + * Delete a Widget asynchronously. + * + * @param widgetName The widget name. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of provides status details for long running operations. + */ + @Generated + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller beginDeleteWidget(String widgetName) { + // Generated convenience method for beginDeleteWidgetWithModel + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.beginDeleteWidgetWithModel(widgetName, requestOptions); + } + + /** + * List Widget resources. + * + * @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 paged collection of WidgetSuite items as paginated response with {@link PagedIterable}. + */ + @Generated + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWidgets() { + // Generated convenience method for listWidgets + RequestOptions requestOptions = new RequestOptions(); + return serviceClient.listWidgets(requestOptions) + .mapPage(bodyItemValue -> bodyItemValue.toObject(WidgetSuite.class)); + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/WidgetManagerClientBuilder.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/WidgetManagerClientBuilder.java new file mode 100644 index 000000000000..5dd19e183a0a --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/WidgetManagerClientBuilder.java @@ -0,0 +1,334 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager; + +import com.azure.contoso.widgetmanager.implementation.WidgetManagerClientImpl; +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.client.traits.TokenCredentialTrait; +import com.azure.core.credential.TokenCredential; +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.BearerTokenAuthenticationPolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.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 WidgetManagerClient type. + */ +@ServiceClientBuilder(serviceClients = { WidgetManagerClient.class, WidgetManagerAsyncClient.class }) +public final class WidgetManagerClientBuilder + implements HttpTrait, ConfigurationTrait, + TokenCredentialTrait, EndpointTrait { + @Generated + private static final String SDK_NAME = "name"; + + @Generated + private static final String SDK_VERSION = "version"; + + @Generated + private static final String[] DEFAULT_SCOPES = new String[] { "https://contoso.azure.com/.default" }; + + @Generated + private static final Map PROPERTIES + = CoreUtils.getProperties("azure-contoso-widgetmanager.properties"); + + @Generated + private final List pipelinePolicies; + + /** + * Create an instance of the WidgetManagerClientBuilder. + */ + @Generated + public WidgetManagerClientBuilder() { + this.pipelinePolicies = new ArrayList<>(); + } + + /* + * The HTTP pipeline to send requests through. + */ + @Generated + private HttpPipeline pipeline; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public WidgetManagerClientBuilder 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 WidgetManagerClientBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /* + * The logging configuration for HTTP requests and responses. + */ + @Generated + private HttpLogOptions httpLogOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public WidgetManagerClientBuilder 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 WidgetManagerClientBuilder 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 WidgetManagerClientBuilder retryOptions(RetryOptions retryOptions) { + this.retryOptions = retryOptions; + return this; + } + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public WidgetManagerClientBuilder 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 WidgetManagerClientBuilder configuration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + /* + * The TokenCredential used for authentication. + */ + @Generated + private TokenCredential tokenCredential; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public WidgetManagerClientBuilder credential(TokenCredential tokenCredential) { + this.tokenCredential = tokenCredential; + return this; + } + + /* + * The service endpoint + */ + @Generated + private String endpoint; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public WidgetManagerClientBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * Service version + */ + @Generated + private WidgetManagerServiceVersion serviceVersion; + + /** + * Sets Service version. + * + * @param serviceVersion the serviceVersion value. + * @return the WidgetManagerClientBuilder. + */ + @Generated + public WidgetManagerClientBuilder serviceVersion(WidgetManagerServiceVersion serviceVersion) { + this.serviceVersion = serviceVersion; + 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 WidgetManagerClientBuilder. + */ + @Generated + public WidgetManagerClientBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + + /** + * Builds an instance of WidgetManagerClientImpl with the provided parameters. + * + * @return an instance of WidgetManagerClientImpl. + */ + @Generated + private WidgetManagerClientImpl buildInnerClient() { + this.validateClient(); + HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); + WidgetManagerServiceVersion localServiceVersion + = (serviceVersion != null) ? serviceVersion : WidgetManagerServiceVersion.getLatest(); + WidgetManagerClientImpl client = new WidgetManagerClientImpl(localPipeline, + JacksonAdapter.createDefaultSerializerAdapter(), this.endpoint, localServiceVersion); + return client; + } + + @Generated + private void validateClient() { + // This method is invoked from 'buildInnerClient'/'buildClient' method. + // Developer can customize this method, to validate that the necessary conditions are met for the new client. + Objects.requireNonNull(endpoint, "'endpoint' cannot be null."); + } + + @Generated + private HttpPipeline createHttpPipeline() { + Configuration buildConfiguration + = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; + HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions; + ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions; + List policies = new ArrayList<>(); + String clientName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName"); + String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); + String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions); + policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + policies.add(new RequestIdPolicy()); + policies.add(new AddHeadersFromContextPolicy()); + HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(localClientOptions); + if (headers != null) { + policies.add(new AddHeadersPolicy(headers)); + } + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); + policies.add(new AddDatePolicy()); + if (tokenCredential != null) { + policies.add(new BearerTokenAuthenticationPolicy(tokenCredential, DEFAULT_SCOPES)); + } + 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 WidgetManagerAsyncClient class. + * + * @return an instance of WidgetManagerAsyncClient. + */ + @Generated + public WidgetManagerAsyncClient buildAsyncClient() { + return new WidgetManagerAsyncClient(buildInnerClient().getWidgets()); + } + + /** + * Builds an instance of WidgetManagerClient class. + * + * @return an instance of WidgetManagerClient. + */ + @Generated + public WidgetManagerClient buildClient() { + return new WidgetManagerClient(buildInnerClient().getWidgets()); + } + + private static final ClientLogger LOGGER = new ClientLogger(WidgetManagerClientBuilder.class); +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/WidgetManagerServiceVersion.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/WidgetManagerServiceVersion.java new file mode 100644 index 000000000000..64cde42aedc1 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/WidgetManagerServiceVersion.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 com.azure.contoso.widgetmanager; + +import com.azure.core.util.ServiceVersion; + +/** + * Service version of WidgetManagerClient. + */ +public enum WidgetManagerServiceVersion implements ServiceVersion { + /** + * Enum value 2022-11-01-preview. + */ + V2022_11_01_PREVIEW("2022-11-01-preview"), + + /** + * Enum value 2022-12-01. + */ + V2022_12_01("2022-12-01"); + + private final String version; + + WidgetManagerServiceVersion(String version) { + this.version = version; + } + + /** + * {@inheritDoc} + */ + @Override + public String getVersion() { + return this.version; + } + + /** + * Gets the latest service version supported by this client library. + * + * @return The latest {@link WidgetManagerServiceVersion}. + */ + public static WidgetManagerServiceVersion getLatest() { + return V2022_12_01; + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/JsonMergePatchHelper.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/JsonMergePatchHelper.java new file mode 100644 index 000000000000..5e98b27061b3 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/JsonMergePatchHelper.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 com.azure.contoso.widgetmanager.implementation; + +import com.azure.contoso.widgetmanager.models.FakedSharedModel; +import com.azure.contoso.widgetmanager.models.WidgetSuite; + +/** + * This is the Helper class to enable json merge patch serialization for a model. + */ +public class JsonMergePatchHelper { + private static WidgetSuiteAccessor widgetSuiteAccessor; + + public interface WidgetSuiteAccessor { + WidgetSuite prepareModelForJsonMergePatch(WidgetSuite widgetSuite, boolean jsonMergePatchEnabled); + + boolean isJsonMergePatch(WidgetSuite widgetSuite); + } + + public static void setWidgetSuiteAccessor(WidgetSuiteAccessor accessor) { + widgetSuiteAccessor = accessor; + } + + public static WidgetSuiteAccessor getWidgetSuiteAccessor() { + return widgetSuiteAccessor; + } + + private static FakedSharedModelAccessor fakedSharedModelAccessor; + + public interface FakedSharedModelAccessor { + FakedSharedModel prepareModelForJsonMergePatch(FakedSharedModel fakedSharedModel, + boolean jsonMergePatchEnabled); + + boolean isJsonMergePatch(FakedSharedModel fakedSharedModel); + } + + public static void setFakedSharedModelAccessor(FakedSharedModelAccessor accessor) { + fakedSharedModelAccessor = accessor; + } + + public static FakedSharedModelAccessor getFakedSharedModelAccessor() { + return fakedSharedModelAccessor; + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/OperationLocationPollingStrategy.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/OperationLocationPollingStrategy.java new file mode 100644 index 000000000000..0ec54366b74d --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/OperationLocationPollingStrategy.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 com.azure.contoso.widgetmanager.implementation; + +import com.azure.core.exception.AzureException; +import com.azure.core.http.HttpHeader; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.polling.LongRunningOperationStatus; +import com.azure.core.util.polling.OperationResourcePollingStrategy; +import com.azure.core.util.polling.PollResponse; +import com.azure.core.util.polling.PollingContext; +import com.azure.core.util.polling.PollingStrategyOptions; +import com.azure.core.util.serializer.JsonSerializerProviders; +import com.azure.core.util.serializer.ObjectSerializer; +import com.azure.core.util.serializer.TypeReference; +import java.time.Duration; +import java.time.OffsetDateTime; +import reactor.core.publisher.Mono; + +// DO NOT modify this helper class + +/** + * Implements an operation location polling strategy, from Operation-Location. + * + * @param the type of the response type from a polling call, or BinaryData if raw response body should be kept + * @param the type of the final result object to deserialize into, or BinaryData if raw response body should be + * kept + */ +public final class OperationLocationPollingStrategy extends OperationResourcePollingStrategy { + + private static final ClientLogger LOGGER = new ClientLogger(OperationLocationPollingStrategy.class); + + private final ObjectSerializer serializer; + private final String endpoint; + private final String propertyName; + + /** + * Creates an instance of the operation resource polling strategy. + * + * @param pollingStrategyOptions options to configure this polling strategy. + * @throws NullPointerException if {@code pollingStrategyOptions} is null. + */ + public OperationLocationPollingStrategy(PollingStrategyOptions pollingStrategyOptions) { + this(pollingStrategyOptions, null); + } + + /** + * Creates an instance of the operation resource polling strategy. + * + * @param pollingStrategyOptions options to configure this polling strategy. + * @param propertyName the name of the property to extract final result. + * @throws NullPointerException if {@code pollingStrategyOptions} is null. + */ + public OperationLocationPollingStrategy(PollingStrategyOptions pollingStrategyOptions, String propertyName) { + super(PollingUtils.OPERATION_LOCATION_HEADER, pollingStrategyOptions); + this.propertyName = propertyName; + this.endpoint = pollingStrategyOptions.getEndpoint(); + this.serializer = pollingStrategyOptions.getSerializer() != null + ? pollingStrategyOptions.getSerializer() + : JsonSerializerProviders.createInstance(true); + } + + /** + * {@inheritDoc} + */ + @Override + public Mono> onInitialResponse(Response response, PollingContext pollingContext, + TypeReference pollResponseType) { + // Response is Response + + HttpHeader operationLocationHeader = response.getHeaders().get(PollingUtils.OPERATION_LOCATION_HEADER); + if (operationLocationHeader != null) { + pollingContext.setData(PollingUtils.OPERATION_LOCATION_HEADER.getCaseSensitiveName(), + PollingUtils.getAbsolutePath(operationLocationHeader.getValue(), endpoint, LOGGER)); + } + final String httpMethod = response.getRequest().getHttpMethod().name(); + pollingContext.setData(PollingUtils.HTTP_METHOD, httpMethod); + pollingContext.setData(PollingUtils.REQUEST_URL, response.getRequest().getUrl().toString()); + + if (response.getStatusCode() == 200 + || response.getStatusCode() == 201 + || response.getStatusCode() == 202 + || response.getStatusCode() == 204) { + final Duration retryAfter + = PollingUtils.getRetryAfterFromHeaders(response.getHeaders(), OffsetDateTime::now); + final Mono> pollResponseMono + = PollingUtils.deserializeResponse((BinaryData) response.getValue(), serializer, pollResponseType) + .onErrorResume(exception -> { + LOGGER.info("Failed to parse initial response."); + return Mono.empty(); + }) + .map(value -> new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS, value, retryAfter)); + return pollResponseMono.switchIfEmpty( + Mono.fromSupplier(() -> new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS, null, retryAfter))); + } else { + return Mono + .error( + new AzureException(String.format( + "Operation failed or cancelled with status code %d," + + ", '%s' header: %s, and response body: %s", + response.getStatusCode(), PollingUtils.OPERATION_LOCATION_HEADER, operationLocationHeader, + response.getValue()))); + } + } + + /** + * {@inheritDoc} + */ + @Override + public Mono getResult(PollingContext pollingContext, TypeReference resultType) { + if (pollingContext.getLatestResponse().getStatus() == LongRunningOperationStatus.FAILED) { + return Mono.error(new AzureException("Long running operation failed.")); + } else if (pollingContext.getLatestResponse().getStatus() == LongRunningOperationStatus.USER_CANCELLED) { + return Mono.error(new AzureException("Long running operation cancelled.")); + } + if (propertyName != null) { + // take the last poll response body from PollingContext, + // and de-serialize the property as final result + BinaryData latestResponseBody + = BinaryData.fromString(pollingContext.getData(PollingUtils.POLL_RESPONSE_BODY)); + return PollingUtils + .deserializeResponse(latestResponseBody, serializer, PollingUtils.POST_POLL_RESULT_TYPE_REFERENCE) + .flatMap(value -> { + if (value.get(propertyName) != null) { + return BinaryData.fromObjectAsync(value.get(propertyName)) + .flatMap(result -> PollingUtils.deserializeResponse(result, serializer, resultType)); + } else { + return Mono.error(new AzureException("Cannot get final result")); + } + }) + .switchIfEmpty(Mono.error(new AzureException("Cannot get final result"))); + } else { + return super.getResult(pollingContext, resultType); + } + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/PollingUtils.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/PollingUtils.java new file mode 100644 index 000000000000..ba4fd2f07a79 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/PollingUtils.java @@ -0,0 +1,151 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.implementation; + +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.HttpHeaders; +import com.azure.core.util.BinaryData; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.DateTimeRfc1123; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.serializer.ObjectSerializer; +import com.azure.core.util.serializer.TypeReference; +import java.net.URI; +import java.net.URISyntaxException; +import java.time.DateTimeException; +import java.time.Duration; +import java.time.OffsetDateTime; +import java.time.temporal.ChronoUnit; +import java.util.Map; +import java.util.function.Function; +import java.util.function.Supplier; +import reactor.core.publisher.Mono; + +// DO NOT modify this helper class + +final class PollingUtils { + + public static final TypeReference> POST_POLL_RESULT_TYPE_REFERENCE + = new TypeReference>() { + }; + + public static final HttpHeaderName OPERATION_LOCATION_HEADER = HttpHeaderName.fromString("Operation-Location"); + + public static final String HTTP_METHOD = "httpMethod"; + public static final String REQUEST_URL = "requestURL"; + public static final String POLL_RESPONSE_BODY = "pollResponseBody"; + + private static final String FORWARD_SLASH = "/"; + + public static String getAbsolutePath(String path, String endpoint, ClientLogger logger) { + try { + URI uri = new URI(path); + if (!uri.isAbsolute()) { + if (CoreUtils.isNullOrEmpty(endpoint)) { + throw logger.logExceptionAsError(new IllegalArgumentException( + "Relative path requires endpoint to be non-null and non-empty to create an absolute path.")); + } + + if (endpoint.endsWith(FORWARD_SLASH) && path.startsWith(FORWARD_SLASH)) { + return endpoint + path.substring(1); + } else if (!endpoint.endsWith(FORWARD_SLASH) && !path.startsWith(FORWARD_SLASH)) { + return endpoint + FORWARD_SLASH + path; + } else { + return endpoint + path; + } + } + } catch (URISyntaxException ex) { + throw logger.logExceptionAsWarning(new IllegalArgumentException("'path' must be a valid URI.", ex)); + } + return path; + } + + public static T deserializeResponseSync(BinaryData binaryData, ObjectSerializer serializer, + TypeReference typeReference) { + T value; + if (binaryData == null) { + value = null; + } else if (typeReference.getJavaClass().isAssignableFrom(BinaryData.class)) { + // T is BinaryData + value = typeReference.getJavaClass().cast(binaryData.toReplayableBinaryData()); + } else { + value = binaryData.toObject(typeReference, serializer); + } + return value; + } + + @SuppressWarnings("unchecked") + public static Mono deserializeResponse(BinaryData binaryData, ObjectSerializer serializer, + TypeReference typeReference) { + Mono value; + if (binaryData == null) { + value = Mono.empty(); + } else if (typeReference.getJavaClass().isAssignableFrom(BinaryData.class)) { + // T is BinaryData + value = (Mono) binaryData.toReplayableBinaryDataAsync(); + } else { + value = binaryData.toObjectAsync(typeReference, serializer); + } + return value; + } + + private static final HttpHeaderName RETRY_AFTER_MS_HEADER = HttpHeaderName.fromString("retry-after-ms"); + private static final HttpHeaderName X_MS_RETRY_AFTER_MS_HEADER = HttpHeaderName.fromString("x-ms-retry-after-ms"); + + public static Duration getRetryAfterFromHeaders(HttpHeaders headers, Supplier nowSupplier) { + // Found 'x-ms-retry-after-ms' header, use a Duration of milliseconds based on the value. + Duration retryDelay = tryGetRetryDelay(headers, X_MS_RETRY_AFTER_MS_HEADER, s -> tryGetDelayMillis(s)); + if (retryDelay != null) { + return retryDelay; + } + + // Found 'retry-after-ms' header, use a Duration of milliseconds based on the value. + retryDelay = tryGetRetryDelay(headers, RETRY_AFTER_MS_HEADER, s -> tryGetDelayMillis(s)); + if (retryDelay != null) { + return retryDelay; + } + + // Found 'Retry-After' header. First, attempt to resolve it as a Duration of seconds. If that fails, then + // attempt to resolve it as an HTTP date (RFC1123). + retryDelay = tryGetRetryDelay(headers, HttpHeaderName.RETRY_AFTER, + headerValue -> tryParseLongOrDateTime(headerValue, nowSupplier)); + + // Either the retry delay will have been found or it'll be null, null indicates no retry after. + return retryDelay; + } + + private static Duration tryGetRetryDelay(HttpHeaders headers, HttpHeaderName headerName, + Function delayParser) { + String headerValue = headers.getValue(headerName); + + return CoreUtils.isNullOrEmpty(headerValue) ? null : delayParser.apply(headerValue); + } + + private static Duration tryParseLongOrDateTime(String value, Supplier nowSupplier) { + long delaySeconds; + try { + OffsetDateTime retryAfter = new DateTimeRfc1123(value).getDateTime(); + + delaySeconds = nowSupplier.get().until(retryAfter, ChronoUnit.SECONDS); + } catch (DateTimeException ex) { + delaySeconds = tryParseLong(value); + } + + return (delaySeconds >= 0) ? Duration.ofSeconds(delaySeconds) : null; + } + + private static long tryParseLong(String value) { + try { + return Long.parseLong(value); + } catch (NumberFormatException ex) { + return -1; + } + } + + private static Duration tryGetDelayMillis(String value) { + long delayMillis = tryParseLong(value); + return (delayMillis >= 0) ? Duration.ofMillis(delayMillis) : null; + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/SyncOperationLocationPollingStrategy.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/SyncOperationLocationPollingStrategy.java new file mode 100644 index 000000000000..af88e9814a23 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/SyncOperationLocationPollingStrategy.java @@ -0,0 +1,133 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.implementation; + +import com.azure.core.exception.AzureException; +import com.azure.core.http.HttpHeader; +import com.azure.core.http.rest.Response; +import com.azure.core.util.BinaryData; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.polling.LongRunningOperationStatus; +import com.azure.core.util.polling.PollResponse; +import com.azure.core.util.polling.PollingContext; +import com.azure.core.util.polling.PollingStrategyOptions; +import com.azure.core.util.polling.SyncOperationResourcePollingStrategy; +import com.azure.core.util.serializer.JsonSerializerProviders; +import com.azure.core.util.serializer.ObjectSerializer; +import com.azure.core.util.serializer.TypeReference; +import java.io.UncheckedIOException; +import java.time.Duration; +import java.time.OffsetDateTime; +import java.util.Map; + +// DO NOT modify this helper class + +/** + * Implements a synchronous operation location polling strategy, from Operation-Location. + * + * @param the type of the response type from a polling call, or BinaryData if raw response body should be kept + * @param the type of the final result object to deserialize into, or BinaryData if raw response body should be + * kept + */ +public final class SyncOperationLocationPollingStrategy extends SyncOperationResourcePollingStrategy { + + private static final ClientLogger LOGGER = new ClientLogger(SyncOperationLocationPollingStrategy.class); + + private final ObjectSerializer serializer; + private final String endpoint; + private final String propertyName; + + /** + * Creates an instance of the operation resource polling strategy. + * + * @param pollingStrategyOptions options to configure this polling strategy. + * @throws NullPointerException if {@code pollingStrategyOptions} is null. + */ + public SyncOperationLocationPollingStrategy(PollingStrategyOptions pollingStrategyOptions) { + this(pollingStrategyOptions, null); + } + + /** + * Creates an instance of the operation resource polling strategy. + * + * @param pollingStrategyOptions options to configure this polling strategy. + * @param propertyName the name of the property to extract final result. + * @throws NullPointerException if {@code pollingStrategyOptions} is null. + */ + public SyncOperationLocationPollingStrategy(PollingStrategyOptions pollingStrategyOptions, String propertyName) { + super(PollingUtils.OPERATION_LOCATION_HEADER, pollingStrategyOptions); + this.propertyName = propertyName; + this.endpoint = pollingStrategyOptions.getEndpoint(); + this.serializer = pollingStrategyOptions.getSerializer() != null + ? pollingStrategyOptions.getSerializer() + : JsonSerializerProviders.createInstance(true); + } + + /** + * {@inheritDoc} + */ + @Override + public PollResponse onInitialResponse(Response response, PollingContext pollingContext, + TypeReference pollResponseType) { + // Response is Response + + HttpHeader operationLocationHeader = response.getHeaders().get(PollingUtils.OPERATION_LOCATION_HEADER); + if (operationLocationHeader != null) { + pollingContext.setData(PollingUtils.OPERATION_LOCATION_HEADER.getCaseSensitiveName(), + PollingUtils.getAbsolutePath(operationLocationHeader.getValue(), endpoint, LOGGER)); + } + final String httpMethod = response.getRequest().getHttpMethod().name(); + pollingContext.setData(PollingUtils.HTTP_METHOD, httpMethod); + pollingContext.setData(PollingUtils.REQUEST_URL, response.getRequest().getUrl().toString()); + + if (response.getStatusCode() == 200 + || response.getStatusCode() == 201 + || response.getStatusCode() == 202 + || response.getStatusCode() == 204) { + final Duration retryAfter + = PollingUtils.getRetryAfterFromHeaders(response.getHeaders(), OffsetDateTime::now); + T initialResponseType = null; + try { + initialResponseType = PollingUtils.deserializeResponseSync((BinaryData) response.getValue(), serializer, + pollResponseType); + } catch (UncheckedIOException e) { + LOGGER.info("Failed to parse initial response."); + } + return new PollResponse<>(LongRunningOperationStatus.IN_PROGRESS, initialResponseType, retryAfter); + } + + throw LOGGER.logExceptionAsError(new AzureException( + String.format("Operation failed or cancelled with status code %d, '%s' header: %s, and response body: %s", + response.getStatusCode(), PollingUtils.OPERATION_LOCATION_HEADER, operationLocationHeader, + response.getValue()))); + } + + /** + * {@inheritDoc} + */ + public U getResult(PollingContext pollingContext, TypeReference resultType) { + if (pollingContext.getLatestResponse().getStatus() == LongRunningOperationStatus.FAILED) { + throw LOGGER.logExceptionAsError(new AzureException("Long running operation failed.")); + } else if (pollingContext.getLatestResponse().getStatus() == LongRunningOperationStatus.USER_CANCELLED) { + throw LOGGER.logExceptionAsError(new AzureException("Long running operation cancelled.")); + } + if (propertyName != null) { + // take the last poll response body from PollingContext, + // and de-serialize the property as final result + BinaryData latestResponseBody + = BinaryData.fromString(pollingContext.getData(PollingUtils.POLL_RESPONSE_BODY)); + Map pollResult = PollingUtils.deserializeResponseSync(latestResponseBody, serializer, + PollingUtils.POST_POLL_RESULT_TYPE_REFERENCE); + if (pollResult != null && pollResult.get(propertyName) != null) { + return PollingUtils.deserializeResponseSync(BinaryData.fromObject(pollResult.get(propertyName)), + serializer, resultType); + } else { + throw LOGGER.logExceptionAsError(new AzureException("Cannot get final result")); + } + } else { + return super.getResult(pollingContext, resultType); + } + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/WidgetManagerClientImpl.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/WidgetManagerClientImpl.java new file mode 100644 index 000000000000..7f57877add4a --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/WidgetManagerClientImpl.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 com.azure.contoso.widgetmanager.implementation; + +import com.azure.contoso.widgetmanager.WidgetManagerServiceVersion; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; + +/** + * Initializes a new instance of the WidgetManagerClient type. + */ +public final class WidgetManagerClientImpl { + /** + * Service host. + */ + private final String endpoint; + + /** + * Gets Service host. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** + * Service version. + */ + private final WidgetManagerServiceVersion serviceVersion; + + /** + * Gets Service version. + * + * @return the serviceVersion value. + */ + public WidgetManagerServiceVersion getServiceVersion() { + return this.serviceVersion; + } + + /** + * The HTTP pipeline to send requests through. + */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The serializer to serialize an object into a string. + */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + public SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * The WidgetsImpl object to access its operations. + */ + private final WidgetsImpl widgets; + + /** + * Gets the WidgetsImpl object to access its operations. + * + * @return the WidgetsImpl object. + */ + public WidgetsImpl getWidgets() { + return this.widgets; + } + + /** + * Initializes an instance of WidgetManagerClient client. + * + * @param endpoint Service host. + * @param serviceVersion Service version. + */ + public WidgetManagerClientImpl(String endpoint, WidgetManagerServiceVersion serviceVersion) { + this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(), + JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion); + } + + /** + * Initializes an instance of WidgetManagerClient client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param endpoint Service host. + * @param serviceVersion Service version. + */ + public WidgetManagerClientImpl(HttpPipeline httpPipeline, String endpoint, + WidgetManagerServiceVersion serviceVersion) { + this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion); + } + + /** + * Initializes an instance of WidgetManagerClient 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. + * @param serviceVersion Service version. + */ + public WidgetManagerClientImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint, + WidgetManagerServiceVersion serviceVersion) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.endpoint = endpoint; + this.serviceVersion = serviceVersion; + this.widgets = new WidgetsImpl(this); + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/WidgetsImpl.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/WidgetsImpl.java new file mode 100644 index 000000000000..9a2e1fb18997 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/WidgetsImpl.java @@ -0,0 +1,1202 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.implementation; + +import com.azure.contoso.widgetmanager.WidgetManagerServiceVersion; +import com.azure.contoso.widgetmanager.models.WidgetSuite; +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.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.Patch; +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.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.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 com.azure.core.util.polling.PollOperationDetails; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.polling.PollingStrategyOptions; +import com.azure.core.util.polling.SyncPoller; +import com.azure.core.util.serializer.TypeReference; +import java.time.Duration; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in Widgets. + */ +public final class WidgetsImpl { + /** + * The proxy service used to perform REST calls. + */ + private final WidgetsService service; + + /** + * The service client containing this operation class. + */ + private final WidgetManagerClientImpl client; + + /** + * Initializes an instance of WidgetsImpl. + * + * @param client the instance of the service client containing this operation class. + */ + WidgetsImpl(WidgetManagerClientImpl client) { + this.service = RestProxy.create(WidgetsService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * Gets Service version. + * + * @return the serviceVersion value. + */ + public WidgetManagerServiceVersion getServiceVersion() { + return client.getServiceVersion(); + } + + /** + * The interface defining all the services for WidgetManagerClientWidgets to be used by the proxy service to perform + * REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "WidgetManagerClientW") + public interface WidgetsService { + @Get("/widgets/{widgetName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getWidget(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("widgetName") String widgetName, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/widgets/{widgetName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response getWidgetSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("widgetName") String widgetName, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/widgets/{widgetName}/operations/{operationId}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> getWidgetOperationStatus(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("widgetName") String widgetName, + @PathParam("operationId") String operationId, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Get("/widgets/{widgetName}/operations/{operationId}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response getWidgetOperationStatusSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("widgetName") String widgetName, + @PathParam("operationId") String operationId, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Patch("/widgets/{widgetName}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> createOrUpdateWidget(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("widgetName") String widgetName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/merge-patch+json") BinaryData resource, RequestOptions requestOptions, + Context context); + + @Patch("/widgets/{widgetName}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response createOrUpdateWidgetSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("widgetName") String widgetName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/merge-patch+json") BinaryData resource, RequestOptions requestOptions, + Context context); + + @Delete("/widgets/{widgetName}") + @ExpectedResponses({ 202 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> deleteWidget(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("widgetName") String widgetName, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Delete("/widgets/{widgetName}") + @ExpectedResponses({ 202 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response deleteWidgetSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("widgetName") String widgetName, + @HeaderParam("Accept") String accept, RequestOptions requestOptions, Context context); + + @Get("/widgets") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> listWidgets(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @HeaderParam("Accept") String accept, + RequestOptions requestOptions, Context context); + + @Get("/widgets") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response listWidgetsSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @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> listWidgetsNext(@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 listWidgetsNextSync(@PathParam(value = "nextLink", encoded = true) String nextLink, + @HostParam("endpoint") String endpoint, @HeaderParam("Accept") String accept, RequestOptions requestOptions, + Context context); + } + + /** + * Fetch a Widget by name. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @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 a widget along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getWidgetWithResponseAsync(String widgetName, RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.getWidget(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), widgetName, accept, requestOptions, context)); + } + + /** + * Fetch a Widget by name. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @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 a widget along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getWidgetWithResponse(String widgetName, RequestOptions requestOptions) { + final String accept = "application/json"; + return service.getWidgetSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), + widgetName, accept, requestOptions, Context.NONE); + } + + /** + * Gets status of a Widget operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     *     result (Optional): {
+     *         name: String (Required)
+     *         manufacturerId: String (Optional, Required on create)
+     *         sharedModel (Optional): {
+     *             tag: String (Optional, Required on create)
+     *             createdAt: OffsetDateTime (Optional, Required on create)
+     *         }
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @param operationId The unique ID of the operation. + * @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 status of a Widget operation along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> getWidgetOperationStatusWithResponseAsync(String widgetName, String operationId, + RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.getWidgetOperationStatus(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), widgetName, operationId, accept, requestOptions, context)); + } + + /** + * Gets status of a Widget operation. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     *     result (Optional): {
+     *         name: String (Required)
+     *         manufacturerId: String (Optional, Required on create)
+     *         sharedModel (Optional): {
+     *             tag: String (Optional, Required on create)
+     *             createdAt: OffsetDateTime (Optional, Required on create)
+     *         }
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @param operationId The unique ID of the operation. + * @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 status of a Widget operation along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getWidgetOperationStatusWithResponse(String widgetName, String operationId, + RequestOptions requestOptions) { + final String accept = "application/json"; + return service.getWidgetOperationStatusSync(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), widgetName, operationId, accept, requestOptions, + Context.NONE); + } + + /** + * Creates or updates a Widget asynchronously. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @param resource The resource instance. + * @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 a widget along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> createOrUpdateWidgetWithResponseAsync(String widgetName, BinaryData resource, + RequestOptions requestOptions) { + final String contentType = "application/merge-patch+json"; + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.createOrUpdateWidget(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), widgetName, contentType, accept, resource, requestOptions, + context)); + } + + /** + * Creates or updates a Widget asynchronously. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @param resource The resource instance. + * @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 a widget along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Response createOrUpdateWidgetWithResponse(String widgetName, BinaryData resource, + RequestOptions requestOptions) { + final String contentType = "application/merge-patch+json"; + final String accept = "application/json"; + return service.createOrUpdateWidgetSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), + widgetName, contentType, accept, resource, requestOptions, Context.NONE); + } + + /** + * Creates or updates a Widget asynchronously. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @param resource The resource instance. + * @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 {@link PollerFlux} for polling of a widget. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux beginCreateOrUpdateWidgetAsync(String widgetName, BinaryData resource, + RequestOptions requestOptions) { + return PollerFlux.create(Duration.ofSeconds(1), + () -> this.createOrUpdateWidgetWithResponseAsync(widgetName, resource, requestOptions), + new com.azure.contoso.widgetmanager.implementation.OperationLocationPollingStrategy<>( + new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(requestOptions != null && requestOptions.getContext() != null + ? requestOptions.getContext() + : Context.NONE) + .setServiceVersion(this.client.getServiceVersion().getVersion()), + "result"), + TypeReference.createInstance(BinaryData.class), TypeReference.createInstance(BinaryData.class)); + } + + /** + * Creates or updates a Widget asynchronously. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @param resource The resource instance. + * @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 {@link SyncPoller} for polling of a widget. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller beginCreateOrUpdateWidget(String widgetName, BinaryData resource, + RequestOptions requestOptions) { + return SyncPoller.createPoller(Duration.ofSeconds(1), + () -> this.createOrUpdateWidgetWithResponse(widgetName, resource, requestOptions), + new com.azure.contoso.widgetmanager.implementation.SyncOperationLocationPollingStrategy<>( + new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(requestOptions != null && requestOptions.getContext() != null + ? requestOptions.getContext() + : Context.NONE) + .setServiceVersion(this.client.getServiceVersion().getVersion()), + "result"), + TypeReference.createInstance(BinaryData.class), TypeReference.createInstance(BinaryData.class)); + } + + /** + * Creates or updates a Widget asynchronously. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @param resource The resource instance. + * @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 {@link PollerFlux} for polling of a widget. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux beginCreateOrUpdateWidgetWithModelAsync(String widgetName, + BinaryData resource, RequestOptions requestOptions) { + return PollerFlux.create(Duration.ofSeconds(1), + () -> this.createOrUpdateWidgetWithResponseAsync(widgetName, resource, requestOptions), + new com.azure.contoso.widgetmanager.implementation.OperationLocationPollingStrategy<>( + new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(requestOptions != null && requestOptions.getContext() != null + ? requestOptions.getContext() + : Context.NONE) + .setServiceVersion(this.client.getServiceVersion().getVersion()), + "result"), + TypeReference.createInstance(PollOperationDetails.class), TypeReference.createInstance(WidgetSuite.class)); + } + + /** + * Creates or updates a Widget asynchronously. + *

Request Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @param resource The resource instance. + * @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 {@link SyncPoller} for polling of a widget. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller beginCreateOrUpdateWidgetWithModel(String widgetName, + BinaryData resource, RequestOptions requestOptions) { + return SyncPoller.createPoller(Duration.ofSeconds(1), + () -> this.createOrUpdateWidgetWithResponse(widgetName, resource, requestOptions), + new com.azure.contoso.widgetmanager.implementation.SyncOperationLocationPollingStrategy<>( + new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(requestOptions != null && requestOptions.getContext() != null + ? requestOptions.getContext() + : Context.NONE) + .setServiceVersion(this.client.getServiceVersion().getVersion()), + "result"), + TypeReference.createInstance(PollOperationDetails.class), TypeReference.createInstance(WidgetSuite.class)); + } + + /** + * Delete a Widget asynchronously. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @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 provides status details for long running operations along with {@link Response} on successful completion + * of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> deleteWidgetWithResponseAsync(String widgetName, RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.deleteWidget(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), widgetName, accept, requestOptions, context)); + } + + /** + * Delete a Widget asynchronously. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @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 provides status details for long running operations along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Response deleteWidgetWithResponse(String widgetName, RequestOptions requestOptions) { + final String accept = "application/json"; + return service.deleteWidgetSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), + widgetName, accept, requestOptions, Context.NONE); + } + + /** + * Delete a Widget asynchronously. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @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 {@link PollerFlux} for polling of provides status details for long running operations. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux beginDeleteWidgetAsync(String widgetName, RequestOptions requestOptions) { + return PollerFlux.create(Duration.ofSeconds(1), + () -> this.deleteWidgetWithResponseAsync(widgetName, requestOptions), + new com.azure.contoso.widgetmanager.implementation.OperationLocationPollingStrategy<>( + new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(requestOptions != null && requestOptions.getContext() != null + ? requestOptions.getContext() + : Context.NONE) + .setServiceVersion(this.client.getServiceVersion().getVersion())), + TypeReference.createInstance(BinaryData.class), TypeReference.createInstance(Void.class)); + } + + /** + * Delete a Widget asynchronously. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @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 {@link SyncPoller} for polling of provides status details for long running operations. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller beginDeleteWidget(String widgetName, RequestOptions requestOptions) { + return SyncPoller.createPoller(Duration.ofSeconds(1), + () -> this.deleteWidgetWithResponse(widgetName, requestOptions), + new com.azure.contoso.widgetmanager.implementation.SyncOperationLocationPollingStrategy<>( + new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(requestOptions != null && requestOptions.getContext() != null + ? requestOptions.getContext() + : Context.NONE) + .setServiceVersion(this.client.getServiceVersion().getVersion())), + TypeReference.createInstance(BinaryData.class), TypeReference.createInstance(Void.class)); + } + + /** + * Delete a Widget asynchronously. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @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 {@link PollerFlux} for polling of provides status details for long running operations. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public PollerFlux beginDeleteWidgetWithModelAsync(String widgetName, + RequestOptions requestOptions) { + return PollerFlux.create(Duration.ofSeconds(1), + () -> this.deleteWidgetWithResponseAsync(widgetName, requestOptions), + new com.azure.contoso.widgetmanager.implementation.OperationLocationPollingStrategy<>( + new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(requestOptions != null && requestOptions.getContext() != null + ? requestOptions.getContext() + : Context.NONE) + .setServiceVersion(this.client.getServiceVersion().getVersion())), + TypeReference.createInstance(PollOperationDetails.class), TypeReference.createInstance(Void.class)); + } + + /** + * Delete a Widget asynchronously. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     id: String (Required)
+     *     status: String(NotStarted/Running/Succeeded/Failed/Canceled) (Required)
+     *     error (Optional): {
+     *         code: String (Required)
+     *         message: String (Required)
+     *         target: String (Optional)
+     *         details (Optional): [
+     *             (recursive schema, see above)
+     *         ]
+     *         innererror (Optional): {
+     *             code: String (Optional)
+     *             innererror (Optional): (recursive schema, see innererror above)
+     *         }
+     *     }
+     * }
+     * }
+     * 
+ * + * @param widgetName The widget name. + * @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 {@link SyncPoller} for polling of provides status details for long running operations. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller beginDeleteWidgetWithModel(String widgetName, + RequestOptions requestOptions) { + return SyncPoller.createPoller(Duration.ofSeconds(1), + () -> this.deleteWidgetWithResponse(widgetName, requestOptions), + new com.azure.contoso.widgetmanager.implementation.SyncOperationLocationPollingStrategy<>( + new PollingStrategyOptions(this.client.getHttpPipeline()) + .setEndpoint("{endpoint}".replace("{endpoint}", this.client.getEndpoint())) + .setContext(requestOptions != null && requestOptions.getContext() != null + ? requestOptions.getContext() + : Context.NONE) + .setServiceVersion(this.client.getServiceVersion().getVersion())), + TypeReference.createInstance(PollOperationDetails.class), TypeReference.createInstance(Void.class)); + } + + /** + * List Widget resources. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @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 paged collection of WidgetSuite items along with {@link PagedResponse} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listWidgetsSinglePageAsync(RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.listWidgets(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null)); + } + + /** + * List Widget resources. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @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 paged collection of WidgetSuite items as paginated response with {@link PagedFlux}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedFlux listWidgetsAsync(RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedFlux<>(() -> listWidgetsSinglePageAsync(requestOptions), + nextLink -> listWidgetsNextSinglePageAsync(nextLink, requestOptionsForNextPage)); + } + + /** + * List Widget resources. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @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 paged collection of WidgetSuite items along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listWidgetsSinglePage(RequestOptions requestOptions) { + final String accept = "application/json"; + Response res = service.listWidgetsSync(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null); + } + + /** + * List Widget resources. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @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 paged collection of WidgetSuite items as paginated response with {@link PagedIterable}. + */ + @ServiceMethod(returns = ReturnType.COLLECTION) + public PagedIterable listWidgets(RequestOptions requestOptions) { + RequestOptions requestOptionsForNextPage = new RequestOptions(); + requestOptionsForNextPage.setContext( + requestOptions != null && requestOptions.getContext() != null ? requestOptions.getContext() : Context.NONE); + return new PagedIterable<>(() -> listWidgetsSinglePage(requestOptions), + nextLink -> listWidgetsNextSinglePage(nextLink, requestOptionsForNextPage)); + } + + /** + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @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 paged collection of WidgetSuite items along with {@link PagedResponse} on successful completion of + * {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> listWidgetsNextSinglePageAsync(String nextLink, + RequestOptions requestOptions) { + final String accept = "application/json"; + return FluxUtil.withContext( + context -> service.listWidgetsNext(nextLink, this.client.getEndpoint(), accept, requestOptions, context)) + .map(res -> new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), null)); + } + + /** + * Get the next page of items. + *

Response Body Schema

+ * + *
+     * {@code
+     * {
+     *     name: String (Required)
+     *     manufacturerId: String (Optional, Required on create)
+     *     sharedModel (Optional): {
+     *         tag: String (Optional, Required on create)
+     *         createdAt: OffsetDateTime (Optional, Required on create)
+     *     }
+     * }
+     * }
+     * 
+ * + * @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 paged collection of WidgetSuite items along with {@link PagedResponse}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private PagedResponse listWidgetsNextSinglePage(String nextLink, RequestOptions requestOptions) { + final String accept = "application/json"; + Response res + = service.listWidgetsNextSync(nextLink, this.client.getEndpoint(), accept, requestOptions, Context.NONE); + return new PagedResponseBase<>(res.getRequest(), res.getStatusCode(), res.getHeaders(), + getValues(res.getValue(), "value"), getNextLink(res.getValue(), "nextLink"), 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/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/package-info.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/package-info.java new file mode 100644 index 000000000000..5bccc0987be3 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/implementation/package-info.java @@ -0,0 +1,8 @@ +// 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 WidgetManager. + */ +package com.azure.contoso.widgetmanager.implementation; diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/models/FakedSharedModel.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/models/FakedSharedModel.java new file mode 100644 index 000000000000..bde01c9851f0 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/models/FakedSharedModel.java @@ -0,0 +1,190 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.models; + +import com.azure.contoso.widgetmanager.implementation.JsonMergePatchHelper; +import com.azure.core.annotation.Fluent; +import com.azure.core.annotation.Generated; +import com.azure.core.util.CoreUtils; +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.time.OffsetDateTime; +import java.time.format.DateTimeFormatter; +import java.util.HashSet; +import java.util.Set; + +/** + * Faked shared model. + */ +@Fluent +public final class FakedSharedModel implements JsonSerializable { + /* + * The tag. + */ + @Generated + private String tag; + + /* + * The created date. + */ + @Generated + private OffsetDateTime createdAt; + + /** + * Stores updated model property, the value is property name, not serialized name. + */ + @Generated + private final Set updatedProperties = new HashSet<>(); + + @Generated + private boolean jsonMergePatch; + + @Generated + private void serializeAsJsonMergePatch(boolean jsonMergePatch) { + this.jsonMergePatch = jsonMergePatch; + } + + static { + JsonMergePatchHelper.setFakedSharedModelAccessor(new JsonMergePatchHelper.FakedSharedModelAccessor() { + @Override + public FakedSharedModel prepareModelForJsonMergePatch(FakedSharedModel model, + boolean jsonMergePatchEnabled) { + model.serializeAsJsonMergePatch(jsonMergePatchEnabled); + return model; + } + + @Override + public boolean isJsonMergePatch(FakedSharedModel model) { + return model.jsonMergePatch; + } + }); + } + + /** + * Creates an instance of FakedSharedModel class. + */ + @Generated + public FakedSharedModel() { + } + + /** + * Get the tag property: The tag. + * + * @return the tag value. + */ + @Generated + public String getTag() { + return this.tag; + } + + /** + * Set the tag property: The tag. + *

Required when create the resource.

+ * + * @param tag the tag value to set. + * @return the FakedSharedModel object itself. + */ + @Generated + public FakedSharedModel setTag(String tag) { + this.tag = tag; + this.updatedProperties.add("tag"); + return this; + } + + /** + * Get the createdAt property: The created date. + * + * @return the createdAt value. + */ + @Generated + public OffsetDateTime getCreatedAt() { + return this.createdAt; + } + + /** + * Set the createdAt property: The created date. + *

Required when create the resource.

+ * + * @param createdAt the createdAt value to set. + * @return the FakedSharedModel object itself. + */ + @Generated + public FakedSharedModel setCreatedAt(OffsetDateTime createdAt) { + this.createdAt = createdAt; + this.updatedProperties.add("createdAt"); + return this; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + if (jsonMergePatch) { + return toJsonMergePatch(jsonWriter); + } else { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("tag", this.tag); + jsonWriter.writeStringField("createdAt", + this.createdAt == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.createdAt)); + return jsonWriter.writeEndObject(); + } + } + + @Generated + private JsonWriter toJsonMergePatch(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + if (updatedProperties.contains("tag")) { + if (this.tag == null) { + jsonWriter.writeNullField("tag"); + } else { + jsonWriter.writeStringField("tag", this.tag); + } + } + if (updatedProperties.contains("createdAt")) { + if (this.createdAt == null) { + jsonWriter.writeNullField("createdAt"); + } else { + jsonWriter.writeStringField("createdAt", + this.createdAt == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.createdAt)); + } + } + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of FakedSharedModel from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of FakedSharedModel 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 FakedSharedModel. + */ + @Generated + public static FakedSharedModel fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + FakedSharedModel deserializedFakedSharedModel = new FakedSharedModel(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("tag".equals(fieldName)) { + deserializedFakedSharedModel.tag = reader.getString(); + } else if ("createdAt".equals(fieldName)) { + deserializedFakedSharedModel.createdAt = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); + } else { + reader.skipChildren(); + } + } + + return deserializedFakedSharedModel; + }); + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/models/OperationState.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/models/OperationState.java new file mode 100644 index 000000000000..09213c0e1307 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/models/OperationState.java @@ -0,0 +1,75 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * Enum describing allowed operation states. + */ +public final class OperationState extends ExpandableStringEnum { + /** + * The operation has not started. + */ + @Generated + public static final OperationState NOT_STARTED = fromString("NotStarted"); + + /** + * The operation is in progress. + */ + @Generated + public static final OperationState RUNNING = fromString("Running"); + + /** + * The operation has completed successfully. + */ + @Generated + public static final OperationState SUCCEEDED = fromString("Succeeded"); + + /** + * The operation has failed. + */ + @Generated + public static final OperationState FAILED = fromString("Failed"); + + /** + * The operation has been canceled by the user. + */ + @Generated + public static final OperationState CANCELED = fromString("Canceled"); + + /** + * Creates a new instance of OperationState value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Generated + @Deprecated + public OperationState() { + } + + /** + * Creates or finds a OperationState from its string representation. + * + * @param name a name to look for. + * @return the corresponding OperationState. + */ + @Generated + public static OperationState fromString(String name) { + return fromString(name, OperationState.class); + } + + /** + * Gets known OperationState values. + * + * @return known OperationState values. + */ + @Generated + public static Collection values() { + return values(OperationState.class); + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/models/ResourceOperationStatusWidgetSuiteWidgetSuiteError.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/models/ResourceOperationStatusWidgetSuiteWidgetSuiteError.java new file mode 100644 index 000000000000..a3d96ddf478b --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/models/ResourceOperationStatusWidgetSuiteWidgetSuiteError.java @@ -0,0 +1,151 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.models; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.Immutable; +import com.azure.core.models.ResponseError; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Provides status details for long running operations. + */ +@Immutable +public final class ResourceOperationStatusWidgetSuiteWidgetSuiteError + implements JsonSerializable { + /* + * The unique ID of the operation. + */ + @Generated + private String id; + + /* + * The status of the operation + */ + @Generated + private final OperationState status; + + /* + * Error object that describes the error when status is "Failed". + */ + @Generated + private ResponseError error; + + /* + * The result of the operation. + */ + @Generated + private WidgetSuite result; + + /** + * Creates an instance of ResourceOperationStatusWidgetSuiteWidgetSuiteError class. + * + * @param status the status value to set. + */ + @Generated + private ResourceOperationStatusWidgetSuiteWidgetSuiteError(OperationState status) { + this.status = status; + } + + /** + * Get the id property: The unique ID of the operation. + * + * @return the id value. + */ + @Generated + public String getId() { + return this.id; + } + + /** + * Get the status property: The status of the operation. + * + * @return the status value. + */ + @Generated + public OperationState getStatus() { + return this.status; + } + + /** + * Get the error property: Error object that describes the error when status is "Failed". + * + * @return the error value. + */ + @Generated + public ResponseError getError() { + return this.error; + } + + /** + * Get the result property: The result of the operation. + * + * @return the result value. + */ + @Generated + public WidgetSuite getResult() { + return this.result; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("status", this.status == null ? null : this.status.toString()); + jsonWriter.writeJsonField("error", this.error); + jsonWriter.writeJsonField("result", this.result); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of ResourceOperationStatusWidgetSuiteWidgetSuiteError from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of ResourceOperationStatusWidgetSuiteWidgetSuiteError 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 ResourceOperationStatusWidgetSuiteWidgetSuiteError. + */ + @Generated + public static ResourceOperationStatusWidgetSuiteWidgetSuiteError fromJson(JsonReader jsonReader) + throws IOException { + return jsonReader.readObject(reader -> { + String id = null; + OperationState status = null; + ResponseError error = null; + WidgetSuite result = null; + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + id = reader.getString(); + } else if ("status".equals(fieldName)) { + status = OperationState.fromString(reader.getString()); + } else if ("error".equals(fieldName)) { + error = ResponseError.fromJson(reader); + } else if ("result".equals(fieldName)) { + result = WidgetSuite.fromJson(reader); + } else { + reader.skipChildren(); + } + } + ResourceOperationStatusWidgetSuiteWidgetSuiteError deserializedResourceOperationStatusWidgetSuiteWidgetSuiteError + = new ResourceOperationStatusWidgetSuiteWidgetSuiteError(status); + deserializedResourceOperationStatusWidgetSuiteWidgetSuiteError.id = id; + deserializedResourceOperationStatusWidgetSuiteWidgetSuiteError.error = error; + deserializedResourceOperationStatusWidgetSuiteWidgetSuiteError.result = result; + + return deserializedResourceOperationStatusWidgetSuiteWidgetSuiteError; + }); + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/models/WidgetSuite.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/models/WidgetSuite.java new file mode 100644 index 000000000000..45d8288c1346 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/models/WidgetSuite.java @@ -0,0 +1,205 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.models; + +import com.azure.contoso.widgetmanager.implementation.JsonMergePatchHelper; +import com.azure.core.annotation.Fluent; +import com.azure.core.annotation.Generated; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.HashSet; +import java.util.Set; + +/** + * A widget. + */ +@Fluent +public final class WidgetSuite implements JsonSerializable { + /* + * The widget name. + */ + @Generated + private String name; + + /* + * The ID of the widget's manufacturer. + */ + @Generated + private String manufacturerId; + + /* + * The faked shared model. + */ + @Generated + private FakedSharedModel sharedModel; + + /** + * Stores updated model property, the value is property name, not serialized name. + */ + @Generated + private final Set updatedProperties = new HashSet<>(); + + @Generated + private boolean jsonMergePatch; + + @Generated + private void serializeAsJsonMergePatch(boolean jsonMergePatch) { + this.jsonMergePatch = jsonMergePatch; + } + + static { + JsonMergePatchHelper.setWidgetSuiteAccessor(new JsonMergePatchHelper.WidgetSuiteAccessor() { + @Override + public WidgetSuite prepareModelForJsonMergePatch(WidgetSuite model, boolean jsonMergePatchEnabled) { + model.serializeAsJsonMergePatch(jsonMergePatchEnabled); + return model; + } + + @Override + public boolean isJsonMergePatch(WidgetSuite model) { + return model.jsonMergePatch; + } + }); + } + + /** + * Creates an instance of WidgetSuite class. + */ + @Generated + public WidgetSuite() { + } + + /** + * Get the name property: The widget name. + * + * @return the name value. + */ + @Generated + public String getName() { + return this.name; + } + + /** + * Get the manufacturerId property: The ID of the widget's manufacturer. + * + * @return the manufacturerId value. + */ + @Generated + public String getManufacturerId() { + return this.manufacturerId; + } + + /** + * Set the manufacturerId property: The ID of the widget's manufacturer. + *

Required when create the resource.

+ * + * @param manufacturerId the manufacturerId value to set. + * @return the WidgetSuite object itself. + */ + @Generated + public WidgetSuite setManufacturerId(String manufacturerId) { + this.manufacturerId = manufacturerId; + this.updatedProperties.add("manufacturerId"); + return this; + } + + /** + * Get the sharedModel property: The faked shared model. + * + * @return the sharedModel value. + */ + @Generated + public FakedSharedModel getSharedModel() { + return this.sharedModel; + } + + /** + * Set the sharedModel property: The faked shared model. + * + * @param sharedModel the sharedModel value to set. + * @return the WidgetSuite object itself. + */ + @Generated + public WidgetSuite setSharedModel(FakedSharedModel sharedModel) { + this.sharedModel = sharedModel; + this.updatedProperties.add("sharedModel"); + return this; + } + + /** + * {@inheritDoc} + */ + @Generated + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + if (jsonMergePatch) { + return toJsonMergePatch(jsonWriter); + } else { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("manufacturerId", this.manufacturerId); + jsonWriter.writeJsonField("sharedModel", this.sharedModel); + return jsonWriter.writeEndObject(); + } + } + + @Generated + private JsonWriter toJsonMergePatch(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + if (updatedProperties.contains("manufacturerId")) { + if (this.manufacturerId == null) { + jsonWriter.writeNullField("manufacturerId"); + } else { + jsonWriter.writeStringField("manufacturerId", this.manufacturerId); + } + } + if (updatedProperties.contains("sharedModel")) { + if (this.sharedModel == null) { + jsonWriter.writeNullField("sharedModel"); + } else { + JsonMergePatchHelper.getFakedSharedModelAccessor() + .prepareModelForJsonMergePatch(this.sharedModel, true); + jsonWriter.writeJsonField("sharedModel", this.sharedModel); + JsonMergePatchHelper.getFakedSharedModelAccessor() + .prepareModelForJsonMergePatch(this.sharedModel, false); + } + } + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of WidgetSuite from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of WidgetSuite 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 WidgetSuite. + */ + @Generated + public static WidgetSuite fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + WidgetSuite deserializedWidgetSuite = new WidgetSuite(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("name".equals(fieldName)) { + deserializedWidgetSuite.name = reader.getString(); + } else if ("manufacturerId".equals(fieldName)) { + deserializedWidgetSuite.manufacturerId = reader.getString(); + } else if ("sharedModel".equals(fieldName)) { + deserializedWidgetSuite.sharedModel = FakedSharedModel.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedWidgetSuite; + }); + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/models/package-info.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/models/package-info.java new file mode 100644 index 000000000000..d37fdb5f4bfe --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/models/package-info.java @@ -0,0 +1,8 @@ +// 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 WidgetManager. + */ +package com.azure.contoso.widgetmanager.models; diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/package-info.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/package-info.java new file mode 100644 index 000000000000..3e3df931cd9e --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/com/azure/contoso/widgetmanager/package-info.java @@ -0,0 +1,8 @@ +// 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 WidgetManager. + */ +package com.azure.contoso.widgetmanager; diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/module-info.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/module-info.java new file mode 100644 index 000000000000..4dfd7d0862af --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/java/module-info.java @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +module com.azure.contoso.widgetmanager { + requires transitive com.azure.core; + + exports com.azure.contoso.widgetmanager; + exports com.azure.contoso.widgetmanager.models; + + opens com.azure.contoso.widgetmanager.models to com.azure.core; +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/resources/META-INF/azure-contoso-widgetmanager_apiview_properties.json b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/resources/META-INF/azure-contoso-widgetmanager_apiview_properties.json new file mode 100644 index 000000000000..bbd8ab308715 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/resources/META-INF/azure-contoso-widgetmanager_apiview_properties.json @@ -0,0 +1,30 @@ +{ + "flavor": "azure", + "CrossLanguageDefinitionId": { + "com.azure.contoso.widgetmanager.WidgetManagerAsyncClient": "Azure.Contoso.WidgetManager.Widgets", + "com.azure.contoso.widgetmanager.WidgetManagerAsyncClient.beginCreateOrUpdateWidget": "Azure.Contoso.WidgetManager.Widgets.createOrUpdateWidget", + "com.azure.contoso.widgetmanager.WidgetManagerAsyncClient.beginCreateOrUpdateWidgetWithModel": "Azure.Contoso.WidgetManager.Widgets.createOrUpdateWidget", + "com.azure.contoso.widgetmanager.WidgetManagerAsyncClient.beginDeleteWidget": "Azure.Contoso.WidgetManager.Widgets.deleteWidget", + "com.azure.contoso.widgetmanager.WidgetManagerAsyncClient.beginDeleteWidgetWithModel": "Azure.Contoso.WidgetManager.Widgets.deleteWidget", + "com.azure.contoso.widgetmanager.WidgetManagerAsyncClient.getWidget": "Azure.Contoso.WidgetManager.Widgets.getWidget", + "com.azure.contoso.widgetmanager.WidgetManagerAsyncClient.getWidgetOperationStatus": "Azure.Contoso.WidgetManager.Widgets.getWidgetOperationStatus", + "com.azure.contoso.widgetmanager.WidgetManagerAsyncClient.getWidgetOperationStatusWithResponse": "Azure.Contoso.WidgetManager.Widgets.getWidgetOperationStatus", + "com.azure.contoso.widgetmanager.WidgetManagerAsyncClient.getWidgetWithResponse": "Azure.Contoso.WidgetManager.Widgets.getWidget", + "com.azure.contoso.widgetmanager.WidgetManagerAsyncClient.listWidgets": "Azure.Contoso.WidgetManager.Widgets.listWidgets", + "com.azure.contoso.widgetmanager.WidgetManagerClient": "Azure.Contoso.WidgetManager.Widgets", + "com.azure.contoso.widgetmanager.WidgetManagerClient.beginCreateOrUpdateWidget": "Azure.Contoso.WidgetManager.Widgets.createOrUpdateWidget", + "com.azure.contoso.widgetmanager.WidgetManagerClient.beginCreateOrUpdateWidgetWithModel": "Azure.Contoso.WidgetManager.Widgets.createOrUpdateWidget", + "com.azure.contoso.widgetmanager.WidgetManagerClient.beginDeleteWidget": "Azure.Contoso.WidgetManager.Widgets.deleteWidget", + "com.azure.contoso.widgetmanager.WidgetManagerClient.beginDeleteWidgetWithModel": "Azure.Contoso.WidgetManager.Widgets.deleteWidget", + "com.azure.contoso.widgetmanager.WidgetManagerClient.getWidget": "Azure.Contoso.WidgetManager.Widgets.getWidget", + "com.azure.contoso.widgetmanager.WidgetManagerClient.getWidgetOperationStatus": "Azure.Contoso.WidgetManager.Widgets.getWidgetOperationStatus", + "com.azure.contoso.widgetmanager.WidgetManagerClient.getWidgetOperationStatusWithResponse": "Azure.Contoso.WidgetManager.Widgets.getWidgetOperationStatus", + "com.azure.contoso.widgetmanager.WidgetManagerClient.getWidgetWithResponse": "Azure.Contoso.WidgetManager.Widgets.getWidget", + "com.azure.contoso.widgetmanager.WidgetManagerClient.listWidgets": "Azure.Contoso.WidgetManager.Widgets.listWidgets", + "com.azure.contoso.widgetmanager.WidgetManagerClientBuilder": "Azure.Contoso.WidgetManager", + "com.azure.contoso.widgetmanager.models.FakedSharedModel": "FakedSharedModel", + "com.azure.contoso.widgetmanager.models.OperationState": "Azure.Core.Foundations.OperationState", + "com.azure.contoso.widgetmanager.models.ResourceOperationStatusWidgetSuiteWidgetSuiteError": "Azure.Core.ResourceOperationStatus", + "com.azure.contoso.widgetmanager.models.WidgetSuite": "Azure.Contoso.WidgetManager.WidgetSuite" + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/resources/azure-contoso-widgetmanager.properties b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/resources/azure-contoso-widgetmanager.properties new file mode 100644 index 000000000000..ca812989b4f2 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/main/resources/azure-contoso-widgetmanager.properties @@ -0,0 +1,2 @@ +name=${project.artifactId} +version=${project.version} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/ReadmeSamples.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/ReadmeSamples.java new file mode 100644 index 000000000000..0b22137a223e --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/ReadmeSamples.java @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager; + +public final class ReadmeSamples { + public void readmeSamples() { + // BEGIN: com.azure.contoso.widgetmanager.readme + // END: com.azure.contoso.widgetmanager.readme + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/generated/DeleteWidgetByWidgetNameUsingLongRunningOperation.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/generated/DeleteWidgetByWidgetNameUsingLongRunningOperation.java new file mode 100644 index 000000000000..9a4d41d81c11 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/generated/DeleteWidgetByWidgetNameUsingLongRunningOperation.java @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.generated; + +import com.azure.contoso.widgetmanager.WidgetManagerClient; +import com.azure.contoso.widgetmanager.WidgetManagerClientBuilder; +import com.azure.core.util.Configuration; +import com.azure.core.util.polling.PollOperationDetails; +import com.azure.core.util.polling.SyncPoller; +import com.azure.identity.DefaultAzureCredentialBuilder; + +public class DeleteWidgetByWidgetNameUsingLongRunningOperation { + public static void main(String[] args) { + WidgetManagerClient widgetManagerClient + = new WidgetManagerClientBuilder().credential(new DefaultAzureCredentialBuilder().build()) + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT")) + .buildClient(); + // BEGIN:com.azure.contoso.widgetmanager.generated.widgetsdeletewidget.deletewidgetbywidgetnameusinglongrunningoperation + SyncPoller response = widgetManagerClient.beginDeleteWidget("searchbox"); + // END:com.azure.contoso.widgetmanager.generated.widgetsdeletewidget.deletewidgetbywidgetnameusinglongrunningoperation + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/generated/GetWidgetByWidgetName.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/generated/GetWidgetByWidgetName.java new file mode 100644 index 000000000000..5431ff290d44 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/generated/GetWidgetByWidgetName.java @@ -0,0 +1,23 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.generated; + +import com.azure.contoso.widgetmanager.WidgetManagerClient; +import com.azure.contoso.widgetmanager.WidgetManagerClientBuilder; +import com.azure.contoso.widgetmanager.models.WidgetSuite; +import com.azure.core.util.Configuration; +import com.azure.identity.DefaultAzureCredentialBuilder; + +public class GetWidgetByWidgetName { + public static void main(String[] args) { + WidgetManagerClient widgetManagerClient + = new WidgetManagerClientBuilder().credential(new DefaultAzureCredentialBuilder().build()) + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT")) + .buildClient(); + // BEGIN:com.azure.contoso.widgetmanager.generated.widgetsgetwidget.getwidgetbywidgetname + WidgetSuite response = widgetManagerClient.getWidget("searchbox"); + // END:com.azure.contoso.widgetmanager.generated.widgetsgetwidget.getwidgetbywidgetname + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/generated/WidgetsCreateOrUpdateWidget.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/generated/WidgetsCreateOrUpdateWidget.java new file mode 100644 index 000000000000..58d9b048ac6d --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/generated/WidgetsCreateOrUpdateWidget.java @@ -0,0 +1,30 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.generated; + +import com.azure.contoso.widgetmanager.WidgetManagerClient; +import com.azure.contoso.widgetmanager.WidgetManagerClientBuilder; +import com.azure.contoso.widgetmanager.models.FakedSharedModel; +import com.azure.contoso.widgetmanager.models.WidgetSuite; +import com.azure.core.util.Configuration; +import com.azure.core.util.polling.PollOperationDetails; +import com.azure.core.util.polling.SyncPoller; +import com.azure.identity.DefaultAzureCredentialBuilder; +import java.time.OffsetDateTime; + +public class WidgetsCreateOrUpdateWidget { + public static void main(String[] args) { + WidgetManagerClient widgetManagerClient + = new WidgetManagerClientBuilder().credential(new DefaultAzureCredentialBuilder().build()) + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT")) + .buildClient(); + // BEGIN:com.azure.contoso.widgetmanager.generated.widgetscreateorupdatewidget.widgetscreateorupdatewidget + SyncPoller response = widgetManagerClient.beginCreateOrUpdateWidget("name1", + new WidgetSuite().setManufacturerId("manufacturer id1") + .setSharedModel(new FakedSharedModel().setTag("tag1") + .setCreatedAt(OffsetDateTime.parse("2023-01-09T02:12:25.689Z")))); + // END:com.azure.contoso.widgetmanager.generated.widgetscreateorupdatewidget.widgetscreateorupdatewidget + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/generated/WidgetsGetWidgetOperationStatus.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/generated/WidgetsGetWidgetOperationStatus.java new file mode 100644 index 000000000000..72172b23d4e5 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/generated/WidgetsGetWidgetOperationStatus.java @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.generated; + +import com.azure.contoso.widgetmanager.WidgetManagerClient; +import com.azure.contoso.widgetmanager.WidgetManagerClientBuilder; +import com.azure.contoso.widgetmanager.models.ResourceOperationStatusWidgetSuiteWidgetSuiteError; +import com.azure.core.util.Configuration; +import com.azure.identity.DefaultAzureCredentialBuilder; + +public class WidgetsGetWidgetOperationStatus { + public static void main(String[] args) { + WidgetManagerClient widgetManagerClient + = new WidgetManagerClientBuilder().credential(new DefaultAzureCredentialBuilder().build()) + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT")) + .buildClient(); + // BEGIN:com.azure.contoso.widgetmanager.generated.widgetsgetwidgetoperationstatus.widgetsgetwidgetoperationstatus + ResourceOperationStatusWidgetSuiteWidgetSuiteError response + = widgetManagerClient.getWidgetOperationStatus("name1", "opreation id1"); + // END:com.azure.contoso.widgetmanager.generated.widgetsgetwidgetoperationstatus.widgetsgetwidgetoperationstatus + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/generated/WidgetsListWidgets.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/generated/WidgetsListWidgets.java new file mode 100644 index 000000000000..2860712239fc --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/samples/java/com/azure/contoso/widgetmanager/generated/WidgetsListWidgets.java @@ -0,0 +1,24 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.generated; + +import com.azure.contoso.widgetmanager.WidgetManagerClient; +import com.azure.contoso.widgetmanager.WidgetManagerClientBuilder; +import com.azure.contoso.widgetmanager.models.WidgetSuite; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.util.Configuration; +import com.azure.identity.DefaultAzureCredentialBuilder; + +public class WidgetsListWidgets { + public static void main(String[] args) { + WidgetManagerClient widgetManagerClient + = new WidgetManagerClientBuilder().credential(new DefaultAzureCredentialBuilder().build()) + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT")) + .buildClient(); + // BEGIN:com.azure.contoso.widgetmanager.generated.widgetslistwidgets.widgetslistwidgets + PagedIterable response = widgetManagerClient.listWidgets(); + // END:com.azure.contoso.widgetmanager.generated.widgetslistwidgets.widgetslistwidgets + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/DeleteWidgetByWidgetNameUsingLongRunningOperationTests.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/DeleteWidgetByWidgetNameUsingLongRunningOperationTests.java new file mode 100644 index 000000000000..1285c0c414fe --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/DeleteWidgetByWidgetNameUsingLongRunningOperationTests.java @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.generated; + +import com.azure.core.util.polling.LongRunningOperationStatus; +import com.azure.core.util.polling.PollOperationDetails; +import com.azure.core.util.polling.SyncPoller; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +@Disabled +public final class DeleteWidgetByWidgetNameUsingLongRunningOperationTests extends WidgetManagerClientTestBase { + @Test + @Disabled + public void testDeleteWidgetByWidgetNameUsingLongRunningOperationTests() { + // method invocation + SyncPoller response + = setPlaybackSyncPollerPollInterval(widgetManagerClient.beginDeleteWidget("searchbox")); + + // response assertion + Assertions.assertEquals(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED, + response.waitForCompletion().getStatus()); + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/GetWidgetByWidgetNameTests.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/GetWidgetByWidgetNameTests.java new file mode 100644 index 000000000000..4945b3e2ccb8 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/GetWidgetByWidgetNameTests.java @@ -0,0 +1,27 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.generated; + +import com.azure.contoso.widgetmanager.models.WidgetSuite; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +@Disabled +public final class GetWidgetByWidgetNameTests extends WidgetManagerClientTestBase { + @Test + @Disabled + public void testGetWidgetByWidgetNameTests() { + // method invocation + WidgetSuite response = widgetManagerClient.getWidget("searchbox"); + + // response assertion + Assertions.assertNotNull(response); + // verify property "name" + Assertions.assertEquals("bingsearch", response.getName()); + // verify property "manufacturerId" + Assertions.assertEquals("a-22-01", response.getManufacturerId()); + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/WidgetManagerClientTestBase.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/WidgetManagerClientTestBase.java new file mode 100644 index 000000000000..e0e947b19862 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/WidgetManagerClientTestBase.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 com.azure.contoso.widgetmanager.generated; + +// The Java test files under 'generated' package are generated for your reference. +// If you wish to modify these files, please copy them out of the 'generated' package, and modify there. +// See https://aka.ms/azsdk/dpg/java/tests for guide on adding a test. + +import com.azure.contoso.widgetmanager.WidgetManagerClient; +import com.azure.contoso.widgetmanager.WidgetManagerClientBuilder; +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.test.utils.MockTokenCredential; +import com.azure.core.util.Configuration; +import com.azure.identity.DefaultAzureCredentialBuilder; + +class WidgetManagerClientTestBase extends TestProxyTestBase { + protected WidgetManagerClient widgetManagerClient; + + @Override + protected void beforeTest() { + WidgetManagerClientBuilder widgetManagerClientbuilder = new WidgetManagerClientBuilder() + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "endpoint")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.PLAYBACK) { + widgetManagerClientbuilder.credential(new MockTokenCredential()); + } else if (getTestMode() == TestMode.RECORD) { + widgetManagerClientbuilder.addPolicy(interceptorManager.getRecordPolicy()) + .credential(new DefaultAzureCredentialBuilder().build()); + } else if (getTestMode() == TestMode.LIVE) { + widgetManagerClientbuilder.credential(new DefaultAzureCredentialBuilder().build()); + } + widgetManagerClient = widgetManagerClientbuilder.buildClient(); + + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/WidgetsCreateOrUpdateWidgetTests.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/WidgetsCreateOrUpdateWidgetTests.java new file mode 100644 index 000000000000..169e0df3a467 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/WidgetsCreateOrUpdateWidgetTests.java @@ -0,0 +1,33 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.generated; + +import com.azure.contoso.widgetmanager.models.FakedSharedModel; +import com.azure.contoso.widgetmanager.models.WidgetSuite; +import com.azure.core.util.polling.LongRunningOperationStatus; +import com.azure.core.util.polling.PollOperationDetails; +import com.azure.core.util.polling.SyncPoller; +import java.time.OffsetDateTime; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +@Disabled +public final class WidgetsCreateOrUpdateWidgetTests extends WidgetManagerClientTestBase { + @Test + @Disabled + public void testWidgetsCreateOrUpdateWidgetTests() { + // method invocation + SyncPoller response + = setPlaybackSyncPollerPollInterval(widgetManagerClient.beginCreateOrUpdateWidget("name1", + new WidgetSuite().setManufacturerId("manufacturer id1") + .setSharedModel(new FakedSharedModel().setTag("tag1") + .setCreatedAt(OffsetDateTime.parse("2023-01-09T02:12:25.689Z"))))); + + // response assertion + Assertions.assertEquals(LongRunningOperationStatus.SUCCESSFULLY_COMPLETED, + response.waitForCompletion().getStatus()); + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/WidgetsGetWidgetOperationStatusTests.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/WidgetsGetWidgetOperationStatusTests.java new file mode 100644 index 000000000000..98ab9b014728 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/WidgetsGetWidgetOperationStatusTests.java @@ -0,0 +1,42 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.generated; + +import com.azure.contoso.widgetmanager.models.FakedSharedModel; +import com.azure.contoso.widgetmanager.models.OperationState; +import com.azure.contoso.widgetmanager.models.ResourceOperationStatusWidgetSuiteWidgetSuiteError; +import com.azure.contoso.widgetmanager.models.WidgetSuite; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +@Disabled +public final class WidgetsGetWidgetOperationStatusTests extends WidgetManagerClientTestBase { + @Test + @Disabled + public void testWidgetsGetWidgetOperationStatusTests() { + // method invocation + ResourceOperationStatusWidgetSuiteWidgetSuiteError response + = widgetManagerClient.getWidgetOperationStatus("name1", "opreation id1"); + + // response assertion + Assertions.assertNotNull(response); + // verify property "id" + Assertions.assertEquals("opreation id1", response.getId()); + // verify property "status" + Assertions.assertEquals(OperationState.fromString("InProgress"), response.getStatus()); + // verify property "error" + Assertions.assertNotNull(response.getError()); + // verify property "result" + WidgetSuite responseResult = response.getResult(); + Assertions.assertNotNull(responseResult); + Assertions.assertEquals("bingsearch", responseResult.getName()); + Assertions.assertEquals("manufacturer Id1", responseResult.getManufacturerId()); + FakedSharedModel responseResultSharedModel = responseResult.getSharedModel(); + Assertions.assertNotNull(responseResultSharedModel); + Assertions.assertEquals("tag1", responseResultSharedModel.getTag()); + Assertions.assertNotNull(responseResultSharedModel.getCreatedAt()); + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/WidgetsListWidgetsTests.java b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/WidgetsListWidgetsTests.java new file mode 100644 index 000000000000..f67ff3bda66b --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/src/test/java/com/azure/contoso/widgetmanager/generated/WidgetsListWidgetsTests.java @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package com.azure.contoso.widgetmanager.generated; + +import com.azure.contoso.widgetmanager.models.FakedSharedModel; +import com.azure.contoso.widgetmanager.models.WidgetSuite; +import com.azure.core.http.rest.PagedIterable; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; + +@Disabled +public final class WidgetsListWidgetsTests extends WidgetManagerClientTestBase { + @Test + @Disabled + public void testWidgetsListWidgetsTests() { + // method invocation + PagedIterable response = widgetManagerClient.listWidgets(); + + // response assertion + Assertions.assertEquals(200, response.iterableByPage().iterator().next().getStatusCode()); + WidgetSuite firstItem = response.iterator().next(); + Assertions.assertNotNull(firstItem); + // verify property "name" + Assertions.assertEquals("bingsearch", firstItem.getName()); + // verify property "manufacturerId" + Assertions.assertEquals("manufacturer Id1", firstItem.getManufacturerId()); + // verify property "sharedModel" + FakedSharedModel firstItemSharedModel = firstItem.getSharedModel(); + Assertions.assertNotNull(firstItemSharedModel); + Assertions.assertEquals("tag1", firstItemSharedModel.getTag()); + Assertions.assertNotNull(firstItemSharedModel.getCreatedAt()); + } +} diff --git a/sdk/contosowidgetmanager/azure-contoso-widgetmanager/tsp-location.yaml b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/tsp-location.yaml new file mode 100644 index 000000000000..c14d43b4f6a8 --- /dev/null +++ b/sdk/contosowidgetmanager/azure-contoso-widgetmanager/tsp-location.yaml @@ -0,0 +1,5 @@ +directory: specification/contosowidgetmanager/Contoso.WidgetManager +commit: cd79adfdffe8d52c895afeec7aaf0b4a0bbac747 +repo: Azure/azure-rest-api-specs +additionalDirectories: +- specification/contosowidgetmanager/Contoso.WidgetManager.Shared diff --git a/sdk/contosowidgetmanager/ci.yml b/sdk/contosowidgetmanager/ci.yml new file mode 100644 index 000000000000..169dcc554e3d --- /dev/null +++ b/sdk/contosowidgetmanager/ci.yml @@ -0,0 +1,46 @@ +# NOTE: Please refer to https://aka.ms/azsdk/engsys/ci-yaml before editing this file. + +trigger: + branches: + include: + - main + - hotfix/* + - release/* + paths: + include: + - sdk/contosowidgetmanager/ci.yml + - sdk/contosowidgetmanager/azure-contoso-widgetmanager/ + exclude: + - sdk/contosowidgetmanager/pom.xml + - sdk/contosowidgetmanager/azure-contoso-widgetmanager/pom.xml + +pr: + branches: + include: + - main + - feature/* + - hotfix/* + - release/* + paths: + include: + - sdk/contosowidgetmanager/ci.yml + - sdk/contosowidgetmanager/azure-contoso-widgetmanager/ + exclude: + - sdk/contosowidgetmanager/pom.xml + - sdk/contosowidgetmanager/azure-contoso-widgetmanager/pom.xml + +parameters: + - name: release_azurecontosowidgetmanager + displayName: azure-contoso-widgetmanager + type: boolean + default: true + +extends: + template: ../../eng/pipelines/templates/stages/archetype-sdk-client.yml + parameters: + ServiceDirectory: contosowidgetmanager + Artifacts: + - name: azure-contoso-widgetmanager + groupId: com.azure + safeName: azurecontosowidgetmanager + releaseInBatch: ${{ parameters.release_azurecontosowidgetmanager }} diff --git a/sdk/contosowidgetmanager/pom.xml b/sdk/contosowidgetmanager/pom.xml new file mode 100644 index 000000000000..6d6c6b2185fd --- /dev/null +++ b/sdk/contosowidgetmanager/pom.xml @@ -0,0 +1,15 @@ + + + 4.0.0 + com.azure + azure-contosowidgetmanager-service + pom + 1.0.0 + + + azure-contoso-widgetmanager + +