diff --git a/core b/core index 6c96b66348..1e3aa033c5 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 6c96b6634864a63ba46639314f6414614884e03f +Subproject commit 1e3aa033c5e3bf783025d010ab7e841b2b7c27c9 diff --git a/eng/pipelines/post-publish-sdk.yaml b/eng/pipelines/post-publish-sdk.yaml index fff2ca3770..5dbf71a92c 100644 --- a/eng/pipelines/post-publish-sdk.yaml +++ b/eng/pipelines/post-publish-sdk.yaml @@ -22,7 +22,7 @@ resources: jobs: - job: Generate_SDK - timeoutInMinutes: 60 + timeoutInMinutes: 120 variables: - template: /eng/pipelines/variables/globals.yml diff --git a/eng/sdk/sync_sdk.py b/eng/sdk/sync_sdk.py index 7346e11598..7030f0cae7 100644 --- a/eng/sdk/sync_sdk.py +++ b/eng/sdk/sync_sdk.py @@ -20,8 +20,6 @@ skip_artifacts: List[str] = [ "azure-ai-anomalydetector", # deprecated # expect failure on below - "azure-ai-projects", # wait for service dev update tsp-location.yaml - "azure-ai-agents-persistent", # tspconfig does not have java # "azure-developer-devcenter", # 2 breaks introduced into stable api-version # "azure-ai-vision-face", # SDK in development ] diff --git a/typespec-extension/changelog.md b/typespec-extension/changelog.md index e36789d730..ef411a6ca7 100644 --- a/typespec-extension/changelog.md +++ b/typespec-extension/changelog.md @@ -1,5 +1,11 @@ # Release History +## 0.38.4 (2026-01-19) + +Compatible with compiler 1.8.0. + +- Updated package dependencies to the latest versions. + ## 0.38.3 (2026-01-15) Compatible with compiler 1.8.0. diff --git a/typespec-extension/package-lock.json b/typespec-extension/package-lock.json index 4598ef2bab..39d0c9bb53 100644 --- a/typespec-extension/package-lock.json +++ b/typespec-extension/package-lock.json @@ -1,12 +1,12 @@ { "name": "@azure-tools/typespec-java", - "version": "0.38.3", + "version": "0.38.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@azure-tools/typespec-java", - "version": "0.38.3", + "version": "0.38.4", "license": "MIT", "dependencies": { "@autorest/codemodel": "~4.20.1", @@ -14,6 +14,7 @@ "lodash": "~4.17.21" }, "devDependencies": { + "@azure-tools/openai-typespec": "^1.6.2", "@azure-tools/typespec-autorest": "0.64.0", "@azure-tools/typespec-azure-core": "0.64.0", "@azure-tools/typespec-azure-resource-manager": "0.64.0", @@ -23,7 +24,7 @@ "@microsoft/api-extractor": "^7.55.2", "@types/js-yaml": "~4.0.9", "@types/lodash": "~4.17.23", - "@types/node": "~25.0.8", + "@types/node": "~25.0.9", "@typescript-eslint/eslint-plugin": "~8.53.0", "@typescript-eslint/parser": "~8.53.0", "@typespec/compiler": "1.8.0", @@ -53,6 +54,7 @@ "node": ">=20.0.0" }, "peerDependencies": { + "@azure-tools/openai-typespec": "^1.6.1", "@azure-tools/typespec-autorest": ">=0.64.0 <1.0.0", "@azure-tools/typespec-azure-core": ">=0.64.0 <1.0.0", "@azure-tools/typespec-azure-resource-manager": ">=0.64.0 <1.0.0", @@ -144,6 +146,17 @@ "node": ">=12.0.0" } }, + "node_modules/@azure-tools/openai-typespec": { + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/@azure-tools/openai-typespec/-/openai-typespec-1.6.2.tgz", + "integrity": "sha512-u2Y8ZS6OMO9lUbSyYgBiDuGQkF/ccv9qk6ipvDwu+vZmxRx2c9Zp2VOcC6dxWNOT62DWjlfmbJQy7E/fNaQVrw==", + "dev": true, + "license": "MIT", + "peerDependencies": { + "@typespec/http": "*", + "@typespec/openapi": "*" + } + }, "node_modules/@azure-tools/tasks": { "version": "3.0.255", "resolved": "https://registry.npmjs.org/@azure-tools/tasks/-/tasks-3.0.255.tgz", @@ -185,6 +198,7 @@ "integrity": "sha512-BXiHc5oayhMsG1dHFU1aFK/ZQX2Gl0dKB0FAFceapaFV9093J2obbsdhIDR3Tl0qei9g3Ha+iWKZ4KgnLdhv4w==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=20.0.0" }, @@ -200,6 +214,7 @@ "integrity": "sha512-1HwGo3Nt8ksafoPp1rFOopSzgh68SFsyVNCauzjO8ftf0fEqhRXo70OaGwP6wmTZJsLnW7u1DbrBNu6b0z2sOQ==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "change-case": "~5.4.4", "pluralize": "^8.0.0" @@ -238,6 +253,7 @@ "integrity": "sha512-u1iWLergQmNG/0Wk3wVjCj/Q9cxUlxLGnLhd0hr3H1Wy1xvg7mLRaH+a62J//wvUZYBQsz1XGnm2QnksAzAdzg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "change-case": "~5.4.4", "pluralize": "^8.0.0", @@ -2462,11 +2478,12 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "25.0.8", - "resolved": "https://registry.npmjs.org/@types/node/-/node-25.0.8.tgz", - "integrity": "sha512-powIePYMmC3ibL0UJ2i2s0WIbq6cg6UyVFQxSCpaPxxzAaziRfimGivjdF943sSGV6RADVbk0Nvlm5P/FB44Zg==", + "version": "25.0.9", + "resolved": "https://registry.npmjs.org/@types/node/-/node-25.0.9.tgz", + "integrity": "sha512-/rpCXHlCWeqClNBwUhDcusJxXYDjZTyE8v5oTO7WbL8eij2nKhUeU89/6xgjU7N4/Vh3He0BtyhJdQbDyhiXAw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "undici-types": "~7.16.0" } @@ -2536,6 +2553,7 @@ "integrity": "sha512-npiaib8XzbjtzS2N4HlqPvlpxpmZ14FjSJrteZpPxGUaYPlvhzlzUZ4mZyABo0EFrOWnvyd0Xxroq//hKhtAWg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@typescript-eslint/scope-manager": "8.53.0", "@typescript-eslint/types": "8.53.0", @@ -2766,6 +2784,7 @@ "integrity": "sha512-FeLb7Q0z6Bh5dDpqtnU2RlWiIWWWF7rujx2xGMta5dcTuIOZ4jbdyz1hVdxk4iM4qadvaSV4ey/qrSuffNoh3w==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@babel/code-frame": "~7.27.1", "@inquirer/prompts": "^8.0.1", @@ -2987,6 +3006,7 @@ "integrity": "sha512-gSI4rAexxfYyZX0ZqYNRWQyuMb1UeakjAjOeh/2ntmxWCdYc+wSbJjxrxIArsZC+LwzTxq5WpdtD7+7OWzG4yw==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=20.0.0" }, @@ -3000,6 +3020,7 @@ "integrity": "sha512-ZKa4RISabwL8cUAmE3BkoNmtCYRjerO0+1Ba6XdDJKG+vJC5EGM2hkDf+ZmYsYZgrX0cvbhPXUKKh28zBV60hw==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=20.0.0" }, @@ -3019,6 +3040,7 @@ "integrity": "sha512-v+RIJpx7vALBSGQmnUWemvXjnrk50HAVqJeg0RbaF3VUnh66Z4itsoNJJmIIc+HmBJng8Ie0V7xv3l02ek6HWA==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=20.0.0" }, @@ -3033,6 +3055,7 @@ "integrity": "sha512-1clnDw1JbBvjLcfFvEvHdIrnsQuQI5/Cl6mRIrzWWX0pKJ+R89rCdZD1KpidEXw4B4qscD48LsssyrEIFLtuPg==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=20.0.0" }, @@ -3047,6 +3070,7 @@ "integrity": "sha512-jPARl+e1e/nsDW/1uVsGTzvKmjqezVMyUa13igXxk5nV2ScMdFpH1HhBwTmAhUeaZgY3J81dFHNUnIY67HCrmw==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=20.0.0" }, @@ -3063,6 +3087,7 @@ "integrity": "sha512-wzh5bVdzh+K+pFQFs/EZkVsTH5TQGi12XwhjxJS0UKRwaW2UwSZeY1HqX07oMMPdYESTbjgMrXcxtn89AlzjvQ==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=20.0.0" }, @@ -3249,6 +3274,7 @@ "integrity": "sha512-I14X6+IMd0wFMNI8oMFSeFBi2nD4idub+geSO34vuCs4rwuEj3FNzy+rkNkDDvf0+gIUGxeyg7s+YDUcNyiqOA==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=20.0.0" }, @@ -3262,6 +3288,7 @@ "integrity": "sha512-KSDhJX6A/Onsu9FKVZtR/xSy5va3k0y9/U4eiZUn91V/LQyMZNwmResPDHEVYk6JqaIH8bbd6ANWPu3nMd7mmw==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=20.0.0" }, @@ -3403,6 +3430,7 @@ "integrity": "sha512-hRDjg6dlDz7JlZAvjbiCdAJ3SDG+NH8tjZe21vjxfvT2ssYAn72SRXMge3dKKABm3bIJ3C+3wdunIdur8PHEAw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@vitest/utils": "4.0.17", "fflate": "^0.8.2", @@ -3456,6 +3484,7 @@ "integrity": "sha512-NZyJarBfL7nWwIq+FDL6Zp/yHEhePMNnnJ0y3qfieCrmNvYct8uvtiV41UvlSe6apAfk0fY1FbWx+NwfmpvtTg==", "dev": true, "license": "MIT", + "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -3478,6 +3507,7 @@ "resolved": "https://registry.npmjs.org/ajv/-/ajv-8.17.1.tgz", "integrity": "sha512-B/gBuNg5SiMTrPkC+A2+cW0RszwxYmn6VYxB/inlBStS5nx6xHIt/ehKRhIMhqusl7a8LjQoZnjCs5vhwxOQ1g==", "dev": true, + "peer": true, "dependencies": { "fast-deep-equal": "^3.1.3", "fast-uri": "^3.0.1", @@ -3793,6 +3823,7 @@ } ], "license": "MIT", + "peer": true, "dependencies": { "baseline-browser-mapping": "^2.8.19", "caniuse-lite": "^1.0.30001751", @@ -4228,9 +4259,9 @@ } }, "node_modules/diff": { - "version": "8.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-8.0.2.tgz", - "integrity": "sha512-sSuxWU5j5SR9QQji/o2qMvqRNYRDOcBTgsJ/DeCf4iSN4gW+gNMXM7wFIP+fdXZxoNiAnHUTGjCr+TSWXdRDKg==", + "version": "8.0.3", + "resolved": "https://registry.npmjs.org/diff/-/diff-8.0.3.tgz", + "integrity": "sha512-qejHi7bcSD4hQAZE0tNAawRK1ZtafHDmMTMkrrIGgSLl7hTnQHmKCeB45xAcbfTqK2zowkM3j3bHt/4b/ARbYQ==", "dev": true, "license": "BSD-3-Clause", "engines": { @@ -4545,6 +4576,7 @@ "integrity": "sha512-LEyamqS7W5HB3ujJyvi0HQK/dtVINZvd5mAAp9eT5S/ujByGjiZLCzPcHVzuXbpJDJF/cxwHlfceVUDZ2lnSTw==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.8.0", "@eslint-community/regexpp": "^4.12.1", @@ -7915,6 +7947,7 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -8083,6 +8116,7 @@ "integrity": "sha512-aw45vwtwOl3QkUAmWCnLV9QW1xY+FSX2zzlit4MAfE99wX+Jij4ycnpbAWgBXsRrxmfs9LaYktg/eX5Bpthd3g==", "dev": true, "license": "Apache-2.0", + "peer": true, "dependencies": { "@gerrit0/mini-shiki": "^3.9.0", "lunr": "^2.3.9", @@ -8120,6 +8154,7 @@ "integrity": "sha512-jl1vZzPDinLr9eUt3J/t7V6FgNEw9QjvBPdysz9KfQDD41fQrC2Y4vKQdiaUpFT4bXlb1RHhLpp8wtm6M5TgSw==", "dev": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -8268,6 +8303,7 @@ "integrity": "sha512-w+N7Hifpc3gRjZ63vYBXA56dvvRlNWRczTdmCBBa+CotUzAPf5b7YMdMR/8CQoeYE5LX3W4wj6RYTgonm1b9DA==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "esbuild": "^0.27.0", "fdir": "^6.5.0", @@ -8361,6 +8397,7 @@ "integrity": "sha512-5gTmgEY/sqK6gFXLIsQNH19lWb4ebPDLA4SdLP7dsWkIXHWlG66oPuVvXSGFPppYZz8ZDZq0dYYrbHfBCVUb1Q==", "dev": true, "license": "MIT", + "peer": true, "engines": { "node": ">=12" }, @@ -8374,6 +8411,7 @@ "integrity": "sha512-FQMeF0DJdWY0iOnbv466n/0BudNdKj1l5jYgl5JVTwjSsZSlqyXFt/9+1sEyhR6CLowbZpV7O1sCHrzBhucKKg==", "dev": true, "license": "MIT", + "peer": true, "dependencies": { "@vitest/expect": "4.0.17", "@vitest/mocker": "4.0.17", diff --git a/typespec-extension/package.json b/typespec-extension/package.json index 71e944158b..5c6a0f2943 100644 --- a/typespec-extension/package.json +++ b/typespec-extension/package.json @@ -1,6 +1,6 @@ { "name": "@azure-tools/typespec-java", - "version": "0.38.3", + "version": "0.38.4", "description": "TypeSpec library for emitting Java client from the TypeSpec REST protocol binding", "keywords": [ "TypeSpec" @@ -53,6 +53,7 @@ "@azure-tools/typespec-azure-rulesets": ">=0.64.0 <1.0.0", "@azure-tools/typespec-client-generator-core": ">=0.64.1 <1.0.0", "@azure-tools/typespec-liftr-base": ">=0.11.0 <1.0.0", + "@azure-tools/openai-typespec": "^1.6.1", "@typespec/compiler": "^1.8.0", "@typespec/http": "^1.8.0", "@typespec/openapi": "^1.8.0", @@ -72,10 +73,11 @@ "@azure-tools/typespec-azure-rulesets": "0.64.0", "@azure-tools/typespec-client-generator-core": "0.64.1", "@azure-tools/typespec-liftr-base": "0.11.0", + "@azure-tools/openai-typespec": "^1.6.2", "@microsoft/api-extractor": "^7.55.2", "@types/js-yaml": "~4.0.9", "@types/lodash": "~4.17.23", - "@types/node": "~25.0.8", + "@types/node": "~25.0.9", "@typescript-eslint/eslint-plugin": "~8.53.0", "@typescript-eslint/parser": "~8.53.0", "@typespec/compiler": "1.8.0", diff --git a/typespec-tests/Generate.ps1 b/typespec-tests/Generate.ps1 index f056594536..1049a9e38a 100644 --- a/typespec-tests/Generate.ps1 +++ b/typespec-tests/Generate.ps1 @@ -62,6 +62,10 @@ $generateScript = { } elseif ($tspFile -match "azure[\\/]resource-manager[\\/].*[\\/]main\.tsp") { # for mgmt, do not generate tests due to random mock values $tspOptions += " --option ""@azure-tools/typespec-java.generate-tests=false""" + } elseif ($tspFile -match "azure[\\/]resource-manager[\\/]multi-service-older-versions[\\/]") { + $tspOptions += " --option ""@azure-tools/typespec-java.metadata-suffix=older-versions""" + } elseif ($tspFile -match "azure[\\/]resource-manager[\\/]multi-service-shared-models[\\/]") { + $tspOptions += " --option ""@azure-tools/typespec-java.metadata-suffix=shared-models""" } elseif ($tspFile -match "tsp[\\/]versioning.tsp") { # test generating from specific api-version $tspOptions += " --option ""@azure-tools/typespec-java.api-version=2022-09-01""" @@ -194,11 +198,10 @@ try { Remove-Item ./specs/payload/xml -Recurse -Force $specFiles = Get-ChildItem ./specs -Include "main.tsp","old.tsp" -File -Recurse - $multiServiceSpec = Join-Path ./specs "azure/resource-manager/multi-service/client.tsp" - if (Test-Path $multiServiceSpec) { - # ensure multi-service client specs are processed even though they do not match the default filter - $specFiles += Get-Item $multiServiceSpec - } + # ensure multi-service client specs are processed even though they do not match the default filter + $specFiles += Get-Item (Join-Path ./specs "azure/resource-manager/multi-service/client.tsp") + $specFiles += Get-Item (Join-Path ./specs "azure/resource-manager/multi-service-older-versions/client.tsp") + $specFiles += Get-Item (Join-Path ./specs "azure/resource-manager/multi-service-shared-models/client.tsp") $job = $specFiles | ForEach-Object -Parallel $generateScript -ThrottleLimit $Parallelization -AsJob diff --git a/typespec-tests/package.json b/typespec-tests/package.json index f9b350dcef..1b98451c00 100644 --- a/typespec-tests/package.json +++ b/typespec-tests/package.json @@ -13,7 +13,7 @@ "@typespec/spector": "0.1.0-alpha.22", "@typespec/http-specs": "0.1.0-alpha.31", "@azure-tools/azure-http-specs": "0.1.0-alpha.36", - "@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.38.3.tgz" + "@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.38.4.tgz" }, "devDependencies": { "@typespec/prettier-plugin-typespec": "^1.8.0", diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/CombinedManager.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/CombinedManager.java new file mode 100644 index 0000000000..d24968bd14 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/CombinedManager.java @@ -0,0 +1,298 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined; + +import azure.resourcemanager.multiserviceolderversions.combined.fluent.Combined; +import azure.resourcemanager.multiserviceolderversions.combined.implementation.CombinedBuilder; +import azure.resourcemanager.multiserviceolderversions.combined.implementation.DisksImpl; +import azure.resourcemanager.multiserviceolderversions.combined.implementation.VirtualMachinesImpl; +import azure.resourcemanager.multiserviceolderversions.combined.models.Disks; +import azure.resourcemanager.multiserviceolderversions.combined.models.VirtualMachines; +import com.azure.core.credential.TokenCredential; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; +import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.management.profile.AzureProfile; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.logging.ClientLogger; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * Entry point to CombinedManager. + * Compute Client. + */ +public final class CombinedManager { + private VirtualMachines virtualMachines; + + private Disks disks; + + private final Combined clientObject; + + private CombinedManager(HttpPipeline httpPipeline, AzureProfile profile, Duration defaultPollInterval) { + Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + this.clientObject = new CombinedBuilder().pipeline(httpPipeline) + .endpoint(profile.getEnvironment().getResourceManagerEndpoint()) + .subscriptionId(profile.getSubscriptionId()) + .defaultPollInterval(defaultPollInterval) + .buildClient(); + } + + /** + * Creates an instance of combined service API entry point. + * + * @param credential the credential to use. + * @param profile the Azure profile for client. + * @return the combined service API instance. + */ + public static CombinedManager authenticate(TokenCredential credential, AzureProfile profile) { + Objects.requireNonNull(credential, "'credential' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + return configure().authenticate(credential, profile); + } + + /** + * Creates an instance of combined service API entry point. + * + * @param httpPipeline the {@link HttpPipeline} configured with Azure authentication credential. + * @param profile the Azure profile for client. + * @return the combined service API instance. + */ + public static CombinedManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) { + Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + return new CombinedManager(httpPipeline, profile, null); + } + + /** + * Gets a Configurable instance that can be used to create CombinedManager with optional configuration. + * + * @return the Configurable instance allowing configurations. + */ + public static Configurable configure() { + return new CombinedManager.Configurable(); + } + + /** + * The Configurable allowing configurations to be set. + */ + public static final class Configurable { + private static final ClientLogger LOGGER = new ClientLogger(Configurable.class); + private static final String SDK_VERSION = "version"; + private static final Map PROPERTIES + = CoreUtils.getProperties("azure-resourcemanager-combined-generated.properties"); + + private HttpClient httpClient; + private HttpLogOptions httpLogOptions; + private final List policies = new ArrayList<>(); + private final List scopes = new ArrayList<>(); + private RetryPolicy retryPolicy; + private RetryOptions retryOptions; + private Duration defaultPollInterval; + + private Configurable() { + } + + /** + * Sets the http client. + * + * @param httpClient the HTTP client. + * @return the configurable object itself. + */ + public Configurable withHttpClient(HttpClient httpClient) { + this.httpClient = Objects.requireNonNull(httpClient, "'httpClient' cannot be null."); + return this; + } + + /** + * Sets the logging options to the HTTP pipeline. + * + * @param httpLogOptions the HTTP log options. + * @return the configurable object itself. + */ + public Configurable withLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = Objects.requireNonNull(httpLogOptions, "'httpLogOptions' cannot be null."); + return this; + } + + /** + * Adds the pipeline policy to the HTTP pipeline. + * + * @param policy the HTTP pipeline policy. + * @return the configurable object itself. + */ + public Configurable withPolicy(HttpPipelinePolicy policy) { + this.policies.add(Objects.requireNonNull(policy, "'policy' cannot be null.")); + return this; + } + + /** + * Adds the scope to permission sets. + * + * @param scope the scope. + * @return the configurable object itself. + */ + public Configurable withScope(String scope) { + this.scopes.add(Objects.requireNonNull(scope, "'scope' cannot be null.")); + return this; + } + + /** + * Sets the retry policy to the HTTP pipeline. + * + * @param retryPolicy the HTTP pipeline retry policy. + * @return the configurable object itself. + */ + public Configurable withRetryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = Objects.requireNonNull(retryPolicy, "'retryPolicy' cannot be null."); + return this; + } + + /** + * Sets the retry options for the HTTP pipeline retry policy. + *

+ * This setting has no effect, if retry policy is set via {@link #withRetryPolicy(RetryPolicy)}. + * + * @param retryOptions the retry options for the HTTP pipeline retry policy. + * @return the configurable object itself. + */ + public Configurable withRetryOptions(RetryOptions retryOptions) { + this.retryOptions = Objects.requireNonNull(retryOptions, "'retryOptions' cannot be null."); + return this; + } + + /** + * Sets the default poll interval, used when service does not provide "Retry-After" header. + * + * @param defaultPollInterval the default poll interval. + * @return the configurable object itself. + */ + public Configurable withDefaultPollInterval(Duration defaultPollInterval) { + this.defaultPollInterval + = Objects.requireNonNull(defaultPollInterval, "'defaultPollInterval' cannot be null."); + if (this.defaultPollInterval.isNegative()) { + throw LOGGER + .logExceptionAsError(new IllegalArgumentException("'defaultPollInterval' cannot be negative")); + } + return this; + } + + /** + * Creates an instance of combined service API entry point. + * + * @param credential the credential to use. + * @param profile the Azure profile for client. + * @return the combined service API instance. + */ + public CombinedManager authenticate(TokenCredential credential, AzureProfile profile) { + Objects.requireNonNull(credential, "'credential' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + + String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); + + StringBuilder userAgentBuilder = new StringBuilder(); + userAgentBuilder.append("azsdk-java") + .append("-") + .append("azure.resourcemanager.multiserviceolderversions.combined") + .append("/") + .append(clientVersion); + if (!Configuration.getGlobalConfiguration().get("AZURE_TELEMETRY_DISABLED", false)) { + userAgentBuilder.append(" (") + .append(Configuration.getGlobalConfiguration().get("java.version")) + .append("; ") + .append(Configuration.getGlobalConfiguration().get("os.name")) + .append("; ") + .append(Configuration.getGlobalConfiguration().get("os.version")) + .append("; auto-generated)"); + } else { + userAgentBuilder.append(" (auto-generated)"); + } + + if (scopes.isEmpty()) { + scopes.add(profile.getEnvironment().getManagementEndpoint() + "/.default"); + } + if (retryPolicy == null) { + if (retryOptions != null) { + retryPolicy = new RetryPolicy(retryOptions); + } else { + retryPolicy = new RetryPolicy("Retry-After", ChronoUnit.SECONDS); + } + } + List policies = new ArrayList<>(); + policies.add(new UserAgentPolicy(userAgentBuilder.toString())); + policies.add(new AddHeadersFromContextPolicy()); + policies.add(new RequestIdPolicy()); + policies.addAll(this.policies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .collect(Collectors.toList())); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(retryPolicy); + policies.add(new AddDatePolicy()); + policies.add(new BearerTokenAuthenticationPolicy(credential, scopes.toArray(new String[0]))); + policies.addAll(this.policies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .collect(Collectors.toList())); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(httpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(httpClient) + .policies(policies.toArray(new HttpPipelinePolicy[0])) + .build(); + return new CombinedManager(httpPipeline, profile, defaultPollInterval); + } + } + + /** + * Gets the resource collection API of VirtualMachines. It manages VirtualMachine. + * + * @return Resource collection API of VirtualMachines. + */ + public VirtualMachines virtualMachines() { + if (this.virtualMachines == null) { + this.virtualMachines = new VirtualMachinesImpl(clientObject.getVirtualMachines(), this); + } + return virtualMachines; + } + + /** + * Gets the resource collection API of Disks. It manages Disk. + * + * @return Resource collection API of Disks. + */ + public Disks disks() { + if (this.disks == null) { + this.disks = new DisksImpl(clientObject.getDisks(), this); + } + return disks; + } + + /** + * Gets wrapped service client Combined providing direct access to the underlying auto-generated API implementation, + * based on Azure REST API. + * + * @return Wrapped service client Combined. + */ + public Combined serviceClient() { + return this.clientObject; + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/Combined.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/Combined.java new file mode 100644 index 0000000000..c14cf89263 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/Combined.java @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.fluent; + +import com.azure.core.http.HttpPipeline; +import java.time.Duration; + +/** + * The interface for Combined class. + */ +public interface Combined { + /** + * Gets Service host. + * + * @return the endpoint value. + */ + String getEndpoint(); + + /** + * Gets The ID of the target subscription. The value must be an UUID. + * + * @return the subscriptionId value. + */ + String getSubscriptionId(); + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + HttpPipeline getHttpPipeline(); + + /** + * Gets The default poll interval for long-running operation. + * + * @return the defaultPollInterval value. + */ + Duration getDefaultPollInterval(); + + /** + * Gets the VirtualMachinesClient object to access its operations. + * + * @return the VirtualMachinesClient object. + */ + VirtualMachinesClient getVirtualMachines(); + + /** + * Gets the DisksClient object to access its operations. + * + * @return the DisksClient object. + */ + DisksClient getDisks(); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/DisksClient.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/DisksClient.java new file mode 100644 index 0000000000..53d3f79daf --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/DisksClient.java @@ -0,0 +1,105 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.fluent; + +import azure.resourcemanager.multiserviceolderversions.combined.fluent.models.DiskInner; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.http.rest.Response; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.Context; +import com.azure.core.util.polling.SyncPoller; + +/** + * An instance of this class provides access to all the operations defined in DisksClient. + */ +public interface DisksClient { + /** + * Gets information about a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a disk along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response getByResourceGroupWithResponse(String resourceGroupName, String diskName, Context context); + + /** + * Gets information about a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a disk. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + DiskInner getByResourceGroup(String resourceGroupName, String diskName); + + /** + * Creates or updates a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of disk resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, DiskInner> beginCreateOrUpdate(String resourceGroupName, String diskName, + DiskInner resource); + + /** + * Creates or updates a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of disk resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, DiskInner> beginCreateOrUpdate(String resourceGroupName, String diskName, + DiskInner resource, Context context); + + /** + * Creates or updates a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return disk resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + DiskInner createOrUpdate(String resourceGroupName, String diskName, DiskInner resource); + + /** + * Creates or updates a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return disk resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + DiskInner createOrUpdate(String resourceGroupName, String diskName, DiskInner resource, Context context); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/VirtualMachinesClient.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/VirtualMachinesClient.java new file mode 100644 index 0000000000..ae8ed67197 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/VirtualMachinesClient.java @@ -0,0 +1,111 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.fluent; + +import azure.resourcemanager.multiserviceolderversions.combined.fluent.models.VirtualMachineInner; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.http.rest.Response; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.Context; +import com.azure.core.util.polling.SyncPoller; + +/** + * An instance of this class provides access to all the operations defined in VirtualMachinesClient. + */ +public interface VirtualMachinesClient { + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response getByResourceGroupWithResponse(String resourceGroupName, String vmName, + Context context); + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + VirtualMachineInner getByResourceGroup(String resourceGroupName, String vmName); + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, VirtualMachineInner> beginCreateOrUpdate(String resourceGroupName, + String vmName, VirtualMachineInner resource); + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, VirtualMachineInner> beginCreateOrUpdate(String resourceGroupName, + String vmName, VirtualMachineInner resource, Context context); + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + VirtualMachineInner createOrUpdate(String resourceGroupName, String vmName, VirtualMachineInner resource); + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + VirtualMachineInner createOrUpdate(String resourceGroupName, String vmName, VirtualMachineInner resource, + Context context); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/models/DiskInner.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/models/DiskInner.java new file mode 100644 index 0000000000..920c05c5c2 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/models/DiskInner.java @@ -0,0 +1,181 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.fluent.models; + +import azure.resourcemanager.multiserviceolderversions.combined.models.DiskProperties; +import com.azure.core.annotation.Fluent; +import com.azure.core.management.Resource; +import com.azure.core.management.SystemData; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.Map; + +/** + * Disk resource. + */ +@Fluent +public final class DiskInner extends Resource { + /* + * The resource-specific properties for this resource. + */ + private DiskProperties properties; + + /* + * Azure Resource Manager metadata containing createdBy and modifiedBy information. + */ + private SystemData systemData; + + /* + * The type of the resource. + */ + private String type; + + /* + * The name of the resource. + */ + private String name; + + /* + * Fully qualified resource Id for the resource. + */ + private String id; + + /** + * Creates an instance of DiskInner class. + */ + public DiskInner() { + } + + /** + * Get the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + public DiskProperties properties() { + return this.properties; + } + + /** + * Set the properties property: The resource-specific properties for this resource. + * + * @param properties the properties value to set. + * @return the DiskInner object itself. + */ + public DiskInner withProperties(DiskProperties properties) { + this.properties = properties; + return this; + } + + /** + * Get the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + public SystemData systemData() { + return this.systemData; + } + + /** + * Get the type property: The type of the resource. + * + * @return the type value. + */ + @Override + public String type() { + return this.type; + } + + /** + * Get the name property: The name of the resource. + * + * @return the name value. + */ + @Override + public String name() { + return this.name; + } + + /** + * Get the id property: Fully qualified resource Id for the resource. + * + * @return the id value. + */ + @Override + public String id() { + return this.id; + } + + /** + * {@inheritDoc} + */ + @Override + public DiskInner withLocation(String location) { + super.withLocation(location); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public DiskInner withTags(Map tags) { + super.withTags(tags); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("location", location()); + jsonWriter.writeMapField("tags", tags(), (writer, element) -> writer.writeString(element)); + jsonWriter.writeJsonField("properties", this.properties); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of DiskInner from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of DiskInner 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 DiskInner. + */ + public static DiskInner fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + DiskInner deserializedDiskInner = new DiskInner(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedDiskInner.id = reader.getString(); + } else if ("name".equals(fieldName)) { + deserializedDiskInner.name = reader.getString(); + } else if ("type".equals(fieldName)) { + deserializedDiskInner.type = reader.getString(); + } else if ("location".equals(fieldName)) { + deserializedDiskInner.withLocation(reader.getString()); + } else if ("tags".equals(fieldName)) { + Map tags = reader.readMap(reader1 -> reader1.getString()); + deserializedDiskInner.withTags(tags); + } else if ("properties".equals(fieldName)) { + deserializedDiskInner.properties = DiskProperties.fromJson(reader); + } else if ("systemData".equals(fieldName)) { + deserializedDiskInner.systemData = SystemData.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedDiskInner; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/models/VirtualMachineInner.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/models/VirtualMachineInner.java new file mode 100644 index 0000000000..fbf8b1af82 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/models/VirtualMachineInner.java @@ -0,0 +1,181 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.fluent.models; + +import azure.resourcemanager.multiserviceolderversions.combined.models.VirtualMachineProperties; +import com.azure.core.annotation.Fluent; +import com.azure.core.management.Resource; +import com.azure.core.management.SystemData; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.Map; + +/** + * Describes a Virtual Machine. + */ +@Fluent +public final class VirtualMachineInner extends Resource { + /* + * The resource-specific properties for this resource. + */ + private VirtualMachineProperties properties; + + /* + * Azure Resource Manager metadata containing createdBy and modifiedBy information. + */ + private SystemData systemData; + + /* + * The type of the resource. + */ + private String type; + + /* + * The name of the resource. + */ + private String name; + + /* + * Fully qualified resource Id for the resource. + */ + private String id; + + /** + * Creates an instance of VirtualMachineInner class. + */ + public VirtualMachineInner() { + } + + /** + * Get the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + public VirtualMachineProperties properties() { + return this.properties; + } + + /** + * Set the properties property: The resource-specific properties for this resource. + * + * @param properties the properties value to set. + * @return the VirtualMachineInner object itself. + */ + public VirtualMachineInner withProperties(VirtualMachineProperties properties) { + this.properties = properties; + return this; + } + + /** + * Get the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + public SystemData systemData() { + return this.systemData; + } + + /** + * Get the type property: The type of the resource. + * + * @return the type value. + */ + @Override + public String type() { + return this.type; + } + + /** + * Get the name property: The name of the resource. + * + * @return the name value. + */ + @Override + public String name() { + return this.name; + } + + /** + * Get the id property: Fully qualified resource Id for the resource. + * + * @return the id value. + */ + @Override + public String id() { + return this.id; + } + + /** + * {@inheritDoc} + */ + @Override + public VirtualMachineInner withLocation(String location) { + super.withLocation(location); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VirtualMachineInner withTags(Map tags) { + super.withTags(tags); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("location", location()); + jsonWriter.writeMapField("tags", tags(), (writer, element) -> writer.writeString(element)); + jsonWriter.writeJsonField("properties", this.properties); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VirtualMachineInner from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VirtualMachineInner 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 VirtualMachineInner. + */ + public static VirtualMachineInner fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + VirtualMachineInner deserializedVirtualMachineInner = new VirtualMachineInner(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedVirtualMachineInner.id = reader.getString(); + } else if ("name".equals(fieldName)) { + deserializedVirtualMachineInner.name = reader.getString(); + } else if ("type".equals(fieldName)) { + deserializedVirtualMachineInner.type = reader.getString(); + } else if ("location".equals(fieldName)) { + deserializedVirtualMachineInner.withLocation(reader.getString()); + } else if ("tags".equals(fieldName)) { + Map tags = reader.readMap(reader1 -> reader1.getString()); + deserializedVirtualMachineInner.withTags(tags); + } else if ("properties".equals(fieldName)) { + deserializedVirtualMachineInner.properties = VirtualMachineProperties.fromJson(reader); + } else if ("systemData".equals(fieldName)) { + deserializedVirtualMachineInner.systemData = SystemData.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedVirtualMachineInner; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/models/package-info.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/models/package-info.java new file mode 100644 index 0000000000..b6f7366cf9 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/models/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the inner data models for Compute. + * Compute Client. + */ +package azure.resourcemanager.multiserviceolderversions.combined.fluent.models; diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/package-info.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/package-info.java new file mode 100644 index 0000000000..f26ba06965 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the service clients for Compute. + * Compute Client. + */ +package azure.resourcemanager.multiserviceolderversions.combined.fluent; diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/CombinedBuilder.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/CombinedBuilder.java new file mode 100644 index 0000000000..3178471ba1 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/CombinedBuilder.java @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.implementation; + +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.serializer.SerializerFactory; +import com.azure.core.util.serializer.SerializerAdapter; +import java.time.Duration; + +/** + * A builder for creating a new instance of the CombinedImpl type. + */ +@ServiceClientBuilder(serviceClients = { CombinedImpl.class }) +public final class CombinedBuilder { + /* + * Service host + */ + private String endpoint; + + /** + * Sets Service host. + * + * @param endpoint the endpoint value. + * @return the CombinedBuilder. + */ + public CombinedBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * The ID of the target subscription. The value must be an UUID. + */ + private String subscriptionId; + + /** + * Sets The ID of the target subscription. The value must be an UUID. + * + * @param subscriptionId the subscriptionId value. + * @return the CombinedBuilder. + */ + public CombinedBuilder subscriptionId(String subscriptionId) { + this.subscriptionId = subscriptionId; + return this; + } + + /* + * The environment to connect to + */ + private AzureEnvironment environment; + + /** + * Sets The environment to connect to. + * + * @param environment the environment value. + * @return the CombinedBuilder. + */ + public CombinedBuilder environment(AzureEnvironment environment) { + this.environment = environment; + return this; + } + + /* + * The HTTP pipeline to send requests through + */ + private HttpPipeline pipeline; + + /** + * Sets The HTTP pipeline to send requests through. + * + * @param pipeline the pipeline value. + * @return the CombinedBuilder. + */ + public CombinedBuilder pipeline(HttpPipeline pipeline) { + this.pipeline = pipeline; + return this; + } + + /* + * The default poll interval for long-running operation + */ + private Duration defaultPollInterval; + + /** + * Sets The default poll interval for long-running operation. + * + * @param defaultPollInterval the defaultPollInterval value. + * @return the CombinedBuilder. + */ + public CombinedBuilder defaultPollInterval(Duration defaultPollInterval) { + this.defaultPollInterval = defaultPollInterval; + return this; + } + + /* + * The serializer to serialize an object into a string + */ + private SerializerAdapter serializerAdapter; + + /** + * Sets The serializer to serialize an object into a string. + * + * @param serializerAdapter the serializerAdapter value. + * @return the CombinedBuilder. + */ + public CombinedBuilder serializerAdapter(SerializerAdapter serializerAdapter) { + this.serializerAdapter = serializerAdapter; + return this; + } + + /** + * Builds an instance of CombinedImpl with the provided parameters. + * + * @return an instance of CombinedImpl. + */ + public CombinedImpl buildClient() { + String localEndpoint = (endpoint != null) ? endpoint : "https://management.azure.com"; + AzureEnvironment localEnvironment = (environment != null) ? environment : AzureEnvironment.AZURE; + HttpPipeline localPipeline = (pipeline != null) + ? pipeline + : new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(); + Duration localDefaultPollInterval + = (defaultPollInterval != null) ? defaultPollInterval : Duration.ofSeconds(30); + SerializerAdapter localSerializerAdapter = (serializerAdapter != null) + ? serializerAdapter + : SerializerFactory.createDefaultManagementSerializerAdapter(); + CombinedImpl client = new CombinedImpl(localPipeline, localSerializerAdapter, localDefaultPollInterval, + localEnvironment, localEndpoint, this.subscriptionId); + return client; + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/CombinedImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/CombinedImpl.java new file mode 100644 index 0000000000..75986505a2 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/CombinedImpl.java @@ -0,0 +1,309 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.implementation; + +import azure.resourcemanager.multiserviceolderversions.combined.fluent.Combined; +import azure.resourcemanager.multiserviceolderversions.combined.fluent.DisksClient; +import azure.resourcemanager.multiserviceolderversions.combined.fluent.VirtualMachinesClient; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpResponse; +import com.azure.core.http.rest.Response; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.exception.ManagementError; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.polling.PollResult; +import com.azure.core.management.polling.PollerFactory; +import com.azure.core.management.polling.SyncPollerFactory; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.polling.AsyncPollResponse; +import com.azure.core.util.polling.LongRunningOperationStatus; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.polling.SyncPoller; +import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.core.util.serializer.SerializerEncoding; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.time.Duration; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * Initializes a new instance of the CombinedImpl type. + */ +@ServiceClient(builder = CombinedBuilder.class) +public final class CombinedImpl implements Combined { + /** + * Service host. + */ + private final String endpoint; + + /** + * Gets Service host. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** + * The ID of the target subscription. The value must be an UUID. + */ + private final String subscriptionId; + + /** + * Gets The ID of the target subscription. The value must be an UUID. + * + * @return the subscriptionId value. + */ + public String getSubscriptionId() { + return this.subscriptionId; + } + + /** + * The HTTP pipeline to send requests through. + */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The serializer to serialize an object into a string. + */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * The default poll interval for long-running operation. + */ + private final Duration defaultPollInterval; + + /** + * Gets The default poll interval for long-running operation. + * + * @return the defaultPollInterval value. + */ + public Duration getDefaultPollInterval() { + return this.defaultPollInterval; + } + + /** + * The VirtualMachinesClient object to access its operations. + */ + private final VirtualMachinesClient virtualMachines; + + /** + * Gets the VirtualMachinesClient object to access its operations. + * + * @return the VirtualMachinesClient object. + */ + public VirtualMachinesClient getVirtualMachines() { + return this.virtualMachines; + } + + /** + * The DisksClient object to access its operations. + */ + private final DisksClient disks; + + /** + * Gets the DisksClient object to access its operations. + * + * @return the DisksClient object. + */ + public DisksClient getDisks() { + return this.disks; + } + + /** + * Initializes an instance of Combined client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param defaultPollInterval The default poll interval for long-running operation. + * @param environment The Azure environment. + * @param endpoint Service host. + * @param subscriptionId The ID of the target subscription. The value must be an UUID. + */ + CombinedImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, Duration defaultPollInterval, + AzureEnvironment environment, String endpoint, String subscriptionId) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.defaultPollInterval = defaultPollInterval; + this.endpoint = endpoint; + this.subscriptionId = subscriptionId; + this.virtualMachines = new VirtualMachinesClientImpl(this); + this.disks = new DisksClientImpl(this); + } + + /** + * Gets default client context. + * + * @return the default client context. + */ + public Context getContext() { + return Context.NONE; + } + + /** + * Merges default client context with provided context. + * + * @param context the context to be merged with default client context. + * @return the merged context. + */ + public Context mergeContext(Context context) { + return CoreUtils.mergeContexts(this.getContext(), context); + } + + /** + * Gets long running operation result. + * + * @param activationResponse the response of activation operation. + * @param httpPipeline the http pipeline. + * @param pollResultType type of poll result. + * @param finalResultType type of final result. + * @param context the context shared by all requests. + * @param type of poll result. + * @param type of final result. + * @return poller flux for poll result and final result. + */ + public PollerFlux, U> getLroResult(Mono>> activationResponse, + HttpPipeline httpPipeline, Type pollResultType, Type finalResultType, Context context) { + return PollerFactory.create(serializerAdapter, httpPipeline, pollResultType, finalResultType, + defaultPollInterval, activationResponse, context); + } + + /** + * Gets long running operation result. + * + * @param activationResponse the response of activation operation. + * @param pollResultType type of poll result. + * @param finalResultType type of final result. + * @param context the context shared by all requests. + * @param type of poll result. + * @param type of final result. + * @return SyncPoller for poll result and final result. + */ + public SyncPoller, U> getLroResult(Response activationResponse, + Type pollResultType, Type finalResultType, Context context) { + return SyncPollerFactory.create(serializerAdapter, httpPipeline, pollResultType, finalResultType, + defaultPollInterval, () -> activationResponse, context); + } + + /** + * Gets the final result, or an error, based on last async poll response. + * + * @param response the last async poll response. + * @param type of poll result. + * @param type of final result. + * @return the final result, or an error. + */ + public Mono getLroFinalResultOrError(AsyncPollResponse, U> response) { + if (response.getStatus() != LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) { + String errorMessage; + ManagementError managementError = null; + HttpResponse errorResponse = null; + PollResult.Error lroError = response.getValue().getError(); + if (lroError != null) { + errorResponse = new HttpResponseImpl(lroError.getResponseStatusCode(), lroError.getResponseHeaders(), + lroError.getResponseBody()); + + errorMessage = response.getValue().getError().getMessage(); + String errorBody = response.getValue().getError().getResponseBody(); + if (errorBody != null) { + // try to deserialize error body to ManagementError + try { + managementError = this.getSerializerAdapter() + .deserialize(errorBody, ManagementError.class, SerializerEncoding.JSON); + if (managementError.getCode() == null || managementError.getMessage() == null) { + managementError = null; + } + } catch (IOException | RuntimeException ioe) { + LOGGER.logThrowableAsWarning(ioe); + } + } + } else { + // fallback to default error message + errorMessage = "Long running operation failed."; + } + if (managementError == null) { + // fallback to default ManagementError + managementError = new ManagementError(response.getStatus().toString(), errorMessage); + } + return Mono.error(new ManagementException(errorMessage, errorResponse, managementError)); + } else { + return response.getFinalResult(); + } + } + + private static final class HttpResponseImpl extends HttpResponse { + private final int statusCode; + + private final byte[] responseBody; + + private final HttpHeaders httpHeaders; + + HttpResponseImpl(int statusCode, HttpHeaders httpHeaders, String responseBody) { + super(null); + this.statusCode = statusCode; + this.httpHeaders = httpHeaders; + this.responseBody = responseBody == null ? null : responseBody.getBytes(StandardCharsets.UTF_8); + } + + public int getStatusCode() { + return statusCode; + } + + public String getHeaderValue(String s) { + return httpHeaders.getValue(HttpHeaderName.fromString(s)); + } + + public HttpHeaders getHeaders() { + return httpHeaders; + } + + public Flux getBody() { + return Flux.just(ByteBuffer.wrap(responseBody)); + } + + public Mono getBodyAsByteArray() { + return Mono.just(responseBody); + } + + public Mono getBodyAsString() { + return Mono.just(new String(responseBody, StandardCharsets.UTF_8)); + } + + public Mono getBodyAsString(Charset charset) { + return Mono.just(new String(responseBody, charset)); + } + } + + private static final ClientLogger LOGGER = new ClientLogger(CombinedImpl.class); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/DiskImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/DiskImpl.java new file mode 100644 index 0000000000..4c8b72cd4c --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/DiskImpl.java @@ -0,0 +1,164 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.implementation; + +import azure.resourcemanager.multiserviceolderversions.combined.fluent.models.DiskInner; +import azure.resourcemanager.multiserviceolderversions.combined.models.Disk; +import azure.resourcemanager.multiserviceolderversions.combined.models.DiskProperties; +import com.azure.core.management.Region; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; +import java.util.Collections; +import java.util.Map; + +public final class DiskImpl implements Disk, Disk.Definition, Disk.Update { + private DiskInner innerObject; + + private final azure.resourcemanager.multiserviceolderversions.combined.CombinedManager serviceManager; + + public String id() { + return this.innerModel().id(); + } + + public String name() { + return this.innerModel().name(); + } + + public String type() { + return this.innerModel().type(); + } + + public String location() { + return this.innerModel().location(); + } + + public Map tags() { + Map inner = this.innerModel().tags(); + if (inner != null) { + return Collections.unmodifiableMap(inner); + } else { + return Collections.emptyMap(); + } + } + + public DiskProperties properties() { + return this.innerModel().properties(); + } + + public SystemData systemData() { + return this.innerModel().systemData(); + } + + public Region region() { + return Region.fromName(this.regionName()); + } + + public String regionName() { + return this.location(); + } + + public String resourceGroupName() { + return resourceGroupName; + } + + public DiskInner innerModel() { + return this.innerObject; + } + + private azure.resourcemanager.multiserviceolderversions.combined.CombinedManager manager() { + return this.serviceManager; + } + + private String resourceGroupName; + + private String diskName; + + public DiskImpl withExistingResourceGroup(String resourceGroupName) { + this.resourceGroupName = resourceGroupName; + return this; + } + + public Disk create() { + this.innerObject = serviceManager.serviceClient() + .getDisks() + .createOrUpdate(resourceGroupName, diskName, this.innerModel(), Context.NONE); + return this; + } + + public Disk create(Context context) { + this.innerObject = serviceManager.serviceClient() + .getDisks() + .createOrUpdate(resourceGroupName, diskName, this.innerModel(), context); + return this; + } + + DiskImpl(String name, azure.resourcemanager.multiserviceolderversions.combined.CombinedManager serviceManager) { + this.innerObject = new DiskInner(); + this.serviceManager = serviceManager; + this.diskName = name; + } + + public DiskImpl update() { + return this; + } + + public Disk apply() { + this.innerObject = serviceManager.serviceClient() + .getDisks() + .createOrUpdate(resourceGroupName, diskName, this.innerModel(), Context.NONE); + return this; + } + + public Disk apply(Context context) { + this.innerObject = serviceManager.serviceClient() + .getDisks() + .createOrUpdate(resourceGroupName, diskName, this.innerModel(), context); + return this; + } + + DiskImpl(DiskInner innerObject, + azure.resourcemanager.multiserviceolderversions.combined.CombinedManager serviceManager) { + this.innerObject = innerObject; + this.serviceManager = serviceManager; + this.resourceGroupName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "resourceGroups"); + this.diskName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "disksOld"); + } + + public Disk refresh() { + this.innerObject = serviceManager.serviceClient() + .getDisks() + .getByResourceGroupWithResponse(resourceGroupName, diskName, Context.NONE) + .getValue(); + return this; + } + + public Disk refresh(Context context) { + this.innerObject = serviceManager.serviceClient() + .getDisks() + .getByResourceGroupWithResponse(resourceGroupName, diskName, context) + .getValue(); + return this; + } + + public DiskImpl withRegion(Region location) { + this.innerModel().withLocation(location.toString()); + return this; + } + + public DiskImpl withRegion(String location) { + this.innerModel().withLocation(location); + return this; + } + + public DiskImpl withTags(Map tags) { + this.innerModel().withTags(tags); + return this; + } + + public DiskImpl withProperties(DiskProperties properties) { + this.innerModel().withProperties(properties); + return this; + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/DisksClientImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/DisksClientImpl.java new file mode 100644 index 0000000000..c81a1b1835 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/DisksClientImpl.java @@ -0,0 +1,345 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.implementation; + +import azure.resourcemanager.multiserviceolderversions.combined.fluent.DisksClient; +import azure.resourcemanager.multiserviceolderversions.combined.fluent.models.DiskInner; +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Headers; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Put; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.polling.SyncPoller; +import java.nio.ByteBuffer; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in DisksClient. + */ +public final class DisksClientImpl implements DisksClient { + /** + * The proxy service used to perform REST calls. + */ + private final DisksService service; + + /** + * The service client containing this operation class. + */ + private final CombinedImpl client; + + /** + * Initializes an instance of DisksClientImpl. + * + * @param client the instance of the service client containing this operation class. + */ + DisksClientImpl(CombinedImpl client) { + this.service = RestProxy.create(DisksService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for CombinedDisks to be used by the proxy service to perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "CombinedDisks") + public interface DisksService { + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disksOld/{diskName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> getByResourceGroup(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("diskName") String diskName, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disksOld/{diskName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response getByResourceGroupSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("diskName") String diskName, + @HeaderParam("Accept") String accept, Context context); + + @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disksOld/{diskName}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono>> createOrUpdate(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("diskName") String diskName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") DiskInner resource, Context context); + + @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/disksOld/{diskName}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response createOrUpdateSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("diskName") String diskName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") DiskInner resource, Context context); + } + + /** + * Gets information about a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a disk along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> getByResourceGroupWithResponseAsync(String resourceGroupName, String diskName) { + final String apiVersion = "2024-03-02"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.getByResourceGroup(this.client.getEndpoint(), apiVersion, + this.client.getSubscriptionId(), resourceGroupName, diskName, accept, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Gets information about a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a disk on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono getByResourceGroupAsync(String resourceGroupName, String diskName) { + return getByResourceGroupWithResponseAsync(resourceGroupName, diskName) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Gets information about a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a disk along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getByResourceGroupWithResponse(String resourceGroupName, String diskName, + Context context) { + final String apiVersion = "2024-03-02"; + final String accept = "application/json"; + return service.getByResourceGroupSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, diskName, accept, context); + } + + /** + * Gets information about a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a disk. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public DiskInner getByResourceGroup(String resourceGroupName, String diskName) { + return getByResourceGroupWithResponse(resourceGroupName, diskName, Context.NONE).getValue(); + } + + /** + * Creates or updates a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return disk resource along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono>> createOrUpdateWithResponseAsync(String resourceGroupName, String diskName, + DiskInner resource) { + final String apiVersion = "2024-03-02"; + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), apiVersion, + this.client.getSubscriptionId(), resourceGroupName, diskName, contentType, accept, resource, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Creates or updates a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return disk resource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Response createOrUpdateWithResponse(String resourceGroupName, String diskName, + DiskInner resource) { + final String apiVersion = "2024-03-02"; + final String contentType = "application/json"; + final String accept = "application/json"; + return service.createOrUpdateSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, diskName, contentType, accept, resource, Context.NONE); + } + + /** + * Creates or updates a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return disk resource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Response createOrUpdateWithResponse(String resourceGroupName, String diskName, + DiskInner resource, Context context) { + final String apiVersion = "2024-03-02"; + final String contentType = "application/json"; + final String accept = "application/json"; + return service.createOrUpdateSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, diskName, contentType, accept, resource, context); + } + + /** + * Creates or updates a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of disk resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, DiskInner> beginCreateOrUpdateAsync(String resourceGroupName, + String diskName, DiskInner resource) { + Mono>> mono = createOrUpdateWithResponseAsync(resourceGroupName, diskName, resource); + return this.client.getLroResult(mono, this.client.getHttpPipeline(), DiskInner.class, + DiskInner.class, this.client.getContext()); + } + + /** + * Creates or updates a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of disk resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, DiskInner> beginCreateOrUpdate(String resourceGroupName, String diskName, + DiskInner resource) { + Response response = createOrUpdateWithResponse(resourceGroupName, diskName, resource); + return this.client.getLroResult(response, DiskInner.class, DiskInner.class, Context.NONE); + } + + /** + * Creates or updates a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of disk resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, DiskInner> beginCreateOrUpdate(String resourceGroupName, String diskName, + DiskInner resource, Context context) { + Response response = createOrUpdateWithResponse(resourceGroupName, diskName, resource, context); + return this.client.getLroResult(response, DiskInner.class, DiskInner.class, context); + } + + /** + * Creates or updates a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return disk resource on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono createOrUpdateAsync(String resourceGroupName, String diskName, DiskInner resource) { + return beginCreateOrUpdateAsync(resourceGroupName, diskName, resource).last() + .flatMap(this.client::getLroFinalResultOrError); + } + + /** + * Creates or updates a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return disk resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public DiskInner createOrUpdate(String resourceGroupName, String diskName, DiskInner resource) { + return beginCreateOrUpdate(resourceGroupName, diskName, resource).getFinalResult(); + } + + /** + * Creates or updates a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return disk resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public DiskInner createOrUpdate(String resourceGroupName, String diskName, DiskInner resource, Context context) { + return beginCreateOrUpdate(resourceGroupName, diskName, resource, context).getFinalResult(); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/DisksImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/DisksImpl.java new file mode 100644 index 0000000000..82dc82cdd5 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/DisksImpl.java @@ -0,0 +1,88 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.implementation; + +import azure.resourcemanager.multiserviceolderversions.combined.fluent.DisksClient; +import azure.resourcemanager.multiserviceolderversions.combined.fluent.models.DiskInner; +import azure.resourcemanager.multiserviceolderversions.combined.models.Disk; +import azure.resourcemanager.multiserviceolderversions.combined.models.Disks; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.util.Context; +import com.azure.core.util.logging.ClientLogger; + +public final class DisksImpl implements Disks { + private static final ClientLogger LOGGER = new ClientLogger(DisksImpl.class); + + private final DisksClient innerClient; + + private final azure.resourcemanager.multiserviceolderversions.combined.CombinedManager serviceManager; + + public DisksImpl(DisksClient innerClient, + azure.resourcemanager.multiserviceolderversions.combined.CombinedManager serviceManager) { + this.innerClient = innerClient; + this.serviceManager = serviceManager; + } + + public Response getByResourceGroupWithResponse(String resourceGroupName, String diskName, Context context) { + Response inner + = this.serviceClient().getByResourceGroupWithResponse(resourceGroupName, diskName, context); + if (inner != null) { + return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(), + new DiskImpl(inner.getValue(), this.manager())); + } else { + return null; + } + } + + public Disk getByResourceGroup(String resourceGroupName, String diskName) { + DiskInner inner = this.serviceClient().getByResourceGroup(resourceGroupName, diskName); + if (inner != null) { + return new DiskImpl(inner, this.manager()); + } else { + return null; + } + } + + public Disk getById(String id) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String diskName = ResourceManagerUtils.getValueFromIdByName(id, "disksOld"); + if (diskName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'disksOld'.", id))); + } + return this.getByResourceGroupWithResponse(resourceGroupName, diskName, Context.NONE).getValue(); + } + + public Response getByIdWithResponse(String id, Context context) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String diskName = ResourceManagerUtils.getValueFromIdByName(id, "disksOld"); + if (diskName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'disksOld'.", id))); + } + return this.getByResourceGroupWithResponse(resourceGroupName, diskName, context); + } + + private DisksClient serviceClient() { + return this.innerClient; + } + + private azure.resourcemanager.multiserviceolderversions.combined.CombinedManager manager() { + return this.serviceManager; + } + + public DiskImpl define(String name) { + return new DiskImpl(name, this.manager()); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/ResourceManagerUtils.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/ResourceManagerUtils.java new file mode 100644 index 0000000000..e2a37af0be --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/ResourceManagerUtils.java @@ -0,0 +1,195 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.implementation; + +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.util.CoreUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import reactor.core.publisher.Flux; + +final class ResourceManagerUtils { + private ResourceManagerUtils() { + } + + static String getValueFromIdByName(String id, String name) { + if (id == null) { + return null; + } + Iterator itr = Arrays.stream(id.split("/")).iterator(); + while (itr.hasNext()) { + String part = itr.next(); + if (part != null && !part.trim().isEmpty()) { + if (part.equalsIgnoreCase(name)) { + if (itr.hasNext()) { + return itr.next(); + } else { + return null; + } + } + } + } + return null; + } + + static String getValueFromIdByParameterName(String id, String pathTemplate, String parameterName) { + if (id == null || pathTemplate == null) { + return null; + } + String parameterNameParentheses = "{" + parameterName + "}"; + List idSegmentsReverted = Arrays.asList(id.split("/")); + List pathSegments = Arrays.asList(pathTemplate.split("/")); + Collections.reverse(idSegmentsReverted); + Iterator idItrReverted = idSegmentsReverted.iterator(); + int pathIndex = pathSegments.size(); + while (idItrReverted.hasNext() && pathIndex > 0) { + String idSegment = idItrReverted.next(); + String pathSegment = pathSegments.get(--pathIndex); + if (!CoreUtils.isNullOrEmpty(idSegment) && !CoreUtils.isNullOrEmpty(pathSegment)) { + if (pathSegment.equalsIgnoreCase(parameterNameParentheses)) { + if (pathIndex == 0 || (pathIndex == 1 && pathSegments.get(0).isEmpty())) { + List segments = new ArrayList<>(); + segments.add(idSegment); + idItrReverted.forEachRemaining(segments::add); + Collections.reverse(segments); + if (!segments.isEmpty() && segments.get(0).isEmpty()) { + segments.remove(0); + } + return String.join("/", segments); + } else { + return idSegment; + } + } + } + } + return null; + } + + static PagedIterable mapPage(PagedIterable pageIterable, Function mapper) { + return new PagedIterableImpl<>(pageIterable, mapper); + } + + private static final class PagedIterableImpl extends PagedIterable { + + private final PagedIterable pagedIterable; + private final Function mapper; + private final Function, PagedResponse> pageMapper; + + private PagedIterableImpl(PagedIterable pagedIterable, Function mapper) { + super(PagedFlux.create(() -> (continuationToken, pageSize) -> Flux + .fromStream(pagedIterable.streamByPage().map(getPageMapper(mapper))))); + this.pagedIterable = pagedIterable; + this.mapper = mapper; + this.pageMapper = getPageMapper(mapper); + } + + private static Function, PagedResponse> getPageMapper(Function mapper) { + return page -> new PagedResponseBase(page.getRequest(), page.getStatusCode(), page.getHeaders(), + page.getElements().stream().map(mapper).collect(Collectors.toList()), page.getContinuationToken(), + null); + } + + @Override + public Stream stream() { + return pagedIterable.stream().map(mapper); + } + + @Override + public Stream> streamByPage() { + return pagedIterable.streamByPage().map(pageMapper); + } + + @Override + public Stream> streamByPage(String continuationToken) { + return pagedIterable.streamByPage(continuationToken).map(pageMapper); + } + + @Override + public Stream> streamByPage(int preferredPageSize) { + return pagedIterable.streamByPage(preferredPageSize).map(pageMapper); + } + + @Override + public Stream> streamByPage(String continuationToken, int preferredPageSize) { + return pagedIterable.streamByPage(continuationToken, preferredPageSize).map(pageMapper); + } + + @Override + public Iterator iterator() { + return new IteratorImpl<>(pagedIterable.iterator(), mapper); + } + + @Override + public Iterable> iterableByPage() { + return new IterableImpl<>(pagedIterable.iterableByPage(), pageMapper); + } + + @Override + public Iterable> iterableByPage(String continuationToken) { + return new IterableImpl<>(pagedIterable.iterableByPage(continuationToken), pageMapper); + } + + @Override + public Iterable> iterableByPage(int preferredPageSize) { + return new IterableImpl<>(pagedIterable.iterableByPage(preferredPageSize), pageMapper); + } + + @Override + public Iterable> iterableByPage(String continuationToken, int preferredPageSize) { + return new IterableImpl<>(pagedIterable.iterableByPage(continuationToken, preferredPageSize), pageMapper); + } + } + + private static final class IteratorImpl implements Iterator { + + private final Iterator iterator; + private final Function mapper; + + private IteratorImpl(Iterator iterator, Function mapper) { + this.iterator = iterator; + this.mapper = mapper; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public S next() { + return mapper.apply(iterator.next()); + } + + @Override + public void remove() { + iterator.remove(); + } + } + + private static final class IterableImpl implements Iterable { + + private final Iterable iterable; + private final Function mapper; + + private IterableImpl(Iterable iterable, Function mapper) { + this.iterable = iterable; + this.mapper = mapper; + } + + @Override + public Iterator iterator() { + return new IteratorImpl<>(iterable.iterator(), mapper); + } + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/VirtualMachineImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/VirtualMachineImpl.java new file mode 100644 index 0000000000..5b3de7436c --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/VirtualMachineImpl.java @@ -0,0 +1,165 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.implementation; + +import azure.resourcemanager.multiserviceolderversions.combined.fluent.models.VirtualMachineInner; +import azure.resourcemanager.multiserviceolderversions.combined.models.VirtualMachine; +import azure.resourcemanager.multiserviceolderversions.combined.models.VirtualMachineProperties; +import com.azure.core.management.Region; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; +import java.util.Collections; +import java.util.Map; + +public final class VirtualMachineImpl implements VirtualMachine, VirtualMachine.Definition, VirtualMachine.Update { + private VirtualMachineInner innerObject; + + private final azure.resourcemanager.multiserviceolderversions.combined.CombinedManager serviceManager; + + public String id() { + return this.innerModel().id(); + } + + public String name() { + return this.innerModel().name(); + } + + public String type() { + return this.innerModel().type(); + } + + public String location() { + return this.innerModel().location(); + } + + public Map tags() { + Map inner = this.innerModel().tags(); + if (inner != null) { + return Collections.unmodifiableMap(inner); + } else { + return Collections.emptyMap(); + } + } + + public VirtualMachineProperties properties() { + return this.innerModel().properties(); + } + + public SystemData systemData() { + return this.innerModel().systemData(); + } + + public Region region() { + return Region.fromName(this.regionName()); + } + + public String regionName() { + return this.location(); + } + + public String resourceGroupName() { + return resourceGroupName; + } + + public VirtualMachineInner innerModel() { + return this.innerObject; + } + + private azure.resourcemanager.multiserviceolderversions.combined.CombinedManager manager() { + return this.serviceManager; + } + + private String resourceGroupName; + + private String vmName; + + public VirtualMachineImpl withExistingResourceGroup(String resourceGroupName) { + this.resourceGroupName = resourceGroupName; + return this; + } + + public VirtualMachine create() { + this.innerObject = serviceManager.serviceClient() + .getVirtualMachines() + .createOrUpdate(resourceGroupName, vmName, this.innerModel(), Context.NONE); + return this; + } + + public VirtualMachine create(Context context) { + this.innerObject = serviceManager.serviceClient() + .getVirtualMachines() + .createOrUpdate(resourceGroupName, vmName, this.innerModel(), context); + return this; + } + + VirtualMachineImpl(String name, + azure.resourcemanager.multiserviceolderversions.combined.CombinedManager serviceManager) { + this.innerObject = new VirtualMachineInner(); + this.serviceManager = serviceManager; + this.vmName = name; + } + + public VirtualMachineImpl update() { + return this; + } + + public VirtualMachine apply() { + this.innerObject = serviceManager.serviceClient() + .getVirtualMachines() + .createOrUpdate(resourceGroupName, vmName, this.innerModel(), Context.NONE); + return this; + } + + public VirtualMachine apply(Context context) { + this.innerObject = serviceManager.serviceClient() + .getVirtualMachines() + .createOrUpdate(resourceGroupName, vmName, this.innerModel(), context); + return this; + } + + VirtualMachineImpl(VirtualMachineInner innerObject, + azure.resourcemanager.multiserviceolderversions.combined.CombinedManager serviceManager) { + this.innerObject = innerObject; + this.serviceManager = serviceManager; + this.resourceGroupName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "resourceGroups"); + this.vmName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "virtualMachinesOld"); + } + + public VirtualMachine refresh() { + this.innerObject = serviceManager.serviceClient() + .getVirtualMachines() + .getByResourceGroupWithResponse(resourceGroupName, vmName, Context.NONE) + .getValue(); + return this; + } + + public VirtualMachine refresh(Context context) { + this.innerObject = serviceManager.serviceClient() + .getVirtualMachines() + .getByResourceGroupWithResponse(resourceGroupName, vmName, context) + .getValue(); + return this; + } + + public VirtualMachineImpl withRegion(Region location) { + this.innerModel().withLocation(location.toString()); + return this; + } + + public VirtualMachineImpl withRegion(String location) { + this.innerModel().withLocation(location); + return this; + } + + public VirtualMachineImpl withTags(Map tags) { + this.innerModel().withTags(tags); + return this; + } + + public VirtualMachineImpl withProperties(VirtualMachineProperties properties) { + this.innerModel().withProperties(properties); + return this; + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/VirtualMachinesClientImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/VirtualMachinesClientImpl.java new file mode 100644 index 0000000000..eafb898b30 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/VirtualMachinesClientImpl.java @@ -0,0 +1,361 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.implementation; + +import azure.resourcemanager.multiserviceolderversions.combined.fluent.VirtualMachinesClient; +import azure.resourcemanager.multiserviceolderversions.combined.fluent.models.VirtualMachineInner; +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Headers; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Put; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.polling.SyncPoller; +import java.nio.ByteBuffer; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in VirtualMachinesClient. + */ +public final class VirtualMachinesClientImpl implements VirtualMachinesClient { + /** + * The proxy service used to perform REST calls. + */ + private final VirtualMachinesService service; + + /** + * The service client containing this operation class. + */ + private final CombinedImpl client; + + /** + * Initializes an instance of VirtualMachinesClientImpl. + * + * @param client the instance of the service client containing this operation class. + */ + VirtualMachinesClientImpl(CombinedImpl client) { + this.service + = RestProxy.create(VirtualMachinesService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for CombinedVirtualMachines to be used by the proxy service to perform + * REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "CombinedVirtualMachines") + public interface VirtualMachinesService { + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachinesOld/{vmName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> getByResourceGroup(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("vmName") String vmName, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachinesOld/{vmName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response getByResourceGroupSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("vmName") String vmName, + @HeaderParam("Accept") String accept, Context context); + + @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachinesOld/{vmName}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono>> createOrUpdate(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("vmName") String vmName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") VirtualMachineInner resource, Context context); + + @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachinesOld/{vmName}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response createOrUpdateSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("vmName") String vmName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") VirtualMachineInner resource, Context context); + } + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> getByResourceGroupWithResponseAsync(String resourceGroupName, + String vmName) { + final String apiVersion = "2024-11-01"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.getByResourceGroup(this.client.getEndpoint(), apiVersion, + this.client.getSubscriptionId(), resourceGroupName, vmName, accept, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono getByResourceGroupAsync(String resourceGroupName, String vmName) { + return getByResourceGroupWithResponseAsync(resourceGroupName, vmName) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getByResourceGroupWithResponse(String resourceGroupName, String vmName, + Context context) { + final String apiVersion = "2024-11-01"; + final String accept = "application/json"; + return service.getByResourceGroupSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, vmName, accept, context); + } + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public VirtualMachineInner getByResourceGroup(String resourceGroupName, String vmName) { + return getByResourceGroupWithResponse(resourceGroupName, vmName, Context.NONE).getValue(); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono>> createOrUpdateWithResponseAsync(String resourceGroupName, String vmName, + VirtualMachineInner resource) { + final String apiVersion = "2024-11-01"; + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), apiVersion, + this.client.getSubscriptionId(), resourceGroupName, vmName, contentType, accept, resource, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Response createOrUpdateWithResponse(String resourceGroupName, String vmName, + VirtualMachineInner resource) { + final String apiVersion = "2024-11-01"; + final String contentType = "application/json"; + final String accept = "application/json"; + return service.createOrUpdateSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, vmName, contentType, accept, resource, Context.NONE); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Response createOrUpdateWithResponse(String resourceGroupName, String vmName, + VirtualMachineInner resource, Context context) { + final String apiVersion = "2024-11-01"; + final String contentType = "application/json"; + final String accept = "application/json"; + return service.createOrUpdateSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, vmName, contentType, accept, resource, context); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, VirtualMachineInner> + beginCreateOrUpdateAsync(String resourceGroupName, String vmName, VirtualMachineInner resource) { + Mono>> mono = createOrUpdateWithResponseAsync(resourceGroupName, vmName, resource); + return this.client.getLroResult(mono, this.client.getHttpPipeline(), + VirtualMachineInner.class, VirtualMachineInner.class, this.client.getContext()); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, VirtualMachineInner> + beginCreateOrUpdate(String resourceGroupName, String vmName, VirtualMachineInner resource) { + Response response = createOrUpdateWithResponse(resourceGroupName, vmName, resource); + return this.client.getLroResult(response, VirtualMachineInner.class, + VirtualMachineInner.class, Context.NONE); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, VirtualMachineInner> + beginCreateOrUpdate(String resourceGroupName, String vmName, VirtualMachineInner resource, Context context) { + Response response = createOrUpdateWithResponse(resourceGroupName, vmName, resource, context); + return this.client.getLroResult(response, VirtualMachineInner.class, + VirtualMachineInner.class, context); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono createOrUpdateAsync(String resourceGroupName, String vmName, + VirtualMachineInner resource) { + return beginCreateOrUpdateAsync(resourceGroupName, vmName, resource).last() + .flatMap(this.client::getLroFinalResultOrError); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public VirtualMachineInner createOrUpdate(String resourceGroupName, String vmName, VirtualMachineInner resource) { + return beginCreateOrUpdate(resourceGroupName, vmName, resource).getFinalResult(); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public VirtualMachineInner createOrUpdate(String resourceGroupName, String vmName, VirtualMachineInner resource, + Context context) { + return beginCreateOrUpdate(resourceGroupName, vmName, resource, context).getFinalResult(); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/VirtualMachinesImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/VirtualMachinesImpl.java new file mode 100644 index 0000000000..f72d70052e --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/VirtualMachinesImpl.java @@ -0,0 +1,89 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.implementation; + +import azure.resourcemanager.multiserviceolderversions.combined.fluent.VirtualMachinesClient; +import azure.resourcemanager.multiserviceolderversions.combined.fluent.models.VirtualMachineInner; +import azure.resourcemanager.multiserviceolderversions.combined.models.VirtualMachine; +import azure.resourcemanager.multiserviceolderversions.combined.models.VirtualMachines; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.util.Context; +import com.azure.core.util.logging.ClientLogger; + +public final class VirtualMachinesImpl implements VirtualMachines { + private static final ClientLogger LOGGER = new ClientLogger(VirtualMachinesImpl.class); + + private final VirtualMachinesClient innerClient; + + private final azure.resourcemanager.multiserviceolderversions.combined.CombinedManager serviceManager; + + public VirtualMachinesImpl(VirtualMachinesClient innerClient, + azure.resourcemanager.multiserviceolderversions.combined.CombinedManager serviceManager) { + this.innerClient = innerClient; + this.serviceManager = serviceManager; + } + + public Response getByResourceGroupWithResponse(String resourceGroupName, String vmName, + Context context) { + Response inner + = this.serviceClient().getByResourceGroupWithResponse(resourceGroupName, vmName, context); + if (inner != null) { + return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(), + new VirtualMachineImpl(inner.getValue(), this.manager())); + } else { + return null; + } + } + + public VirtualMachine getByResourceGroup(String resourceGroupName, String vmName) { + VirtualMachineInner inner = this.serviceClient().getByResourceGroup(resourceGroupName, vmName); + if (inner != null) { + return new VirtualMachineImpl(inner, this.manager()); + } else { + return null; + } + } + + public VirtualMachine getById(String id) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String vmName = ResourceManagerUtils.getValueFromIdByName(id, "virtualMachinesOld"); + if (vmName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'virtualMachinesOld'.", id))); + } + return this.getByResourceGroupWithResponse(resourceGroupName, vmName, Context.NONE).getValue(); + } + + public Response getByIdWithResponse(String id, Context context) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String vmName = ResourceManagerUtils.getValueFromIdByName(id, "virtualMachinesOld"); + if (vmName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'virtualMachinesOld'.", id))); + } + return this.getByResourceGroupWithResponse(resourceGroupName, vmName, context); + } + + private VirtualMachinesClient serviceClient() { + return this.innerClient; + } + + private azure.resourcemanager.multiserviceolderversions.combined.CombinedManager manager() { + return this.serviceManager; + } + + public VirtualMachineImpl define(String name) { + return new VirtualMachineImpl(name, this.manager()); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/package-info.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/package-info.java new file mode 100644 index 0000000000..0fe238e297 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the implementations for Compute. + * Compute Client. + */ +package azure.resourcemanager.multiserviceolderversions.combined.implementation; diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/Disk.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/Disk.java new file mode 100644 index 0000000000..29add8d7ce --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/Disk.java @@ -0,0 +1,265 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.models; + +import azure.resourcemanager.multiserviceolderversions.combined.fluent.models.DiskInner; +import com.azure.core.management.Region; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; +import java.util.Map; + +/** + * An immutable client-side representation of Disk. + */ +public interface Disk { + /** + * Gets the id property: Fully qualified resource Id for the resource. + * + * @return the id value. + */ + String id(); + + /** + * Gets the name property: The name of the resource. + * + * @return the name value. + */ + String name(); + + /** + * Gets the type property: The type of the resource. + * + * @return the type value. + */ + String type(); + + /** + * Gets the location property: The geo-location where the resource lives. + * + * @return the location value. + */ + String location(); + + /** + * Gets the tags property: Resource tags. + * + * @return the tags value. + */ + Map tags(); + + /** + * Gets the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + DiskProperties properties(); + + /** + * Gets the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + SystemData systemData(); + + /** + * Gets the region of the resource. + * + * @return the region of the resource. + */ + Region region(); + + /** + * Gets the name of the resource region. + * + * @return the name of the resource region. + */ + String regionName(); + + /** + * Gets the name of the resource group. + * + * @return the name of the resource group. + */ + String resourceGroupName(); + + /** + * Gets the inner azure.resourcemanager.multiserviceolderversions.combined.fluent.models.DiskInner object. + * + * @return the inner object. + */ + DiskInner innerModel(); + + /** + * The entirety of the Disk definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithLocation, + DefinitionStages.WithResourceGroup, DefinitionStages.WithCreate { + } + + /** + * The Disk definition stages. + */ + interface DefinitionStages { + /** + * The first stage of the Disk definition. + */ + interface Blank extends WithLocation { + } + + /** + * The stage of the Disk definition allowing to specify location. + */ + interface WithLocation { + /** + * Specifies the region for the resource. + * + * @param location The geo-location where the resource lives. + * @return the next definition stage. + */ + WithResourceGroup withRegion(Region location); + + /** + * Specifies the region for the resource. + * + * @param location The geo-location where the resource lives. + * @return the next definition stage. + */ + WithResourceGroup withRegion(String location); + } + + /** + * The stage of the Disk definition allowing to specify parent resource. + */ + interface WithResourceGroup { + /** + * Specifies resourceGroupName. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @return the next definition stage. + */ + WithCreate withExistingResourceGroup(String resourceGroupName); + } + + /** + * The stage of the Disk definition which contains all the minimum required properties for the resource to be + * created, but also allows for any other optional properties to be specified. + */ + interface WithCreate extends DefinitionStages.WithTags, DefinitionStages.WithProperties { + /** + * Executes the create request. + * + * @return the created resource. + */ + Disk create(); + + /** + * Executes the create request. + * + * @param context The context to associate with this operation. + * @return the created resource. + */ + Disk create(Context context); + } + + /** + * The stage of the Disk definition allowing to specify tags. + */ + interface WithTags { + /** + * Specifies the tags property: Resource tags.. + * + * @param tags Resource tags. + * @return the next definition stage. + */ + WithCreate withTags(Map tags); + } + + /** + * The stage of the Disk definition allowing to specify properties. + */ + interface WithProperties { + /** + * Specifies the properties property: The resource-specific properties for this resource.. + * + * @param properties The resource-specific properties for this resource. + * @return the next definition stage. + */ + WithCreate withProperties(DiskProperties properties); + } + } + + /** + * Begins update for the Disk resource. + * + * @return the stage of resource update. + */ + Disk.Update update(); + + /** + * The template for Disk update. + */ + interface Update extends UpdateStages.WithTags, UpdateStages.WithProperties { + /** + * Executes the update request. + * + * @return the updated resource. + */ + Disk apply(); + + /** + * Executes the update request. + * + * @param context The context to associate with this operation. + * @return the updated resource. + */ + Disk apply(Context context); + } + + /** + * The Disk update stages. + */ + interface UpdateStages { + /** + * The stage of the Disk update allowing to specify tags. + */ + interface WithTags { + /** + * Specifies the tags property: Resource tags.. + * + * @param tags Resource tags. + * @return the next definition stage. + */ + Update withTags(Map tags); + } + + /** + * The stage of the Disk update allowing to specify properties. + */ + interface WithProperties { + /** + * Specifies the properties property: The resource-specific properties for this resource.. + * + * @param properties The resource-specific properties for this resource. + * @return the next definition stage. + */ + Update withProperties(DiskProperties properties); + } + } + + /** + * Refreshes the resource to sync with Azure. + * + * @return the refreshed resource. + */ + Disk refresh(); + + /** + * Refreshes the resource to sync with Azure. + * + * @param context The context to associate with this operation. + * @return the refreshed resource. + */ + Disk refresh(Context context); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/DiskProperties.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/DiskProperties.java new file mode 100644 index 0000000000..f3fa7ddcc0 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/DiskProperties.java @@ -0,0 +1,102 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.models; + +import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Disk resource properties. + */ +@Fluent +public final class DiskProperties implements JsonSerializable { + /* + * The provisioningState property. + */ + private ResourceProvisioningState provisioningState; + + /* + * Size of the disk in GB. Only available in version 2024-03-02. + */ + private Integer diskSizeGB; + + /** + * Creates an instance of DiskProperties class. + */ + public DiskProperties() { + } + + /** + * Get the provisioningState property: The provisioningState property. + * + * @return the provisioningState value. + */ + public ResourceProvisioningState provisioningState() { + return this.provisioningState; + } + + /** + * Get the diskSizeGB property: Size of the disk in GB. Only available in version 2024-03-02. + * + * @return the diskSizeGB value. + */ + public Integer diskSizeGB() { + return this.diskSizeGB; + } + + /** + * Set the diskSizeGB property: Size of the disk in GB. Only available in version 2024-03-02. + * + * @param diskSizeGB the diskSizeGB value to set. + * @return the DiskProperties object itself. + */ + public DiskProperties withDiskSizeGB(Integer diskSizeGB) { + this.diskSizeGB = diskSizeGB; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeNumberField("diskSizeGB", this.diskSizeGB); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of DiskProperties from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of DiskProperties 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 DiskProperties. + */ + public static DiskProperties fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + DiskProperties deserializedDiskProperties = new DiskProperties(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("provisioningState".equals(fieldName)) { + deserializedDiskProperties.provisioningState + = ResourceProvisioningState.fromString(reader.getString()); + } else if ("diskSizeGB".equals(fieldName)) { + deserializedDiskProperties.diskSizeGB = reader.getNullable(JsonReader::getInt); + } else { + reader.skipChildren(); + } + } + + return deserializedDiskProperties; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/Disks.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/Disks.java new file mode 100644 index 0000000000..8f025c9db8 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/Disks.java @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.models; + +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; + +/** + * Resource collection API of Disks. + */ +public interface Disks { + /** + * Gets information about a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a disk along with {@link Response}. + */ + Response getByResourceGroupWithResponse(String resourceGroupName, String diskName, Context context); + + /** + * Gets information about a disk. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param diskName The name of the Disk. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a disk. + */ + Disk getByResourceGroup(String resourceGroupName, String diskName); + + /** + * Gets information about a disk. + * + * @param id the resource ID. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a disk along with {@link Response}. + */ + Disk getById(String id); + + /** + * Gets information about a disk. + * + * @param id the resource ID. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a disk along with {@link Response}. + */ + Response getByIdWithResponse(String id, Context context); + + /** + * Begins definition for a new Disk resource. + * + * @param name resource name. + * @return the first stage of the new Disk definition. + */ + Disk.DefinitionStages.Blank define(String name); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/ResourceProvisioningState.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/ResourceProvisioningState.java new file mode 100644 index 0000000000..cbd8e8c691 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/ResourceProvisioningState.java @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * The provisioning state of a resource type. + */ +public final class ResourceProvisioningState extends ExpandableStringEnum { + /** + * Resource has been created. + */ + public static final ResourceProvisioningState SUCCEEDED = fromString("Succeeded"); + + /** + * Resource creation failed. + */ + public static final ResourceProvisioningState FAILED = fromString("Failed"); + + /** + * Resource creation was canceled. + */ + public static final ResourceProvisioningState CANCELED = fromString("Canceled"); + + /** + * Creates a new instance of ResourceProvisioningState value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public ResourceProvisioningState() { + } + + /** + * Creates or finds a ResourceProvisioningState from its string representation. + * + * @param name a name to look for. + * @return the corresponding ResourceProvisioningState. + */ + public static ResourceProvisioningState fromString(String name) { + return fromString(name, ResourceProvisioningState.class); + } + + /** + * Gets known ResourceProvisioningState values. + * + * @return known ResourceProvisioningState values. + */ + public static Collection values() { + return values(ResourceProvisioningState.class); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/VirtualMachine.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/VirtualMachine.java new file mode 100644 index 0000000000..e082f9f560 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/VirtualMachine.java @@ -0,0 +1,265 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.models; + +import azure.resourcemanager.multiserviceolderversions.combined.fluent.models.VirtualMachineInner; +import com.azure.core.management.Region; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; +import java.util.Map; + +/** + * An immutable client-side representation of VirtualMachine. + */ +public interface VirtualMachine { + /** + * Gets the id property: Fully qualified resource Id for the resource. + * + * @return the id value. + */ + String id(); + + /** + * Gets the name property: The name of the resource. + * + * @return the name value. + */ + String name(); + + /** + * Gets the type property: The type of the resource. + * + * @return the type value. + */ + String type(); + + /** + * Gets the location property: The geo-location where the resource lives. + * + * @return the location value. + */ + String location(); + + /** + * Gets the tags property: Resource tags. + * + * @return the tags value. + */ + Map tags(); + + /** + * Gets the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + VirtualMachineProperties properties(); + + /** + * Gets the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + SystemData systemData(); + + /** + * Gets the region of the resource. + * + * @return the region of the resource. + */ + Region region(); + + /** + * Gets the name of the resource region. + * + * @return the name of the resource region. + */ + String regionName(); + + /** + * Gets the name of the resource group. + * + * @return the name of the resource group. + */ + String resourceGroupName(); + + /** + * Gets the inner azure.resourcemanager.multiserviceolderversions.combined.fluent.models.VirtualMachineInner object. + * + * @return the inner object. + */ + VirtualMachineInner innerModel(); + + /** + * The entirety of the VirtualMachine definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithLocation, + DefinitionStages.WithResourceGroup, DefinitionStages.WithCreate { + } + + /** + * The VirtualMachine definition stages. + */ + interface DefinitionStages { + /** + * The first stage of the VirtualMachine definition. + */ + interface Blank extends WithLocation { + } + + /** + * The stage of the VirtualMachine definition allowing to specify location. + */ + interface WithLocation { + /** + * Specifies the region for the resource. + * + * @param location The geo-location where the resource lives. + * @return the next definition stage. + */ + WithResourceGroup withRegion(Region location); + + /** + * Specifies the region for the resource. + * + * @param location The geo-location where the resource lives. + * @return the next definition stage. + */ + WithResourceGroup withRegion(String location); + } + + /** + * The stage of the VirtualMachine definition allowing to specify parent resource. + */ + interface WithResourceGroup { + /** + * Specifies resourceGroupName. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @return the next definition stage. + */ + WithCreate withExistingResourceGroup(String resourceGroupName); + } + + /** + * The stage of the VirtualMachine definition which contains all the minimum required properties for the + * resource to be created, but also allows for any other optional properties to be specified. + */ + interface WithCreate extends DefinitionStages.WithTags, DefinitionStages.WithProperties { + /** + * Executes the create request. + * + * @return the created resource. + */ + VirtualMachine create(); + + /** + * Executes the create request. + * + * @param context The context to associate with this operation. + * @return the created resource. + */ + VirtualMachine create(Context context); + } + + /** + * The stage of the VirtualMachine definition allowing to specify tags. + */ + interface WithTags { + /** + * Specifies the tags property: Resource tags.. + * + * @param tags Resource tags. + * @return the next definition stage. + */ + WithCreate withTags(Map tags); + } + + /** + * The stage of the VirtualMachine definition allowing to specify properties. + */ + interface WithProperties { + /** + * Specifies the properties property: The resource-specific properties for this resource.. + * + * @param properties The resource-specific properties for this resource. + * @return the next definition stage. + */ + WithCreate withProperties(VirtualMachineProperties properties); + } + } + + /** + * Begins update for the VirtualMachine resource. + * + * @return the stage of resource update. + */ + VirtualMachine.Update update(); + + /** + * The template for VirtualMachine update. + */ + interface Update extends UpdateStages.WithTags, UpdateStages.WithProperties { + /** + * Executes the update request. + * + * @return the updated resource. + */ + VirtualMachine apply(); + + /** + * Executes the update request. + * + * @param context The context to associate with this operation. + * @return the updated resource. + */ + VirtualMachine apply(Context context); + } + + /** + * The VirtualMachine update stages. + */ + interface UpdateStages { + /** + * The stage of the VirtualMachine update allowing to specify tags. + */ + interface WithTags { + /** + * Specifies the tags property: Resource tags.. + * + * @param tags Resource tags. + * @return the next definition stage. + */ + Update withTags(Map tags); + } + + /** + * The stage of the VirtualMachine update allowing to specify properties. + */ + interface WithProperties { + /** + * Specifies the properties property: The resource-specific properties for this resource.. + * + * @param properties The resource-specific properties for this resource. + * @return the next definition stage. + */ + Update withProperties(VirtualMachineProperties properties); + } + } + + /** + * Refreshes the resource to sync with Azure. + * + * @return the refreshed resource. + */ + VirtualMachine refresh(); + + /** + * Refreshes the resource to sync with Azure. + * + * @param context The context to associate with this operation. + * @return the refreshed resource. + */ + VirtualMachine refresh(Context context); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/VirtualMachineProperties.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/VirtualMachineProperties.java new file mode 100644 index 0000000000..0a5e9296e9 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/VirtualMachineProperties.java @@ -0,0 +1,102 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.models; + +import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The VirtualMachineProperties model. + */ +@Fluent +public final class VirtualMachineProperties implements JsonSerializable { + /* + * The provisioningState property. + */ + private ResourceProvisioningState provisioningState; + + /* + * Size of the virtual machine. Only available in version 2024-11-01. + */ + private String size; + + /** + * Creates an instance of VirtualMachineProperties class. + */ + public VirtualMachineProperties() { + } + + /** + * Get the provisioningState property: The provisioningState property. + * + * @return the provisioningState value. + */ + public ResourceProvisioningState provisioningState() { + return this.provisioningState; + } + + /** + * Get the size property: Size of the virtual machine. Only available in version 2024-11-01. + * + * @return the size value. + */ + public String size() { + return this.size; + } + + /** + * Set the size property: Size of the virtual machine. Only available in version 2024-11-01. + * + * @param size the size value to set. + * @return the VirtualMachineProperties object itself. + */ + public VirtualMachineProperties withSize(String size) { + this.size = size; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("size", this.size); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VirtualMachineProperties from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VirtualMachineProperties 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 VirtualMachineProperties. + */ + public static VirtualMachineProperties fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + VirtualMachineProperties deserializedVirtualMachineProperties = new VirtualMachineProperties(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("provisioningState".equals(fieldName)) { + deserializedVirtualMachineProperties.provisioningState + = ResourceProvisioningState.fromString(reader.getString()); + } else if ("size".equals(fieldName)) { + deserializedVirtualMachineProperties.size = reader.getString(); + } else { + reader.skipChildren(); + } + } + + return deserializedVirtualMachineProperties; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/VirtualMachines.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/VirtualMachines.java new file mode 100644 index 0000000000..085e55909f --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/VirtualMachines.java @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.models; + +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; + +/** + * Resource collection API of VirtualMachines. + */ +public interface VirtualMachines { + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response}. + */ + Response getByResourceGroupWithResponse(String resourceGroupName, String vmName, Context context); + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine. + */ + VirtualMachine getByResourceGroup(String resourceGroupName, String vmName); + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param id the resource ID. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response}. + */ + VirtualMachine getById(String id); + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param id the resource ID. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response}. + */ + Response getByIdWithResponse(String id, Context context); + + /** + * Begins definition for a new VirtualMachine resource. + * + * @param name resource name. + * @return the first stage of the new VirtualMachine definition. + */ + VirtualMachine.DefinitionStages.Blank define(String name); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/package-info.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/package-info.java new file mode 100644 index 0000000000..221f269dbf --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the data models for Compute. + * Compute Client. + */ +package azure.resourcemanager.multiserviceolderversions.combined.models; diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/package-info.java b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/package-info.java new file mode 100644 index 0000000000..af6d0a0983 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiserviceolderversions/combined/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the classes for Compute. + * Compute Client. + */ +package azure.resourcemanager.multiserviceolderversions.combined; diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/CombinedManager.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/CombinedManager.java new file mode 100644 index 0000000000..eec6bad9ba --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/CombinedManager.java @@ -0,0 +1,298 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined; + +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.Combined; +import azure.resourcemanager.multiservicesharedmodels.combined.implementation.CombinedBuilder; +import azure.resourcemanager.multiservicesharedmodels.combined.implementation.StorageAccountsImpl; +import azure.resourcemanager.multiservicesharedmodels.combined.implementation.VirtualMachinesImpl; +import azure.resourcemanager.multiservicesharedmodels.combined.models.StorageAccounts; +import azure.resourcemanager.multiservicesharedmodels.combined.models.VirtualMachines; +import com.azure.core.credential.TokenCredential; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; +import com.azure.core.http.policy.BearerTokenAuthenticationPolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.management.profile.AzureProfile; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.logging.ClientLogger; +import java.time.Duration; +import java.time.temporal.ChronoUnit; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.stream.Collectors; + +/** + * Entry point to CombinedManager. + * Compute Client. + */ +public final class CombinedManager { + private VirtualMachines virtualMachines; + + private StorageAccounts storageAccounts; + + private final Combined clientObject; + + private CombinedManager(HttpPipeline httpPipeline, AzureProfile profile, Duration defaultPollInterval) { + Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + this.clientObject = new CombinedBuilder().pipeline(httpPipeline) + .endpoint(profile.getEnvironment().getResourceManagerEndpoint()) + .subscriptionId(profile.getSubscriptionId()) + .defaultPollInterval(defaultPollInterval) + .buildClient(); + } + + /** + * Creates an instance of combined service API entry point. + * + * @param credential the credential to use. + * @param profile the Azure profile for client. + * @return the combined service API instance. + */ + public static CombinedManager authenticate(TokenCredential credential, AzureProfile profile) { + Objects.requireNonNull(credential, "'credential' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + return configure().authenticate(credential, profile); + } + + /** + * Creates an instance of combined service API entry point. + * + * @param httpPipeline the {@link HttpPipeline} configured with Azure authentication credential. + * @param profile the Azure profile for client. + * @return the combined service API instance. + */ + public static CombinedManager authenticate(HttpPipeline httpPipeline, AzureProfile profile) { + Objects.requireNonNull(httpPipeline, "'httpPipeline' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + return new CombinedManager(httpPipeline, profile, null); + } + + /** + * Gets a Configurable instance that can be used to create CombinedManager with optional configuration. + * + * @return the Configurable instance allowing configurations. + */ + public static Configurable configure() { + return new CombinedManager.Configurable(); + } + + /** + * The Configurable allowing configurations to be set. + */ + public static final class Configurable { + private static final ClientLogger LOGGER = new ClientLogger(Configurable.class); + private static final String SDK_VERSION = "version"; + private static final Map PROPERTIES + = CoreUtils.getProperties("azure-resourcemanager-combined-generated.properties"); + + private HttpClient httpClient; + private HttpLogOptions httpLogOptions; + private final List policies = new ArrayList<>(); + private final List scopes = new ArrayList<>(); + private RetryPolicy retryPolicy; + private RetryOptions retryOptions; + private Duration defaultPollInterval; + + private Configurable() { + } + + /** + * Sets the http client. + * + * @param httpClient the HTTP client. + * @return the configurable object itself. + */ + public Configurable withHttpClient(HttpClient httpClient) { + this.httpClient = Objects.requireNonNull(httpClient, "'httpClient' cannot be null."); + return this; + } + + /** + * Sets the logging options to the HTTP pipeline. + * + * @param httpLogOptions the HTTP log options. + * @return the configurable object itself. + */ + public Configurable withLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = Objects.requireNonNull(httpLogOptions, "'httpLogOptions' cannot be null."); + return this; + } + + /** + * Adds the pipeline policy to the HTTP pipeline. + * + * @param policy the HTTP pipeline policy. + * @return the configurable object itself. + */ + public Configurable withPolicy(HttpPipelinePolicy policy) { + this.policies.add(Objects.requireNonNull(policy, "'policy' cannot be null.")); + return this; + } + + /** + * Adds the scope to permission sets. + * + * @param scope the scope. + * @return the configurable object itself. + */ + public Configurable withScope(String scope) { + this.scopes.add(Objects.requireNonNull(scope, "'scope' cannot be null.")); + return this; + } + + /** + * Sets the retry policy to the HTTP pipeline. + * + * @param retryPolicy the HTTP pipeline retry policy. + * @return the configurable object itself. + */ + public Configurable withRetryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = Objects.requireNonNull(retryPolicy, "'retryPolicy' cannot be null."); + return this; + } + + /** + * Sets the retry options for the HTTP pipeline retry policy. + *

+ * This setting has no effect, if retry policy is set via {@link #withRetryPolicy(RetryPolicy)}. + * + * @param retryOptions the retry options for the HTTP pipeline retry policy. + * @return the configurable object itself. + */ + public Configurable withRetryOptions(RetryOptions retryOptions) { + this.retryOptions = Objects.requireNonNull(retryOptions, "'retryOptions' cannot be null."); + return this; + } + + /** + * Sets the default poll interval, used when service does not provide "Retry-After" header. + * + * @param defaultPollInterval the default poll interval. + * @return the configurable object itself. + */ + public Configurable withDefaultPollInterval(Duration defaultPollInterval) { + this.defaultPollInterval + = Objects.requireNonNull(defaultPollInterval, "'defaultPollInterval' cannot be null."); + if (this.defaultPollInterval.isNegative()) { + throw LOGGER + .logExceptionAsError(new IllegalArgumentException("'defaultPollInterval' cannot be negative")); + } + return this; + } + + /** + * Creates an instance of combined service API entry point. + * + * @param credential the credential to use. + * @param profile the Azure profile for client. + * @return the combined service API instance. + */ + public CombinedManager authenticate(TokenCredential credential, AzureProfile profile) { + Objects.requireNonNull(credential, "'credential' cannot be null."); + Objects.requireNonNull(profile, "'profile' cannot be null."); + + String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); + + StringBuilder userAgentBuilder = new StringBuilder(); + userAgentBuilder.append("azsdk-java") + .append("-") + .append("azure.resourcemanager.multiservicesharedmodels.combined") + .append("/") + .append(clientVersion); + if (!Configuration.getGlobalConfiguration().get("AZURE_TELEMETRY_DISABLED", false)) { + userAgentBuilder.append(" (") + .append(Configuration.getGlobalConfiguration().get("java.version")) + .append("; ") + .append(Configuration.getGlobalConfiguration().get("os.name")) + .append("; ") + .append(Configuration.getGlobalConfiguration().get("os.version")) + .append("; auto-generated)"); + } else { + userAgentBuilder.append(" (auto-generated)"); + } + + if (scopes.isEmpty()) { + scopes.add(profile.getEnvironment().getManagementEndpoint() + "/.default"); + } + if (retryPolicy == null) { + if (retryOptions != null) { + retryPolicy = new RetryPolicy(retryOptions); + } else { + retryPolicy = new RetryPolicy("Retry-After", ChronoUnit.SECONDS); + } + } + List policies = new ArrayList<>(); + policies.add(new UserAgentPolicy(userAgentBuilder.toString())); + policies.add(new AddHeadersFromContextPolicy()); + policies.add(new RequestIdPolicy()); + policies.addAll(this.policies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .collect(Collectors.toList())); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(retryPolicy); + policies.add(new AddDatePolicy()); + policies.add(new BearerTokenAuthenticationPolicy(credential, scopes.toArray(new String[0]))); + policies.addAll(this.policies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .collect(Collectors.toList())); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(httpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().httpClient(httpClient) + .policies(policies.toArray(new HttpPipelinePolicy[0])) + .build(); + return new CombinedManager(httpPipeline, profile, defaultPollInterval); + } + } + + /** + * Gets the resource collection API of VirtualMachines. It manages VirtualMachine. + * + * @return Resource collection API of VirtualMachines. + */ + public VirtualMachines virtualMachines() { + if (this.virtualMachines == null) { + this.virtualMachines = new VirtualMachinesImpl(clientObject.getVirtualMachines(), this); + } + return virtualMachines; + } + + /** + * Gets the resource collection API of StorageAccounts. It manages StorageAccount. + * + * @return Resource collection API of StorageAccounts. + */ + public StorageAccounts storageAccounts() { + if (this.storageAccounts == null) { + this.storageAccounts = new StorageAccountsImpl(clientObject.getStorageAccounts(), this); + } + return storageAccounts; + } + + /** + * Gets wrapped service client Combined providing direct access to the underlying auto-generated API implementation, + * based on Azure REST API. + * + * @return Wrapped service client Combined. + */ + public Combined serviceClient() { + return this.clientObject; + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/Combined.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/Combined.java new file mode 100644 index 0000000000..987aba4313 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/Combined.java @@ -0,0 +1,55 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.fluent; + +import com.azure.core.http.HttpPipeline; +import java.time.Duration; + +/** + * The interface for Combined class. + */ +public interface Combined { + /** + * Gets Service host. + * + * @return the endpoint value. + */ + String getEndpoint(); + + /** + * Gets The ID of the target subscription. The value must be an UUID. + * + * @return the subscriptionId value. + */ + String getSubscriptionId(); + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + HttpPipeline getHttpPipeline(); + + /** + * Gets The default poll interval for long-running operation. + * + * @return the defaultPollInterval value. + */ + Duration getDefaultPollInterval(); + + /** + * Gets the VirtualMachinesClient object to access its operations. + * + * @return the VirtualMachinesClient object. + */ + VirtualMachinesClient getVirtualMachines(); + + /** + * Gets the StorageAccountsClient object to access its operations. + * + * @return the StorageAccountsClient object. + */ + StorageAccountsClient getStorageAccounts(); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/StorageAccountsClient.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/StorageAccountsClient.java new file mode 100644 index 0000000000..61e63e280a --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/StorageAccountsClient.java @@ -0,0 +1,107 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.fluent; + +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.StorageAccountInner; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.http.rest.Response; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.Context; +import com.azure.core.util.polling.SyncPoller; + +/** + * An instance of this class provides access to all the operations defined in StorageAccountsClient. + */ +public interface StorageAccountsClient { + /** + * Gets information about a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a storage account along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response getByResourceGroupWithResponse(String resourceGroupName, String accountName, + Context context); + + /** + * Gets information about a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a storage account. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + StorageAccountInner getByResourceGroup(String resourceGroupName, String accountName); + + /** + * Creates or updates a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of storage account resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, StorageAccountInner> beginCreateOrUpdate(String resourceGroupName, + String accountName, StorageAccountInner resource); + + /** + * Creates or updates a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of storage account resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, StorageAccountInner> beginCreateOrUpdate(String resourceGroupName, + String accountName, StorageAccountInner resource, Context context); + + /** + * Creates or updates a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return storage account resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + StorageAccountInner createOrUpdate(String resourceGroupName, String accountName, StorageAccountInner resource); + + /** + * Creates or updates a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return storage account resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + StorageAccountInner createOrUpdate(String resourceGroupName, String accountName, StorageAccountInner resource, + Context context); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/VirtualMachinesClient.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/VirtualMachinesClient.java new file mode 100644 index 0000000000..78e3bfeb3b --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/VirtualMachinesClient.java @@ -0,0 +1,111 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.fluent; + +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.VirtualMachineInner; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.http.rest.Response; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.Context; +import com.azure.core.util.polling.SyncPoller; + +/** + * An instance of this class provides access to all the operations defined in VirtualMachinesClient. + */ +public interface VirtualMachinesClient { + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + Response getByResourceGroupWithResponse(String resourceGroupName, String vmName, + Context context); + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + VirtualMachineInner getByResourceGroup(String resourceGroupName, String vmName); + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, VirtualMachineInner> beginCreateOrUpdate(String resourceGroupName, + String vmName, VirtualMachineInner resource); + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + SyncPoller, VirtualMachineInner> beginCreateOrUpdate(String resourceGroupName, + String vmName, VirtualMachineInner resource, Context context); + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + VirtualMachineInner createOrUpdate(String resourceGroupName, String vmName, VirtualMachineInner resource); + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + VirtualMachineInner createOrUpdate(String resourceGroupName, String vmName, VirtualMachineInner resource, + Context context); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/models/StorageAccountInner.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/models/StorageAccountInner.java new file mode 100644 index 0000000000..1a102b173d --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/models/StorageAccountInner.java @@ -0,0 +1,181 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.fluent.models; + +import azure.resourcemanager.multiservicesharedmodels.combined.models.StorageAccountProperties; +import com.azure.core.annotation.Fluent; +import com.azure.core.management.Resource; +import com.azure.core.management.SystemData; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.Map; + +/** + * Storage account resource. + */ +@Fluent +public final class StorageAccountInner extends Resource { + /* + * The resource-specific properties for this resource. + */ + private StorageAccountProperties properties; + + /* + * Azure Resource Manager metadata containing createdBy and modifiedBy information. + */ + private SystemData systemData; + + /* + * The type of the resource. + */ + private String type; + + /* + * The name of the resource. + */ + private String name; + + /* + * Fully qualified resource Id for the resource. + */ + private String id; + + /** + * Creates an instance of StorageAccountInner class. + */ + public StorageAccountInner() { + } + + /** + * Get the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + public StorageAccountProperties properties() { + return this.properties; + } + + /** + * Set the properties property: The resource-specific properties for this resource. + * + * @param properties the properties value to set. + * @return the StorageAccountInner object itself. + */ + public StorageAccountInner withProperties(StorageAccountProperties properties) { + this.properties = properties; + return this; + } + + /** + * Get the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + public SystemData systemData() { + return this.systemData; + } + + /** + * Get the type property: The type of the resource. + * + * @return the type value. + */ + @Override + public String type() { + return this.type; + } + + /** + * Get the name property: The name of the resource. + * + * @return the name value. + */ + @Override + public String name() { + return this.name; + } + + /** + * Get the id property: Fully qualified resource Id for the resource. + * + * @return the id value. + */ + @Override + public String id() { + return this.id; + } + + /** + * {@inheritDoc} + */ + @Override + public StorageAccountInner withLocation(String location) { + super.withLocation(location); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public StorageAccountInner withTags(Map tags) { + super.withTags(tags); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("location", location()); + jsonWriter.writeMapField("tags", tags(), (writer, element) -> writer.writeString(element)); + jsonWriter.writeJsonField("properties", this.properties); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of StorageAccountInner from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of StorageAccountInner 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 StorageAccountInner. + */ + public static StorageAccountInner fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + StorageAccountInner deserializedStorageAccountInner = new StorageAccountInner(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedStorageAccountInner.id = reader.getString(); + } else if ("name".equals(fieldName)) { + deserializedStorageAccountInner.name = reader.getString(); + } else if ("type".equals(fieldName)) { + deserializedStorageAccountInner.type = reader.getString(); + } else if ("location".equals(fieldName)) { + deserializedStorageAccountInner.withLocation(reader.getString()); + } else if ("tags".equals(fieldName)) { + Map tags = reader.readMap(reader1 -> reader1.getString()); + deserializedStorageAccountInner.withTags(tags); + } else if ("properties".equals(fieldName)) { + deserializedStorageAccountInner.properties = StorageAccountProperties.fromJson(reader); + } else if ("systemData".equals(fieldName)) { + deserializedStorageAccountInner.systemData = SystemData.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedStorageAccountInner; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/models/VirtualMachineInner.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/models/VirtualMachineInner.java new file mode 100644 index 0000000000..276a871981 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/models/VirtualMachineInner.java @@ -0,0 +1,181 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.fluent.models; + +import azure.resourcemanager.multiservicesharedmodels.combined.models.VirtualMachineProperties; +import com.azure.core.annotation.Fluent; +import com.azure.core.management.Resource; +import com.azure.core.management.SystemData; +import com.azure.json.JsonReader; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; +import java.util.Map; + +/** + * Describes a Virtual Machine. + */ +@Fluent +public final class VirtualMachineInner extends Resource { + /* + * The resource-specific properties for this resource. + */ + private VirtualMachineProperties properties; + + /* + * Azure Resource Manager metadata containing createdBy and modifiedBy information. + */ + private SystemData systemData; + + /* + * The type of the resource. + */ + private String type; + + /* + * The name of the resource. + */ + private String name; + + /* + * Fully qualified resource Id for the resource. + */ + private String id; + + /** + * Creates an instance of VirtualMachineInner class. + */ + public VirtualMachineInner() { + } + + /** + * Get the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + public VirtualMachineProperties properties() { + return this.properties; + } + + /** + * Set the properties property: The resource-specific properties for this resource. + * + * @param properties the properties value to set. + * @return the VirtualMachineInner object itself. + */ + public VirtualMachineInner withProperties(VirtualMachineProperties properties) { + this.properties = properties; + return this; + } + + /** + * Get the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + public SystemData systemData() { + return this.systemData; + } + + /** + * Get the type property: The type of the resource. + * + * @return the type value. + */ + @Override + public String type() { + return this.type; + } + + /** + * Get the name property: The name of the resource. + * + * @return the name value. + */ + @Override + public String name() { + return this.name; + } + + /** + * Get the id property: Fully qualified resource Id for the resource. + * + * @return the id value. + */ + @Override + public String id() { + return this.id; + } + + /** + * {@inheritDoc} + */ + @Override + public VirtualMachineInner withLocation(String location) { + super.withLocation(location); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public VirtualMachineInner withTags(Map tags) { + super.withTags(tags); + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("location", location()); + jsonWriter.writeMapField("tags", tags(), (writer, element) -> writer.writeString(element)); + jsonWriter.writeJsonField("properties", this.properties); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VirtualMachineInner from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VirtualMachineInner 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 VirtualMachineInner. + */ + public static VirtualMachineInner fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + VirtualMachineInner deserializedVirtualMachineInner = new VirtualMachineInner(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("id".equals(fieldName)) { + deserializedVirtualMachineInner.id = reader.getString(); + } else if ("name".equals(fieldName)) { + deserializedVirtualMachineInner.name = reader.getString(); + } else if ("type".equals(fieldName)) { + deserializedVirtualMachineInner.type = reader.getString(); + } else if ("location".equals(fieldName)) { + deserializedVirtualMachineInner.withLocation(reader.getString()); + } else if ("tags".equals(fieldName)) { + Map tags = reader.readMap(reader1 -> reader1.getString()); + deserializedVirtualMachineInner.withTags(tags); + } else if ("properties".equals(fieldName)) { + deserializedVirtualMachineInner.properties = VirtualMachineProperties.fromJson(reader); + } else if ("systemData".equals(fieldName)) { + deserializedVirtualMachineInner.systemData = SystemData.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedVirtualMachineInner; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/models/package-info.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/models/package-info.java new file mode 100644 index 0000000000..be6e63603e --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/models/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the inner data models for Compute. + * Compute Client. + */ +package azure.resourcemanager.multiservicesharedmodels.combined.fluent.models; diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/package-info.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/package-info.java new file mode 100644 index 0000000000..a46908efc1 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the service clients for Compute. + * Compute Client. + */ +package azure.resourcemanager.multiservicesharedmodels.combined.fluent; diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/CombinedBuilder.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/CombinedBuilder.java new file mode 100644 index 0000000000..2519e00c15 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/CombinedBuilder.java @@ -0,0 +1,138 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.implementation; + +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.serializer.SerializerFactory; +import com.azure.core.util.serializer.SerializerAdapter; +import java.time.Duration; + +/** + * A builder for creating a new instance of the CombinedImpl type. + */ +@ServiceClientBuilder(serviceClients = { CombinedImpl.class }) +public final class CombinedBuilder { + /* + * Service host + */ + private String endpoint; + + /** + * Sets Service host. + * + * @param endpoint the endpoint value. + * @return the CombinedBuilder. + */ + public CombinedBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * The ID of the target subscription. The value must be an UUID. + */ + private String subscriptionId; + + /** + * Sets The ID of the target subscription. The value must be an UUID. + * + * @param subscriptionId the subscriptionId value. + * @return the CombinedBuilder. + */ + public CombinedBuilder subscriptionId(String subscriptionId) { + this.subscriptionId = subscriptionId; + return this; + } + + /* + * The environment to connect to + */ + private AzureEnvironment environment; + + /** + * Sets The environment to connect to. + * + * @param environment the environment value. + * @return the CombinedBuilder. + */ + public CombinedBuilder environment(AzureEnvironment environment) { + this.environment = environment; + return this; + } + + /* + * The HTTP pipeline to send requests through + */ + private HttpPipeline pipeline; + + /** + * Sets The HTTP pipeline to send requests through. + * + * @param pipeline the pipeline value. + * @return the CombinedBuilder. + */ + public CombinedBuilder pipeline(HttpPipeline pipeline) { + this.pipeline = pipeline; + return this; + } + + /* + * The default poll interval for long-running operation + */ + private Duration defaultPollInterval; + + /** + * Sets The default poll interval for long-running operation. + * + * @param defaultPollInterval the defaultPollInterval value. + * @return the CombinedBuilder. + */ + public CombinedBuilder defaultPollInterval(Duration defaultPollInterval) { + this.defaultPollInterval = defaultPollInterval; + return this; + } + + /* + * The serializer to serialize an object into a string + */ + private SerializerAdapter serializerAdapter; + + /** + * Sets The serializer to serialize an object into a string. + * + * @param serializerAdapter the serializerAdapter value. + * @return the CombinedBuilder. + */ + public CombinedBuilder serializerAdapter(SerializerAdapter serializerAdapter) { + this.serializerAdapter = serializerAdapter; + return this; + } + + /** + * Builds an instance of CombinedImpl with the provided parameters. + * + * @return an instance of CombinedImpl. + */ + public CombinedImpl buildClient() { + String localEndpoint = (endpoint != null) ? endpoint : "https://management.azure.com"; + AzureEnvironment localEnvironment = (environment != null) ? environment : AzureEnvironment.AZURE; + HttpPipeline localPipeline = (pipeline != null) + ? pipeline + : new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(); + Duration localDefaultPollInterval + = (defaultPollInterval != null) ? defaultPollInterval : Duration.ofSeconds(30); + SerializerAdapter localSerializerAdapter = (serializerAdapter != null) + ? serializerAdapter + : SerializerFactory.createDefaultManagementSerializerAdapter(); + CombinedImpl client = new CombinedImpl(localPipeline, localSerializerAdapter, localDefaultPollInterval, + localEnvironment, localEndpoint, this.subscriptionId); + return client; + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/CombinedImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/CombinedImpl.java new file mode 100644 index 0000000000..124fe1779c --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/CombinedImpl.java @@ -0,0 +1,309 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.implementation; + +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.Combined; +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.StorageAccountsClient; +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.VirtualMachinesClient; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.http.HttpHeaderName; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpResponse; +import com.azure.core.http.rest.Response; +import com.azure.core.management.AzureEnvironment; +import com.azure.core.management.exception.ManagementError; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.polling.PollResult; +import com.azure.core.management.polling.PollerFactory; +import com.azure.core.management.polling.SyncPollerFactory; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.polling.AsyncPollResponse; +import com.azure.core.util.polling.LongRunningOperationStatus; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.polling.SyncPoller; +import com.azure.core.util.serializer.SerializerAdapter; +import com.azure.core.util.serializer.SerializerEncoding; +import java.io.IOException; +import java.lang.reflect.Type; +import java.nio.ByteBuffer; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.time.Duration; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * Initializes a new instance of the CombinedImpl type. + */ +@ServiceClient(builder = CombinedBuilder.class) +public final class CombinedImpl implements Combined { + /** + * Service host. + */ + private final String endpoint; + + /** + * Gets Service host. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** + * The ID of the target subscription. The value must be an UUID. + */ + private final String subscriptionId; + + /** + * Gets The ID of the target subscription. The value must be an UUID. + * + * @return the subscriptionId value. + */ + public String getSubscriptionId() { + return this.subscriptionId; + } + + /** + * The HTTP pipeline to send requests through. + */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The serializer to serialize an object into a string. + */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * The default poll interval for long-running operation. + */ + private final Duration defaultPollInterval; + + /** + * Gets The default poll interval for long-running operation. + * + * @return the defaultPollInterval value. + */ + public Duration getDefaultPollInterval() { + return this.defaultPollInterval; + } + + /** + * The VirtualMachinesClient object to access its operations. + */ + private final VirtualMachinesClient virtualMachines; + + /** + * Gets the VirtualMachinesClient object to access its operations. + * + * @return the VirtualMachinesClient object. + */ + public VirtualMachinesClient getVirtualMachines() { + return this.virtualMachines; + } + + /** + * The StorageAccountsClient object to access its operations. + */ + private final StorageAccountsClient storageAccounts; + + /** + * Gets the StorageAccountsClient object to access its operations. + * + * @return the StorageAccountsClient object. + */ + public StorageAccountsClient getStorageAccounts() { + return this.storageAccounts; + } + + /** + * Initializes an instance of Combined client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param serializerAdapter The serializer to serialize an object into a string. + * @param defaultPollInterval The default poll interval for long-running operation. + * @param environment The Azure environment. + * @param endpoint Service host. + * @param subscriptionId The ID of the target subscription. The value must be an UUID. + */ + CombinedImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, Duration defaultPollInterval, + AzureEnvironment environment, String endpoint, String subscriptionId) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.defaultPollInterval = defaultPollInterval; + this.endpoint = endpoint; + this.subscriptionId = subscriptionId; + this.virtualMachines = new VirtualMachinesClientImpl(this); + this.storageAccounts = new StorageAccountsClientImpl(this); + } + + /** + * Gets default client context. + * + * @return the default client context. + */ + public Context getContext() { + return Context.NONE; + } + + /** + * Merges default client context with provided context. + * + * @param context the context to be merged with default client context. + * @return the merged context. + */ + public Context mergeContext(Context context) { + return CoreUtils.mergeContexts(this.getContext(), context); + } + + /** + * Gets long running operation result. + * + * @param activationResponse the response of activation operation. + * @param httpPipeline the http pipeline. + * @param pollResultType type of poll result. + * @param finalResultType type of final result. + * @param context the context shared by all requests. + * @param type of poll result. + * @param type of final result. + * @return poller flux for poll result and final result. + */ + public PollerFlux, U> getLroResult(Mono>> activationResponse, + HttpPipeline httpPipeline, Type pollResultType, Type finalResultType, Context context) { + return PollerFactory.create(serializerAdapter, httpPipeline, pollResultType, finalResultType, + defaultPollInterval, activationResponse, context); + } + + /** + * Gets long running operation result. + * + * @param activationResponse the response of activation operation. + * @param pollResultType type of poll result. + * @param finalResultType type of final result. + * @param context the context shared by all requests. + * @param type of poll result. + * @param type of final result. + * @return SyncPoller for poll result and final result. + */ + public SyncPoller, U> getLroResult(Response activationResponse, + Type pollResultType, Type finalResultType, Context context) { + return SyncPollerFactory.create(serializerAdapter, httpPipeline, pollResultType, finalResultType, + defaultPollInterval, () -> activationResponse, context); + } + + /** + * Gets the final result, or an error, based on last async poll response. + * + * @param response the last async poll response. + * @param type of poll result. + * @param type of final result. + * @return the final result, or an error. + */ + public Mono getLroFinalResultOrError(AsyncPollResponse, U> response) { + if (response.getStatus() != LongRunningOperationStatus.SUCCESSFULLY_COMPLETED) { + String errorMessage; + ManagementError managementError = null; + HttpResponse errorResponse = null; + PollResult.Error lroError = response.getValue().getError(); + if (lroError != null) { + errorResponse = new HttpResponseImpl(lroError.getResponseStatusCode(), lroError.getResponseHeaders(), + lroError.getResponseBody()); + + errorMessage = response.getValue().getError().getMessage(); + String errorBody = response.getValue().getError().getResponseBody(); + if (errorBody != null) { + // try to deserialize error body to ManagementError + try { + managementError = this.getSerializerAdapter() + .deserialize(errorBody, ManagementError.class, SerializerEncoding.JSON); + if (managementError.getCode() == null || managementError.getMessage() == null) { + managementError = null; + } + } catch (IOException | RuntimeException ioe) { + LOGGER.logThrowableAsWarning(ioe); + } + } + } else { + // fallback to default error message + errorMessage = "Long running operation failed."; + } + if (managementError == null) { + // fallback to default ManagementError + managementError = new ManagementError(response.getStatus().toString(), errorMessage); + } + return Mono.error(new ManagementException(errorMessage, errorResponse, managementError)); + } else { + return response.getFinalResult(); + } + } + + private static final class HttpResponseImpl extends HttpResponse { + private final int statusCode; + + private final byte[] responseBody; + + private final HttpHeaders httpHeaders; + + HttpResponseImpl(int statusCode, HttpHeaders httpHeaders, String responseBody) { + super(null); + this.statusCode = statusCode; + this.httpHeaders = httpHeaders; + this.responseBody = responseBody == null ? null : responseBody.getBytes(StandardCharsets.UTF_8); + } + + public int getStatusCode() { + return statusCode; + } + + public String getHeaderValue(String s) { + return httpHeaders.getValue(HttpHeaderName.fromString(s)); + } + + public HttpHeaders getHeaders() { + return httpHeaders; + } + + public Flux getBody() { + return Flux.just(ByteBuffer.wrap(responseBody)); + } + + public Mono getBodyAsByteArray() { + return Mono.just(responseBody); + } + + public Mono getBodyAsString() { + return Mono.just(new String(responseBody, StandardCharsets.UTF_8)); + } + + public Mono getBodyAsString(Charset charset) { + return Mono.just(new String(responseBody, charset)); + } + } + + private static final ClientLogger LOGGER = new ClientLogger(CombinedImpl.class); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/ResourceManagerUtils.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/ResourceManagerUtils.java new file mode 100644 index 0000000000..070bf10b11 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/ResourceManagerUtils.java @@ -0,0 +1,195 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.implementation; + +import com.azure.core.http.rest.PagedFlux; +import com.azure.core.http.rest.PagedIterable; +import com.azure.core.http.rest.PagedResponse; +import com.azure.core.http.rest.PagedResponseBase; +import com.azure.core.util.CoreUtils; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.List; +import java.util.function.Function; +import java.util.stream.Collectors; +import java.util.stream.Stream; +import reactor.core.publisher.Flux; + +final class ResourceManagerUtils { + private ResourceManagerUtils() { + } + + static String getValueFromIdByName(String id, String name) { + if (id == null) { + return null; + } + Iterator itr = Arrays.stream(id.split("/")).iterator(); + while (itr.hasNext()) { + String part = itr.next(); + if (part != null && !part.trim().isEmpty()) { + if (part.equalsIgnoreCase(name)) { + if (itr.hasNext()) { + return itr.next(); + } else { + return null; + } + } + } + } + return null; + } + + static String getValueFromIdByParameterName(String id, String pathTemplate, String parameterName) { + if (id == null || pathTemplate == null) { + return null; + } + String parameterNameParentheses = "{" + parameterName + "}"; + List idSegmentsReverted = Arrays.asList(id.split("/")); + List pathSegments = Arrays.asList(pathTemplate.split("/")); + Collections.reverse(idSegmentsReverted); + Iterator idItrReverted = idSegmentsReverted.iterator(); + int pathIndex = pathSegments.size(); + while (idItrReverted.hasNext() && pathIndex > 0) { + String idSegment = idItrReverted.next(); + String pathSegment = pathSegments.get(--pathIndex); + if (!CoreUtils.isNullOrEmpty(idSegment) && !CoreUtils.isNullOrEmpty(pathSegment)) { + if (pathSegment.equalsIgnoreCase(parameterNameParentheses)) { + if (pathIndex == 0 || (pathIndex == 1 && pathSegments.get(0).isEmpty())) { + List segments = new ArrayList<>(); + segments.add(idSegment); + idItrReverted.forEachRemaining(segments::add); + Collections.reverse(segments); + if (!segments.isEmpty() && segments.get(0).isEmpty()) { + segments.remove(0); + } + return String.join("/", segments); + } else { + return idSegment; + } + } + } + } + return null; + } + + static PagedIterable mapPage(PagedIterable pageIterable, Function mapper) { + return new PagedIterableImpl<>(pageIterable, mapper); + } + + private static final class PagedIterableImpl extends PagedIterable { + + private final PagedIterable pagedIterable; + private final Function mapper; + private final Function, PagedResponse> pageMapper; + + private PagedIterableImpl(PagedIterable pagedIterable, Function mapper) { + super(PagedFlux.create(() -> (continuationToken, pageSize) -> Flux + .fromStream(pagedIterable.streamByPage().map(getPageMapper(mapper))))); + this.pagedIterable = pagedIterable; + this.mapper = mapper; + this.pageMapper = getPageMapper(mapper); + } + + private static Function, PagedResponse> getPageMapper(Function mapper) { + return page -> new PagedResponseBase(page.getRequest(), page.getStatusCode(), page.getHeaders(), + page.getElements().stream().map(mapper).collect(Collectors.toList()), page.getContinuationToken(), + null); + } + + @Override + public Stream stream() { + return pagedIterable.stream().map(mapper); + } + + @Override + public Stream> streamByPage() { + return pagedIterable.streamByPage().map(pageMapper); + } + + @Override + public Stream> streamByPage(String continuationToken) { + return pagedIterable.streamByPage(continuationToken).map(pageMapper); + } + + @Override + public Stream> streamByPage(int preferredPageSize) { + return pagedIterable.streamByPage(preferredPageSize).map(pageMapper); + } + + @Override + public Stream> streamByPage(String continuationToken, int preferredPageSize) { + return pagedIterable.streamByPage(continuationToken, preferredPageSize).map(pageMapper); + } + + @Override + public Iterator iterator() { + return new IteratorImpl<>(pagedIterable.iterator(), mapper); + } + + @Override + public Iterable> iterableByPage() { + return new IterableImpl<>(pagedIterable.iterableByPage(), pageMapper); + } + + @Override + public Iterable> iterableByPage(String continuationToken) { + return new IterableImpl<>(pagedIterable.iterableByPage(continuationToken), pageMapper); + } + + @Override + public Iterable> iterableByPage(int preferredPageSize) { + return new IterableImpl<>(pagedIterable.iterableByPage(preferredPageSize), pageMapper); + } + + @Override + public Iterable> iterableByPage(String continuationToken, int preferredPageSize) { + return new IterableImpl<>(pagedIterable.iterableByPage(continuationToken, preferredPageSize), pageMapper); + } + } + + private static final class IteratorImpl implements Iterator { + + private final Iterator iterator; + private final Function mapper; + + private IteratorImpl(Iterator iterator, Function mapper) { + this.iterator = iterator; + this.mapper = mapper; + } + + @Override + public boolean hasNext() { + return iterator.hasNext(); + } + + @Override + public S next() { + return mapper.apply(iterator.next()); + } + + @Override + public void remove() { + iterator.remove(); + } + } + + private static final class IterableImpl implements Iterable { + + private final Iterable iterable; + private final Function mapper; + + private IterableImpl(Iterable iterable, Function mapper) { + this.iterable = iterable; + this.mapper = mapper; + } + + @Override + public Iterator iterator() { + return new IteratorImpl<>(iterable.iterator(), mapper); + } + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/StorageAccountImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/StorageAccountImpl.java new file mode 100644 index 0000000000..23ec341363 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/StorageAccountImpl.java @@ -0,0 +1,165 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.implementation; + +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.StorageAccountInner; +import azure.resourcemanager.multiservicesharedmodels.combined.models.StorageAccount; +import azure.resourcemanager.multiservicesharedmodels.combined.models.StorageAccountProperties; +import com.azure.core.management.Region; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; +import java.util.Collections; +import java.util.Map; + +public final class StorageAccountImpl implements StorageAccount, StorageAccount.Definition, StorageAccount.Update { + private StorageAccountInner innerObject; + + private final azure.resourcemanager.multiservicesharedmodels.combined.CombinedManager serviceManager; + + public String id() { + return this.innerModel().id(); + } + + public String name() { + return this.innerModel().name(); + } + + public String type() { + return this.innerModel().type(); + } + + public String location() { + return this.innerModel().location(); + } + + public Map tags() { + Map inner = this.innerModel().tags(); + if (inner != null) { + return Collections.unmodifiableMap(inner); + } else { + return Collections.emptyMap(); + } + } + + public StorageAccountProperties properties() { + return this.innerModel().properties(); + } + + public SystemData systemData() { + return this.innerModel().systemData(); + } + + public Region region() { + return Region.fromName(this.regionName()); + } + + public String regionName() { + return this.location(); + } + + public String resourceGroupName() { + return resourceGroupName; + } + + public StorageAccountInner innerModel() { + return this.innerObject; + } + + private azure.resourcemanager.multiservicesharedmodels.combined.CombinedManager manager() { + return this.serviceManager; + } + + private String resourceGroupName; + + private String accountName; + + public StorageAccountImpl withExistingResourceGroup(String resourceGroupName) { + this.resourceGroupName = resourceGroupName; + return this; + } + + public StorageAccount create() { + this.innerObject = serviceManager.serviceClient() + .getStorageAccounts() + .createOrUpdate(resourceGroupName, accountName, this.innerModel(), Context.NONE); + return this; + } + + public StorageAccount create(Context context) { + this.innerObject = serviceManager.serviceClient() + .getStorageAccounts() + .createOrUpdate(resourceGroupName, accountName, this.innerModel(), context); + return this; + } + + StorageAccountImpl(String name, + azure.resourcemanager.multiservicesharedmodels.combined.CombinedManager serviceManager) { + this.innerObject = new StorageAccountInner(); + this.serviceManager = serviceManager; + this.accountName = name; + } + + public StorageAccountImpl update() { + return this; + } + + public StorageAccount apply() { + this.innerObject = serviceManager.serviceClient() + .getStorageAccounts() + .createOrUpdate(resourceGroupName, accountName, this.innerModel(), Context.NONE); + return this; + } + + public StorageAccount apply(Context context) { + this.innerObject = serviceManager.serviceClient() + .getStorageAccounts() + .createOrUpdate(resourceGroupName, accountName, this.innerModel(), context); + return this; + } + + StorageAccountImpl(StorageAccountInner innerObject, + azure.resourcemanager.multiservicesharedmodels.combined.CombinedManager serviceManager) { + this.innerObject = innerObject; + this.serviceManager = serviceManager; + this.resourceGroupName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "resourceGroups"); + this.accountName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "storageAccounts"); + } + + public StorageAccount refresh() { + this.innerObject = serviceManager.serviceClient() + .getStorageAccounts() + .getByResourceGroupWithResponse(resourceGroupName, accountName, Context.NONE) + .getValue(); + return this; + } + + public StorageAccount refresh(Context context) { + this.innerObject = serviceManager.serviceClient() + .getStorageAccounts() + .getByResourceGroupWithResponse(resourceGroupName, accountName, context) + .getValue(); + return this; + } + + public StorageAccountImpl withRegion(Region location) { + this.innerModel().withLocation(location.toString()); + return this; + } + + public StorageAccountImpl withRegion(String location) { + this.innerModel().withLocation(location); + return this; + } + + public StorageAccountImpl withTags(Map tags) { + this.innerModel().withTags(tags); + return this; + } + + public StorageAccountImpl withProperties(StorageAccountProperties properties) { + this.innerModel().withProperties(properties); + return this; + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/StorageAccountsClientImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/StorageAccountsClientImpl.java new file mode 100644 index 0000000000..50cba1bf45 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/StorageAccountsClientImpl.java @@ -0,0 +1,353 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.implementation; + +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.StorageAccountsClient; +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.StorageAccountInner; +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Headers; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Put; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.polling.SyncPoller; +import java.nio.ByteBuffer; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in StorageAccountsClient. + */ +public final class StorageAccountsClientImpl implements StorageAccountsClient { + /** + * The proxy service used to perform REST calls. + */ + private final StorageAccountsService service; + + /** + * The service client containing this operation class. + */ + private final CombinedImpl client; + + /** + * Initializes an instance of StorageAccountsClientImpl. + * + * @param client the instance of the service client containing this operation class. + */ + StorageAccountsClientImpl(CombinedImpl client) { + this.service + = RestProxy.create(StorageAccountsService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for CombinedStorageAccounts to be used by the proxy service to perform + * REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "CombinedStorageAccounts") + public interface StorageAccountsService { + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/storageAccounts/{accountName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> getByResourceGroup(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("accountName") String accountName, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/storageAccounts/{accountName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response getByResourceGroupSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("accountName") String accountName, + @HeaderParam("Accept") String accept, Context context); + + @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/storageAccounts/{accountName}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono>> createOrUpdate(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("accountName") String accountName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") StorageAccountInner resource, Context context); + + @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/storageAccounts/{accountName}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response createOrUpdateSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("accountName") String accountName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") StorageAccountInner resource, Context context); + } + + /** + * Gets information about a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a storage account along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> getByResourceGroupWithResponseAsync(String resourceGroupName, + String accountName) { + final String apiVersion = "2025-02-01"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.getByResourceGroup(this.client.getEndpoint(), apiVersion, + this.client.getSubscriptionId(), resourceGroupName, accountName, accept, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Gets information about a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a storage account on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono getByResourceGroupAsync(String resourceGroupName, String accountName) { + return getByResourceGroupWithResponseAsync(resourceGroupName, accountName) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Gets information about a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a storage account along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getByResourceGroupWithResponse(String resourceGroupName, String accountName, + Context context) { + final String apiVersion = "2025-02-01"; + final String accept = "application/json"; + return service.getByResourceGroupSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, accountName, accept, context); + } + + /** + * Gets information about a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a storage account. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public StorageAccountInner getByResourceGroup(String resourceGroupName, String accountName) { + return getByResourceGroupWithResponse(resourceGroupName, accountName, Context.NONE).getValue(); + } + + /** + * Creates or updates a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return storage account resource along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono>> createOrUpdateWithResponseAsync(String resourceGroupName, + String accountName, StorageAccountInner resource) { + final String apiVersion = "2025-02-01"; + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil.withContext(context -> service.createOrUpdate(this.client.getEndpoint(), apiVersion, + this.client.getSubscriptionId(), resourceGroupName, accountName, contentType, accept, resource, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Creates or updates a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return storage account resource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Response createOrUpdateWithResponse(String resourceGroupName, String accountName, + StorageAccountInner resource) { + final String apiVersion = "2025-02-01"; + final String contentType = "application/json"; + final String accept = "application/json"; + return service.createOrUpdateSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, accountName, contentType, accept, resource, Context.NONE); + } + + /** + * Creates or updates a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return storage account resource along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Response createOrUpdateWithResponse(String resourceGroupName, String accountName, + StorageAccountInner resource, Context context) { + final String apiVersion = "2025-02-01"; + final String contentType = "application/json"; + final String accept = "application/json"; + return service.createOrUpdateSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, accountName, contentType, accept, resource, context); + } + + /** + * Creates or updates a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of storage account resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, StorageAccountInner> + beginCreateOrUpdateAsync(String resourceGroupName, String accountName, StorageAccountInner resource) { + Mono>> mono + = createOrUpdateWithResponseAsync(resourceGroupName, accountName, resource); + return this.client.getLroResult(mono, this.client.getHttpPipeline(), + StorageAccountInner.class, StorageAccountInner.class, this.client.getContext()); + } + + /** + * Creates or updates a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of storage account resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, StorageAccountInner> + beginCreateOrUpdate(String resourceGroupName, String accountName, StorageAccountInner resource) { + Response response = createOrUpdateWithResponse(resourceGroupName, accountName, resource); + return this.client.getLroResult(response, StorageAccountInner.class, + StorageAccountInner.class, Context.NONE); + } + + /** + * Creates or updates a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of storage account resource. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, StorageAccountInner> beginCreateOrUpdate( + String resourceGroupName, String accountName, StorageAccountInner resource, Context context) { + Response response = createOrUpdateWithResponse(resourceGroupName, accountName, resource, context); + return this.client.getLroResult(response, StorageAccountInner.class, + StorageAccountInner.class, context); + } + + /** + * Creates or updates a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return storage account resource on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono createOrUpdateAsync(String resourceGroupName, String accountName, + StorageAccountInner resource) { + return beginCreateOrUpdateAsync(resourceGroupName, accountName, resource).last() + .flatMap(this.client::getLroFinalResultOrError); + } + + /** + * Creates or updates a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return storage account resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public StorageAccountInner createOrUpdate(String resourceGroupName, String accountName, + StorageAccountInner resource) { + return beginCreateOrUpdate(resourceGroupName, accountName, resource).getFinalResult(); + } + + /** + * Creates or updates a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return storage account resource. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public StorageAccountInner createOrUpdate(String resourceGroupName, String accountName, + StorageAccountInner resource, Context context) { + return beginCreateOrUpdate(resourceGroupName, accountName, resource, context).getFinalResult(); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/StorageAccountsImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/StorageAccountsImpl.java new file mode 100644 index 0000000000..bbf7e7bf70 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/StorageAccountsImpl.java @@ -0,0 +1,89 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.implementation; + +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.StorageAccountsClient; +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.StorageAccountInner; +import azure.resourcemanager.multiservicesharedmodels.combined.models.StorageAccount; +import azure.resourcemanager.multiservicesharedmodels.combined.models.StorageAccounts; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.util.Context; +import com.azure.core.util.logging.ClientLogger; + +public final class StorageAccountsImpl implements StorageAccounts { + private static final ClientLogger LOGGER = new ClientLogger(StorageAccountsImpl.class); + + private final StorageAccountsClient innerClient; + + private final azure.resourcemanager.multiservicesharedmodels.combined.CombinedManager serviceManager; + + public StorageAccountsImpl(StorageAccountsClient innerClient, + azure.resourcemanager.multiservicesharedmodels.combined.CombinedManager serviceManager) { + this.innerClient = innerClient; + this.serviceManager = serviceManager; + } + + public Response getByResourceGroupWithResponse(String resourceGroupName, String accountName, + Context context) { + Response inner + = this.serviceClient().getByResourceGroupWithResponse(resourceGroupName, accountName, context); + if (inner != null) { + return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(), + new StorageAccountImpl(inner.getValue(), this.manager())); + } else { + return null; + } + } + + public StorageAccount getByResourceGroup(String resourceGroupName, String accountName) { + StorageAccountInner inner = this.serviceClient().getByResourceGroup(resourceGroupName, accountName); + if (inner != null) { + return new StorageAccountImpl(inner, this.manager()); + } else { + return null; + } + } + + public StorageAccount getById(String id) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String accountName = ResourceManagerUtils.getValueFromIdByName(id, "storageAccounts"); + if (accountName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'storageAccounts'.", id))); + } + return this.getByResourceGroupWithResponse(resourceGroupName, accountName, Context.NONE).getValue(); + } + + public Response getByIdWithResponse(String id, Context context) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String accountName = ResourceManagerUtils.getValueFromIdByName(id, "storageAccounts"); + if (accountName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'storageAccounts'.", id))); + } + return this.getByResourceGroupWithResponse(resourceGroupName, accountName, context); + } + + private StorageAccountsClient serviceClient() { + return this.innerClient; + } + + private azure.resourcemanager.multiservicesharedmodels.combined.CombinedManager manager() { + return this.serviceManager; + } + + public StorageAccountImpl define(String name) { + return new StorageAccountImpl(name, this.manager()); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/VirtualMachineImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/VirtualMachineImpl.java new file mode 100644 index 0000000000..7c016abac5 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/VirtualMachineImpl.java @@ -0,0 +1,165 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.implementation; + +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.VirtualMachineInner; +import azure.resourcemanager.multiservicesharedmodels.combined.models.VirtualMachine; +import azure.resourcemanager.multiservicesharedmodels.combined.models.VirtualMachineProperties; +import com.azure.core.management.Region; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; +import java.util.Collections; +import java.util.Map; + +public final class VirtualMachineImpl implements VirtualMachine, VirtualMachine.Definition, VirtualMachine.Update { + private VirtualMachineInner innerObject; + + private final azure.resourcemanager.multiservicesharedmodels.combined.CombinedManager serviceManager; + + public String id() { + return this.innerModel().id(); + } + + public String name() { + return this.innerModel().name(); + } + + public String type() { + return this.innerModel().type(); + } + + public String location() { + return this.innerModel().location(); + } + + public Map tags() { + Map inner = this.innerModel().tags(); + if (inner != null) { + return Collections.unmodifiableMap(inner); + } else { + return Collections.emptyMap(); + } + } + + public VirtualMachineProperties properties() { + return this.innerModel().properties(); + } + + public SystemData systemData() { + return this.innerModel().systemData(); + } + + public Region region() { + return Region.fromName(this.regionName()); + } + + public String regionName() { + return this.location(); + } + + public String resourceGroupName() { + return resourceGroupName; + } + + public VirtualMachineInner innerModel() { + return this.innerObject; + } + + private azure.resourcemanager.multiservicesharedmodels.combined.CombinedManager manager() { + return this.serviceManager; + } + + private String resourceGroupName; + + private String vmName; + + public VirtualMachineImpl withExistingResourceGroup(String resourceGroupName) { + this.resourceGroupName = resourceGroupName; + return this; + } + + public VirtualMachine create() { + this.innerObject = serviceManager.serviceClient() + .getVirtualMachines() + .createOrUpdate(resourceGroupName, vmName, this.innerModel(), Context.NONE); + return this; + } + + public VirtualMachine create(Context context) { + this.innerObject = serviceManager.serviceClient() + .getVirtualMachines() + .createOrUpdate(resourceGroupName, vmName, this.innerModel(), context); + return this; + } + + VirtualMachineImpl(String name, + azure.resourcemanager.multiservicesharedmodels.combined.CombinedManager serviceManager) { + this.innerObject = new VirtualMachineInner(); + this.serviceManager = serviceManager; + this.vmName = name; + } + + public VirtualMachineImpl update() { + return this; + } + + public VirtualMachine apply() { + this.innerObject = serviceManager.serviceClient() + .getVirtualMachines() + .createOrUpdate(resourceGroupName, vmName, this.innerModel(), Context.NONE); + return this; + } + + public VirtualMachine apply(Context context) { + this.innerObject = serviceManager.serviceClient() + .getVirtualMachines() + .createOrUpdate(resourceGroupName, vmName, this.innerModel(), context); + return this; + } + + VirtualMachineImpl(VirtualMachineInner innerObject, + azure.resourcemanager.multiservicesharedmodels.combined.CombinedManager serviceManager) { + this.innerObject = innerObject; + this.serviceManager = serviceManager; + this.resourceGroupName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "resourceGroups"); + this.vmName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "virtualMachinesShared"); + } + + public VirtualMachine refresh() { + this.innerObject = serviceManager.serviceClient() + .getVirtualMachines() + .getByResourceGroupWithResponse(resourceGroupName, vmName, Context.NONE) + .getValue(); + return this; + } + + public VirtualMachine refresh(Context context) { + this.innerObject = serviceManager.serviceClient() + .getVirtualMachines() + .getByResourceGroupWithResponse(resourceGroupName, vmName, context) + .getValue(); + return this; + } + + public VirtualMachineImpl withRegion(Region location) { + this.innerModel().withLocation(location.toString()); + return this; + } + + public VirtualMachineImpl withRegion(String location) { + this.innerModel().withLocation(location); + return this; + } + + public VirtualMachineImpl withTags(Map tags) { + this.innerModel().withTags(tags); + return this; + } + + public VirtualMachineImpl withProperties(VirtualMachineProperties properties) { + this.innerModel().withProperties(properties); + return this; + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/VirtualMachinesClientImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/VirtualMachinesClientImpl.java new file mode 100644 index 0000000000..5b974be3c0 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/VirtualMachinesClientImpl.java @@ -0,0 +1,361 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.implementation; + +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.VirtualMachinesClient; +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.VirtualMachineInner; +import com.azure.core.annotation.BodyParam; +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.HeaderParam; +import com.azure.core.annotation.Headers; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.PathParam; +import com.azure.core.annotation.Put; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.management.exception.ManagementException; +import com.azure.core.management.polling.PollResult; +import com.azure.core.util.BinaryData; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import com.azure.core.util.polling.PollerFlux; +import com.azure.core.util.polling.SyncPoller; +import java.nio.ByteBuffer; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +/** + * An instance of this class provides access to all the operations defined in VirtualMachinesClient. + */ +public final class VirtualMachinesClientImpl implements VirtualMachinesClient { + /** + * The proxy service used to perform REST calls. + */ + private final VirtualMachinesService service; + + /** + * The service client containing this operation class. + */ + private final CombinedImpl client; + + /** + * Initializes an instance of VirtualMachinesClientImpl. + * + * @param client the instance of the service client containing this operation class. + */ + VirtualMachinesClientImpl(CombinedImpl client) { + this.service + = RestProxy.create(VirtualMachinesService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * The interface defining all the services for CombinedVirtualMachines to be used by the proxy service to perform + * REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "CombinedVirtualMachines") + public interface VirtualMachinesService { + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachinesShared/{vmName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono> getByResourceGroup(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("vmName") String vmName, + @HeaderParam("Accept") String accept, Context context); + + @Headers({ "Content-Type: application/json" }) + @Get("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachinesShared/{vmName}") + @ExpectedResponses({ 200 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response getByResourceGroupSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("vmName") String vmName, + @HeaderParam("Accept") String accept, Context context); + + @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachinesShared/{vmName}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Mono>> createOrUpdate(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("vmName") String vmName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") VirtualMachineInner resource, Context context); + + @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Compute/virtualMachinesShared/{vmName}") + @ExpectedResponses({ 200, 201 }) + @UnexpectedResponseExceptionType(ManagementException.class) + Response createOrUpdateSync(@HostParam("endpoint") String endpoint, + @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId, + @PathParam("resourceGroupName") String resourceGroupName, @PathParam("vmName") String vmName, + @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept, + @BodyParam("application/json") VirtualMachineInner resource, Context context); + } + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono> getByResourceGroupWithResponseAsync(String resourceGroupName, + String vmName) { + final String apiVersion = "2025-05-01"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.getByResourceGroup(this.client.getEndpoint(), apiVersion, + this.client.getSubscriptionId(), resourceGroupName, vmName, accept, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono getByResourceGroupAsync(String resourceGroupName, String vmName) { + return getByResourceGroupWithResponseAsync(resourceGroupName, vmName) + .flatMap(res -> Mono.justOrEmpty(res.getValue())); + } + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response getByResourceGroupWithResponse(String resourceGroupName, String vmName, + Context context) { + final String apiVersion = "2025-05-01"; + final String accept = "application/json"; + return service.getByResourceGroupSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, vmName, accept, context); + } + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public VirtualMachineInner getByResourceGroup(String resourceGroupName, String vmName) { + return getByResourceGroupWithResponse(resourceGroupName, vmName, Context.NONE).getValue(); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono>> createOrUpdateWithResponseAsync(String resourceGroupName, String vmName, + VirtualMachineInner resource) { + final String apiVersion = "2025-05-01"; + final String contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), apiVersion, + this.client.getSubscriptionId(), resourceGroupName, vmName, contentType, accept, resource, context)) + .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly())); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Response createOrUpdateWithResponse(String resourceGroupName, String vmName, + VirtualMachineInner resource) { + final String apiVersion = "2025-05-01"; + final String contentType = "application/json"; + final String accept = "application/json"; + return service.createOrUpdateSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, vmName, contentType, accept, resource, Context.NONE); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Response createOrUpdateWithResponse(String resourceGroupName, String vmName, + VirtualMachineInner resource, Context context) { + final String apiVersion = "2025-05-01"; + final String contentType = "application/json"; + final String accept = "application/json"; + return service.createOrUpdateSync(this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), + resourceGroupName, vmName, contentType, accept, resource, context); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link PollerFlux} for polling of describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + private PollerFlux, VirtualMachineInner> + beginCreateOrUpdateAsync(String resourceGroupName, String vmName, VirtualMachineInner resource) { + Mono>> mono = createOrUpdateWithResponseAsync(resourceGroupName, vmName, resource); + return this.client.getLroResult(mono, this.client.getHttpPipeline(), + VirtualMachineInner.class, VirtualMachineInner.class, this.client.getContext()); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, VirtualMachineInner> + beginCreateOrUpdate(String resourceGroupName, String vmName, VirtualMachineInner resource) { + Response response = createOrUpdateWithResponse(resourceGroupName, vmName, resource); + return this.client.getLroResult(response, VirtualMachineInner.class, + VirtualMachineInner.class, Context.NONE); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return the {@link SyncPoller} for polling of describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION) + public SyncPoller, VirtualMachineInner> + beginCreateOrUpdate(String resourceGroupName, String vmName, VirtualMachineInner resource, Context context) { + Response response = createOrUpdateWithResponse(resourceGroupName, vmName, resource, context); + return this.client.getLroResult(response, VirtualMachineInner.class, + VirtualMachineInner.class, context); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + private Mono createOrUpdateAsync(String resourceGroupName, String vmName, + VirtualMachineInner resource) { + return beginCreateOrUpdateAsync(resourceGroupName, vmName, resource).last() + .flatMap(this.client::getLroFinalResultOrError); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public VirtualMachineInner createOrUpdate(String resourceGroupName, String vmName, VirtualMachineInner resource) { + return beginCreateOrUpdate(resourceGroupName, vmName, resource).getFinalResult(); + } + + /** + * The operation to create or update a virtual machine. Please note some properties can be set only during virtual + * machine creation. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param resource Resource create parameters. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public VirtualMachineInner createOrUpdate(String resourceGroupName, String vmName, VirtualMachineInner resource, + Context context) { + return beginCreateOrUpdate(resourceGroupName, vmName, resource, context).getFinalResult(); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/VirtualMachinesImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/VirtualMachinesImpl.java new file mode 100644 index 0000000000..617de063fc --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/VirtualMachinesImpl.java @@ -0,0 +1,89 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.implementation; + +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.VirtualMachinesClient; +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.VirtualMachineInner; +import azure.resourcemanager.multiservicesharedmodels.combined.models.VirtualMachine; +import azure.resourcemanager.multiservicesharedmodels.combined.models.VirtualMachines; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.SimpleResponse; +import com.azure.core.util.Context; +import com.azure.core.util.logging.ClientLogger; + +public final class VirtualMachinesImpl implements VirtualMachines { + private static final ClientLogger LOGGER = new ClientLogger(VirtualMachinesImpl.class); + + private final VirtualMachinesClient innerClient; + + private final azure.resourcemanager.multiservicesharedmodels.combined.CombinedManager serviceManager; + + public VirtualMachinesImpl(VirtualMachinesClient innerClient, + azure.resourcemanager.multiservicesharedmodels.combined.CombinedManager serviceManager) { + this.innerClient = innerClient; + this.serviceManager = serviceManager; + } + + public Response getByResourceGroupWithResponse(String resourceGroupName, String vmName, + Context context) { + Response inner + = this.serviceClient().getByResourceGroupWithResponse(resourceGroupName, vmName, context); + if (inner != null) { + return new SimpleResponse<>(inner.getRequest(), inner.getStatusCode(), inner.getHeaders(), + new VirtualMachineImpl(inner.getValue(), this.manager())); + } else { + return null; + } + } + + public VirtualMachine getByResourceGroup(String resourceGroupName, String vmName) { + VirtualMachineInner inner = this.serviceClient().getByResourceGroup(resourceGroupName, vmName); + if (inner != null) { + return new VirtualMachineImpl(inner, this.manager()); + } else { + return null; + } + } + + public VirtualMachine getById(String id) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String vmName = ResourceManagerUtils.getValueFromIdByName(id, "virtualMachinesShared"); + if (vmName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'virtualMachinesShared'.", id))); + } + return this.getByResourceGroupWithResponse(resourceGroupName, vmName, Context.NONE).getValue(); + } + + public Response getByIdWithResponse(String id, Context context) { + String resourceGroupName = ResourceManagerUtils.getValueFromIdByName(id, "resourceGroups"); + if (resourceGroupName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'resourceGroups'.", id))); + } + String vmName = ResourceManagerUtils.getValueFromIdByName(id, "virtualMachinesShared"); + if (vmName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'virtualMachinesShared'.", id))); + } + return this.getByResourceGroupWithResponse(resourceGroupName, vmName, context); + } + + private VirtualMachinesClient serviceClient() { + return this.innerClient; + } + + private azure.resourcemanager.multiservicesharedmodels.combined.CombinedManager manager() { + return this.serviceManager; + } + + public VirtualMachineImpl define(String name) { + return new VirtualMachineImpl(name, this.manager()); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/package-info.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/package-info.java new file mode 100644 index 0000000000..df86a335ec --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the implementations for Compute. + * Compute Client. + */ +package azure.resourcemanager.multiservicesharedmodels.combined.implementation; diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/ResourceProvisioningState.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/ResourceProvisioningState.java new file mode 100644 index 0000000000..b50a53727b --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/ResourceProvisioningState.java @@ -0,0 +1,56 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.models; + +import com.azure.core.util.ExpandableStringEnum; +import java.util.Collection; + +/** + * The provisioning state of a resource type. + */ +public final class ResourceProvisioningState extends ExpandableStringEnum { + /** + * Resource has been created. + */ + public static final ResourceProvisioningState SUCCEEDED = fromString("Succeeded"); + + /** + * Resource creation failed. + */ + public static final ResourceProvisioningState FAILED = fromString("Failed"); + + /** + * Resource creation was canceled. + */ + public static final ResourceProvisioningState CANCELED = fromString("Canceled"); + + /** + * Creates a new instance of ResourceProvisioningState value. + * + * @deprecated Use the {@link #fromString(String)} factory method. + */ + @Deprecated + public ResourceProvisioningState() { + } + + /** + * Creates or finds a ResourceProvisioningState from its string representation. + * + * @param name a name to look for. + * @return the corresponding ResourceProvisioningState. + */ + public static ResourceProvisioningState fromString(String name) { + return fromString(name, ResourceProvisioningState.class); + } + + /** + * Gets known ResourceProvisioningState values. + * + * @return known ResourceProvisioningState values. + */ + public static Collection values() { + return values(ResourceProvisioningState.class); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/SharedMetadata.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/SharedMetadata.java new file mode 100644 index 0000000000..ebaaac5882 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/SharedMetadata.java @@ -0,0 +1,148 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.models; + +import com.azure.core.annotation.Fluent; +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.Map; + +/** + * Common metadata shared across multiple services. + */ +@Fluent +public final class SharedMetadata implements JsonSerializable { + /* + * Creation timestamp of the resource. + */ + private OffsetDateTime createdAt; + + /* + * Creator of the resource. + */ + private String createdBy; + + /* + * Tags associated with the resource. + */ + private Map tags; + + /** + * Creates an instance of SharedMetadata class. + */ + public SharedMetadata() { + } + + /** + * Get the createdAt property: Creation timestamp of the resource. + * + * @return the createdAt value. + */ + public OffsetDateTime createdAt() { + return this.createdAt; + } + + /** + * Set the createdAt property: Creation timestamp of the resource. + * + * @param createdAt the createdAt value to set. + * @return the SharedMetadata object itself. + */ + public SharedMetadata withCreatedAt(OffsetDateTime createdAt) { + this.createdAt = createdAt; + return this; + } + + /** + * Get the createdBy property: Creator of the resource. + * + * @return the createdBy value. + */ + public String createdBy() { + return this.createdBy; + } + + /** + * Set the createdBy property: Creator of the resource. + * + * @param createdBy the createdBy value to set. + * @return the SharedMetadata object itself. + */ + public SharedMetadata withCreatedBy(String createdBy) { + this.createdBy = createdBy; + return this; + } + + /** + * Get the tags property: Tags associated with the resource. + * + * @return the tags value. + */ + public Map tags() { + return this.tags; + } + + /** + * Set the tags property: Tags associated with the resource. + * + * @param tags the tags value to set. + * @return the SharedMetadata object itself. + */ + public SharedMetadata withTags(Map tags) { + this.tags = tags; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeStringField("createdAt", + this.createdAt == null ? null : DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(this.createdAt)); + jsonWriter.writeStringField("createdBy", this.createdBy); + jsonWriter.writeMapField("tags", this.tags, (writer, element) -> writer.writeString(element)); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of SharedMetadata from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of SharedMetadata 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 SharedMetadata. + */ + public static SharedMetadata fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + SharedMetadata deserializedSharedMetadata = new SharedMetadata(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("createdAt".equals(fieldName)) { + deserializedSharedMetadata.createdAt = reader + .getNullable(nonNullReader -> CoreUtils.parseBestOffsetDateTime(nonNullReader.getString())); + } else if ("createdBy".equals(fieldName)) { + deserializedSharedMetadata.createdBy = reader.getString(); + } else if ("tags".equals(fieldName)) { + Map tags = reader.readMap(reader1 -> reader1.getString()); + deserializedSharedMetadata.tags = tags; + } else { + reader.skipChildren(); + } + } + + return deserializedSharedMetadata; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/StorageAccount.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/StorageAccount.java new file mode 100644 index 0000000000..b3456c74a4 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/StorageAccount.java @@ -0,0 +1,265 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.models; + +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.StorageAccountInner; +import com.azure.core.management.Region; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; +import java.util.Map; + +/** + * An immutable client-side representation of StorageAccount. + */ +public interface StorageAccount { + /** + * Gets the id property: Fully qualified resource Id for the resource. + * + * @return the id value. + */ + String id(); + + /** + * Gets the name property: The name of the resource. + * + * @return the name value. + */ + String name(); + + /** + * Gets the type property: The type of the resource. + * + * @return the type value. + */ + String type(); + + /** + * Gets the location property: The geo-location where the resource lives. + * + * @return the location value. + */ + String location(); + + /** + * Gets the tags property: Resource tags. + * + * @return the tags value. + */ + Map tags(); + + /** + * Gets the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + StorageAccountProperties properties(); + + /** + * Gets the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + SystemData systemData(); + + /** + * Gets the region of the resource. + * + * @return the region of the resource. + */ + Region region(); + + /** + * Gets the name of the resource region. + * + * @return the name of the resource region. + */ + String regionName(); + + /** + * Gets the name of the resource group. + * + * @return the name of the resource group. + */ + String resourceGroupName(); + + /** + * Gets the inner azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.StorageAccountInner object. + * + * @return the inner object. + */ + StorageAccountInner innerModel(); + + /** + * The entirety of the StorageAccount definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithLocation, + DefinitionStages.WithResourceGroup, DefinitionStages.WithCreate { + } + + /** + * The StorageAccount definition stages. + */ + interface DefinitionStages { + /** + * The first stage of the StorageAccount definition. + */ + interface Blank extends WithLocation { + } + + /** + * The stage of the StorageAccount definition allowing to specify location. + */ + interface WithLocation { + /** + * Specifies the region for the resource. + * + * @param location The geo-location where the resource lives. + * @return the next definition stage. + */ + WithResourceGroup withRegion(Region location); + + /** + * Specifies the region for the resource. + * + * @param location The geo-location where the resource lives. + * @return the next definition stage. + */ + WithResourceGroup withRegion(String location); + } + + /** + * The stage of the StorageAccount definition allowing to specify parent resource. + */ + interface WithResourceGroup { + /** + * Specifies resourceGroupName. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @return the next definition stage. + */ + WithCreate withExistingResourceGroup(String resourceGroupName); + } + + /** + * The stage of the StorageAccount definition which contains all the minimum required properties for the + * resource to be created, but also allows for any other optional properties to be specified. + */ + interface WithCreate extends DefinitionStages.WithTags, DefinitionStages.WithProperties { + /** + * Executes the create request. + * + * @return the created resource. + */ + StorageAccount create(); + + /** + * Executes the create request. + * + * @param context The context to associate with this operation. + * @return the created resource. + */ + StorageAccount create(Context context); + } + + /** + * The stage of the StorageAccount definition allowing to specify tags. + */ + interface WithTags { + /** + * Specifies the tags property: Resource tags.. + * + * @param tags Resource tags. + * @return the next definition stage. + */ + WithCreate withTags(Map tags); + } + + /** + * The stage of the StorageAccount definition allowing to specify properties. + */ + interface WithProperties { + /** + * Specifies the properties property: The resource-specific properties for this resource.. + * + * @param properties The resource-specific properties for this resource. + * @return the next definition stage. + */ + WithCreate withProperties(StorageAccountProperties properties); + } + } + + /** + * Begins update for the StorageAccount resource. + * + * @return the stage of resource update. + */ + StorageAccount.Update update(); + + /** + * The template for StorageAccount update. + */ + interface Update extends UpdateStages.WithTags, UpdateStages.WithProperties { + /** + * Executes the update request. + * + * @return the updated resource. + */ + StorageAccount apply(); + + /** + * Executes the update request. + * + * @param context The context to associate with this operation. + * @return the updated resource. + */ + StorageAccount apply(Context context); + } + + /** + * The StorageAccount update stages. + */ + interface UpdateStages { + /** + * The stage of the StorageAccount update allowing to specify tags. + */ + interface WithTags { + /** + * Specifies the tags property: Resource tags.. + * + * @param tags Resource tags. + * @return the next definition stage. + */ + Update withTags(Map tags); + } + + /** + * The stage of the StorageAccount update allowing to specify properties. + */ + interface WithProperties { + /** + * Specifies the properties property: The resource-specific properties for this resource.. + * + * @param properties The resource-specific properties for this resource. + * @return the next definition stage. + */ + Update withProperties(StorageAccountProperties properties); + } + } + + /** + * Refreshes the resource to sync with Azure. + * + * @return the refreshed resource. + */ + StorageAccount refresh(); + + /** + * Refreshes the resource to sync with Azure. + * + * @param context The context to associate with this operation. + * @return the refreshed resource. + */ + StorageAccount refresh(Context context); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/StorageAccountProperties.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/StorageAccountProperties.java new file mode 100644 index 0000000000..737ccd00f6 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/StorageAccountProperties.java @@ -0,0 +1,102 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.models; + +import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Storage account properties. + */ +@Fluent +public final class StorageAccountProperties implements JsonSerializable { + /* + * The provisioningState property. + */ + private ResourceProvisioningState provisioningState; + + /* + * Shared metadata for the storage account. + */ + private SharedMetadata metadata; + + /** + * Creates an instance of StorageAccountProperties class. + */ + public StorageAccountProperties() { + } + + /** + * Get the provisioningState property: The provisioningState property. + * + * @return the provisioningState value. + */ + public ResourceProvisioningState provisioningState() { + return this.provisioningState; + } + + /** + * Get the metadata property: Shared metadata for the storage account. + * + * @return the metadata value. + */ + public SharedMetadata metadata() { + return this.metadata; + } + + /** + * Set the metadata property: Shared metadata for the storage account. + * + * @param metadata the metadata value to set. + * @return the StorageAccountProperties object itself. + */ + public StorageAccountProperties withMetadata(SharedMetadata metadata) { + this.metadata = metadata; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("metadata", this.metadata); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of StorageAccountProperties from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of StorageAccountProperties 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 StorageAccountProperties. + */ + public static StorageAccountProperties fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + StorageAccountProperties deserializedStorageAccountProperties = new StorageAccountProperties(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("provisioningState".equals(fieldName)) { + deserializedStorageAccountProperties.provisioningState + = ResourceProvisioningState.fromString(reader.getString()); + } else if ("metadata".equals(fieldName)) { + deserializedStorageAccountProperties.metadata = SharedMetadata.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedStorageAccountProperties; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/StorageAccounts.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/StorageAccounts.java new file mode 100644 index 0000000000..e2cfe55474 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/StorageAccounts.java @@ -0,0 +1,70 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.models; + +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; + +/** + * Resource collection API of StorageAccounts. + */ +public interface StorageAccounts { + /** + * Gets information about a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a storage account along with {@link Response}. + */ + Response getByResourceGroupWithResponse(String resourceGroupName, String accountName, + Context context); + + /** + * Gets information about a storage account. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param accountName The name of the StorageAccount. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a storage account. + */ + StorageAccount getByResourceGroup(String resourceGroupName, String accountName); + + /** + * Gets information about a storage account. + * + * @param id the resource ID. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a storage account along with {@link Response}. + */ + StorageAccount getById(String id); + + /** + * Gets information about a storage account. + * + * @param id the resource ID. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return information about a storage account along with {@link Response}. + */ + Response getByIdWithResponse(String id, Context context); + + /** + * Begins definition for a new StorageAccount resource. + * + * @param name resource name. + * @return the first stage of the new StorageAccount definition. + */ + StorageAccount.DefinitionStages.Blank define(String name); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/VirtualMachine.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/VirtualMachine.java new file mode 100644 index 0000000000..e0b4cfc980 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/VirtualMachine.java @@ -0,0 +1,265 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.models; + +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.VirtualMachineInner; +import com.azure.core.management.Region; +import com.azure.core.management.SystemData; +import com.azure.core.util.Context; +import java.util.Map; + +/** + * An immutable client-side representation of VirtualMachine. + */ +public interface VirtualMachine { + /** + * Gets the id property: Fully qualified resource Id for the resource. + * + * @return the id value. + */ + String id(); + + /** + * Gets the name property: The name of the resource. + * + * @return the name value. + */ + String name(); + + /** + * Gets the type property: The type of the resource. + * + * @return the type value. + */ + String type(); + + /** + * Gets the location property: The geo-location where the resource lives. + * + * @return the location value. + */ + String location(); + + /** + * Gets the tags property: Resource tags. + * + * @return the tags value. + */ + Map tags(); + + /** + * Gets the properties property: The resource-specific properties for this resource. + * + * @return the properties value. + */ + VirtualMachineProperties properties(); + + /** + * Gets the systemData property: Azure Resource Manager metadata containing createdBy and modifiedBy information. + * + * @return the systemData value. + */ + SystemData systemData(); + + /** + * Gets the region of the resource. + * + * @return the region of the resource. + */ + Region region(); + + /** + * Gets the name of the resource region. + * + * @return the name of the resource region. + */ + String regionName(); + + /** + * Gets the name of the resource group. + * + * @return the name of the resource group. + */ + String resourceGroupName(); + + /** + * Gets the inner azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.VirtualMachineInner object. + * + * @return the inner object. + */ + VirtualMachineInner innerModel(); + + /** + * The entirety of the VirtualMachine definition. + */ + interface Definition extends DefinitionStages.Blank, DefinitionStages.WithLocation, + DefinitionStages.WithResourceGroup, DefinitionStages.WithCreate { + } + + /** + * The VirtualMachine definition stages. + */ + interface DefinitionStages { + /** + * The first stage of the VirtualMachine definition. + */ + interface Blank extends WithLocation { + } + + /** + * The stage of the VirtualMachine definition allowing to specify location. + */ + interface WithLocation { + /** + * Specifies the region for the resource. + * + * @param location The geo-location where the resource lives. + * @return the next definition stage. + */ + WithResourceGroup withRegion(Region location); + + /** + * Specifies the region for the resource. + * + * @param location The geo-location where the resource lives. + * @return the next definition stage. + */ + WithResourceGroup withRegion(String location); + } + + /** + * The stage of the VirtualMachine definition allowing to specify parent resource. + */ + interface WithResourceGroup { + /** + * Specifies resourceGroupName. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @return the next definition stage. + */ + WithCreate withExistingResourceGroup(String resourceGroupName); + } + + /** + * The stage of the VirtualMachine definition which contains all the minimum required properties for the + * resource to be created, but also allows for any other optional properties to be specified. + */ + interface WithCreate extends DefinitionStages.WithTags, DefinitionStages.WithProperties { + /** + * Executes the create request. + * + * @return the created resource. + */ + VirtualMachine create(); + + /** + * Executes the create request. + * + * @param context The context to associate with this operation. + * @return the created resource. + */ + VirtualMachine create(Context context); + } + + /** + * The stage of the VirtualMachine definition allowing to specify tags. + */ + interface WithTags { + /** + * Specifies the tags property: Resource tags.. + * + * @param tags Resource tags. + * @return the next definition stage. + */ + WithCreate withTags(Map tags); + } + + /** + * The stage of the VirtualMachine definition allowing to specify properties. + */ + interface WithProperties { + /** + * Specifies the properties property: The resource-specific properties for this resource.. + * + * @param properties The resource-specific properties for this resource. + * @return the next definition stage. + */ + WithCreate withProperties(VirtualMachineProperties properties); + } + } + + /** + * Begins update for the VirtualMachine resource. + * + * @return the stage of resource update. + */ + VirtualMachine.Update update(); + + /** + * The template for VirtualMachine update. + */ + interface Update extends UpdateStages.WithTags, UpdateStages.WithProperties { + /** + * Executes the update request. + * + * @return the updated resource. + */ + VirtualMachine apply(); + + /** + * Executes the update request. + * + * @param context The context to associate with this operation. + * @return the updated resource. + */ + VirtualMachine apply(Context context); + } + + /** + * The VirtualMachine update stages. + */ + interface UpdateStages { + /** + * The stage of the VirtualMachine update allowing to specify tags. + */ + interface WithTags { + /** + * Specifies the tags property: Resource tags.. + * + * @param tags Resource tags. + * @return the next definition stage. + */ + Update withTags(Map tags); + } + + /** + * The stage of the VirtualMachine update allowing to specify properties. + */ + interface WithProperties { + /** + * Specifies the properties property: The resource-specific properties for this resource.. + * + * @param properties The resource-specific properties for this resource. + * @return the next definition stage. + */ + Update withProperties(VirtualMachineProperties properties); + } + } + + /** + * Refreshes the resource to sync with Azure. + * + * @return the refreshed resource. + */ + VirtualMachine refresh(); + + /** + * Refreshes the resource to sync with Azure. + * + * @param context The context to associate with this operation. + * @return the refreshed resource. + */ + VirtualMachine refresh(Context context); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/VirtualMachineProperties.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/VirtualMachineProperties.java new file mode 100644 index 0000000000..d37723f731 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/VirtualMachineProperties.java @@ -0,0 +1,102 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.models; + +import com.azure.core.annotation.Fluent; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The VirtualMachineProperties model. + */ +@Fluent +public final class VirtualMachineProperties implements JsonSerializable { + /* + * The provisioningState property. + */ + private ResourceProvisioningState provisioningState; + + /* + * Shared metadata for the virtual machine. + */ + private SharedMetadata metadata; + + /** + * Creates an instance of VirtualMachineProperties class. + */ + public VirtualMachineProperties() { + } + + /** + * Get the provisioningState property: The provisioningState property. + * + * @return the provisioningState value. + */ + public ResourceProvisioningState provisioningState() { + return this.provisioningState; + } + + /** + * Get the metadata property: Shared metadata for the virtual machine. + * + * @return the metadata value. + */ + public SharedMetadata metadata() { + return this.metadata; + } + + /** + * Set the metadata property: Shared metadata for the virtual machine. + * + * @param metadata the metadata value to set. + * @return the VirtualMachineProperties object itself. + */ + public VirtualMachineProperties withMetadata(SharedMetadata metadata) { + this.metadata = metadata; + return this; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + jsonWriter.writeJsonField("metadata", this.metadata); + return jsonWriter.writeEndObject(); + } + + /** + * Reads an instance of VirtualMachineProperties from the JsonReader. + * + * @param jsonReader The JsonReader being read. + * @return An instance of VirtualMachineProperties 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 VirtualMachineProperties. + */ + public static VirtualMachineProperties fromJson(JsonReader jsonReader) throws IOException { + return jsonReader.readObject(reader -> { + VirtualMachineProperties deserializedVirtualMachineProperties = new VirtualMachineProperties(); + while (reader.nextToken() != JsonToken.END_OBJECT) { + String fieldName = reader.getFieldName(); + reader.nextToken(); + + if ("provisioningState".equals(fieldName)) { + deserializedVirtualMachineProperties.provisioningState + = ResourceProvisioningState.fromString(reader.getString()); + } else if ("metadata".equals(fieldName)) { + deserializedVirtualMachineProperties.metadata = SharedMetadata.fromJson(reader); + } else { + reader.skipChildren(); + } + } + + return deserializedVirtualMachineProperties; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/VirtualMachines.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/VirtualMachines.java new file mode 100644 index 0000000000..4b91173eb9 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/VirtualMachines.java @@ -0,0 +1,69 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.models; + +import com.azure.core.http.rest.Response; +import com.azure.core.util.Context; + +/** + * Resource collection API of VirtualMachines. + */ +public interface VirtualMachines { + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response}. + */ + Response getByResourceGroupWithResponse(String resourceGroupName, String vmName, Context context); + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param resourceGroupName The name of the resource group. The name is case insensitive. + * @param vmName The name of the VirtualMachine. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine. + */ + VirtualMachine getByResourceGroup(String resourceGroupName, String vmName); + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param id the resource ID. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response}. + */ + VirtualMachine getById(String id); + + /** + * Retrieves information about the model view or the instance view of a virtual machine. + * + * @param id the resource ID. + * @param context The context to associate with this operation. + * @throws IllegalArgumentException thrown if parameters fail the validation. + * @throws com.azure.core.management.exception.ManagementException thrown if the request is rejected by server. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return describes a Virtual Machine along with {@link Response}. + */ + Response getByIdWithResponse(String id, Context context); + + /** + * Begins definition for a new VirtualMachine resource. + * + * @param name resource name. + * @return the first stage of the new VirtualMachine definition. + */ + VirtualMachine.DefinitionStages.Blank define(String name); +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/package-info.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/package-info.java new file mode 100644 index 0000000000..539bb429d0 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the data models for Compute. + * Compute Client. + */ +package azure.resourcemanager.multiservicesharedmodels.combined.models; diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/package-info.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/package-info.java new file mode 100644 index 0000000000..018dd4f5ee --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/package-info.java @@ -0,0 +1,9 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * Package containing the classes for Compute. + * Compute Client. + */ +package azure.resourcemanager.multiservicesharedmodels.combined; diff --git a/typespec-tests/src/main/resources/META-INF/azure-resourcemanager-combined-generated_apiview_properties_older-versions.json b/typespec-tests/src/main/resources/META-INF/azure-resourcemanager-combined-generated_apiview_properties_older-versions.json new file mode 100644 index 0000000000..002ec4e400 --- /dev/null +++ b/typespec-tests/src/main/resources/META-INF/azure-resourcemanager-combined-generated_apiview_properties_older-versions.json @@ -0,0 +1,22 @@ +{ + "flavor": "Azure", + "CrossLanguageDefinitionId": { + "azure.resourcemanager.multiserviceolderversions.combined.fluent.Combined": "Azure.ResourceManager.MultiServiceOlderVersions.Combined", + "azure.resourcemanager.multiserviceolderversions.combined.fluent.DisksClient": "Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk.Disks", + "azure.resourcemanager.multiserviceolderversions.combined.fluent.DisksClient.beginCreateOrUpdate": "Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk.Disks.createOrUpdate", + "azure.resourcemanager.multiserviceolderversions.combined.fluent.DisksClient.createOrUpdate": "Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk.Disks.createOrUpdate", + "azure.resourcemanager.multiserviceolderversions.combined.fluent.DisksClient.getByResourceGroup": "Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk.Disks.get", + "azure.resourcemanager.multiserviceolderversions.combined.fluent.DisksClient.getByResourceGroupWithResponse": "Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk.Disks.get", + "azure.resourcemanager.multiserviceolderversions.combined.fluent.VirtualMachinesClient": "Azure.ResourceManager.MultiServiceOlderVersions.Compute.VirtualMachines", + "azure.resourcemanager.multiserviceolderversions.combined.fluent.VirtualMachinesClient.beginCreateOrUpdate": "Azure.ResourceManager.MultiServiceOlderVersions.Compute.VirtualMachines.createOrUpdate", + "azure.resourcemanager.multiserviceolderversions.combined.fluent.VirtualMachinesClient.createOrUpdate": "Azure.ResourceManager.MultiServiceOlderVersions.Compute.VirtualMachines.createOrUpdate", + "azure.resourcemanager.multiserviceolderversions.combined.fluent.VirtualMachinesClient.getByResourceGroup": "Azure.ResourceManager.MultiServiceOlderVersions.Compute.VirtualMachines.get", + "azure.resourcemanager.multiserviceolderversions.combined.fluent.VirtualMachinesClient.getByResourceGroupWithResponse": "Azure.ResourceManager.MultiServiceOlderVersions.Compute.VirtualMachines.get", + "azure.resourcemanager.multiserviceolderversions.combined.fluent.models.DiskInner": "Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk.Disk", + "azure.resourcemanager.multiserviceolderversions.combined.fluent.models.VirtualMachineInner": "Azure.ResourceManager.MultiServiceOlderVersions.Compute.VirtualMachine", + "azure.resourcemanager.multiserviceolderversions.combined.implementation.CombinedBuilder": "Azure.ResourceManager.MultiServiceOlderVersions.Combined", + "azure.resourcemanager.multiserviceolderversions.combined.models.DiskProperties": "Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk.DiskProperties", + "azure.resourcemanager.multiserviceolderversions.combined.models.ResourceProvisioningState": "Azure.ResourceManager.ResourceProvisioningState", + "azure.resourcemanager.multiserviceolderversions.combined.models.VirtualMachineProperties": "Azure.ResourceManager.MultiServiceOlderVersions.Compute.VirtualMachineProperties" + } +} diff --git a/typespec-tests/src/main/resources/META-INF/azure-resourcemanager-combined-generated_apiview_properties_shared-models.json b/typespec-tests/src/main/resources/META-INF/azure-resourcemanager-combined-generated_apiview_properties_shared-models.json new file mode 100644 index 0000000000..306ae1cb8b --- /dev/null +++ b/typespec-tests/src/main/resources/META-INF/azure-resourcemanager-combined-generated_apiview_properties_shared-models.json @@ -0,0 +1,23 @@ +{ + "flavor": "Azure", + "CrossLanguageDefinitionId": { + "azure.resourcemanager.multiservicesharedmodels.combined.fluent.Combined": "Azure.ResourceManager.MultiServiceSharedModels.Combined", + "azure.resourcemanager.multiservicesharedmodels.combined.fluent.StorageAccountsClient": "Azure.ResourceManager.MultiServiceSharedModels.Storage.StorageAccounts", + "azure.resourcemanager.multiservicesharedmodels.combined.fluent.StorageAccountsClient.beginCreateOrUpdate": "Azure.ResourceManager.MultiServiceSharedModels.Storage.StorageAccounts.createOrUpdate", + "azure.resourcemanager.multiservicesharedmodels.combined.fluent.StorageAccountsClient.createOrUpdate": "Azure.ResourceManager.MultiServiceSharedModels.Storage.StorageAccounts.createOrUpdate", + "azure.resourcemanager.multiservicesharedmodels.combined.fluent.StorageAccountsClient.getByResourceGroup": "Azure.ResourceManager.MultiServiceSharedModels.Storage.StorageAccounts.get", + "azure.resourcemanager.multiservicesharedmodels.combined.fluent.StorageAccountsClient.getByResourceGroupWithResponse": "Azure.ResourceManager.MultiServiceSharedModels.Storage.StorageAccounts.get", + "azure.resourcemanager.multiservicesharedmodels.combined.fluent.VirtualMachinesClient": "Azure.ResourceManager.MultiServiceSharedModels.Compute.VirtualMachines", + "azure.resourcemanager.multiservicesharedmodels.combined.fluent.VirtualMachinesClient.beginCreateOrUpdate": "Azure.ResourceManager.MultiServiceSharedModels.Compute.VirtualMachines.createOrUpdate", + "azure.resourcemanager.multiservicesharedmodels.combined.fluent.VirtualMachinesClient.createOrUpdate": "Azure.ResourceManager.MultiServiceSharedModels.Compute.VirtualMachines.createOrUpdate", + "azure.resourcemanager.multiservicesharedmodels.combined.fluent.VirtualMachinesClient.getByResourceGroup": "Azure.ResourceManager.MultiServiceSharedModels.Compute.VirtualMachines.get", + "azure.resourcemanager.multiservicesharedmodels.combined.fluent.VirtualMachinesClient.getByResourceGroupWithResponse": "Azure.ResourceManager.MultiServiceSharedModels.Compute.VirtualMachines.get", + "azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.StorageAccountInner": "Azure.ResourceManager.MultiServiceSharedModels.Storage.StorageAccount", + "azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.VirtualMachineInner": "Azure.ResourceManager.MultiServiceSharedModels.Compute.VirtualMachine", + "azure.resourcemanager.multiservicesharedmodels.combined.implementation.CombinedBuilder": "Azure.ResourceManager.MultiServiceSharedModels.Combined", + "azure.resourcemanager.multiservicesharedmodels.combined.models.ResourceProvisioningState": "Azure.ResourceManager.ResourceProvisioningState", + "azure.resourcemanager.multiservicesharedmodels.combined.models.SharedMetadata": "Azure.ResourceManager.MultiServiceSharedModels.Shared.SharedMetadata", + "azure.resourcemanager.multiservicesharedmodels.combined.models.StorageAccountProperties": "Azure.ResourceManager.MultiServiceSharedModels.Storage.StorageAccountProperties", + "azure.resourcemanager.multiservicesharedmodels.combined.models.VirtualMachineProperties": "Azure.ResourceManager.MultiServiceSharedModels.Compute.VirtualMachineProperties" + } +} diff --git a/typespec-tests/src/main/resources/META-INF/azure-resourcemanager-combined-generated_metadata_older-versions.json b/typespec-tests/src/main/resources/META-INF/azure-resourcemanager-combined-generated_metadata_older-versions.json new file mode 100644 index 0000000000..37b992ffa8 --- /dev/null +++ b/typespec-tests/src/main/resources/META-INF/azure-resourcemanager-combined-generated_metadata_older-versions.json @@ -0,0 +1 @@ +{"flavor":"Azure","crossLanguageDefinitions":{"azure.resourcemanager.multiserviceolderversions.combined.fluent.Combined":"Azure.ResourceManager.MultiServiceOlderVersions.Combined","azure.resourcemanager.multiserviceolderversions.combined.fluent.DisksClient":"Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk.Disks","azure.resourcemanager.multiserviceolderversions.combined.fluent.DisksClient.beginCreateOrUpdate":"Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk.Disks.createOrUpdate","azure.resourcemanager.multiserviceolderversions.combined.fluent.DisksClient.createOrUpdate":"Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk.Disks.createOrUpdate","azure.resourcemanager.multiserviceolderversions.combined.fluent.DisksClient.getByResourceGroup":"Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk.Disks.get","azure.resourcemanager.multiserviceolderversions.combined.fluent.DisksClient.getByResourceGroupWithResponse":"Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk.Disks.get","azure.resourcemanager.multiserviceolderversions.combined.fluent.VirtualMachinesClient":"Azure.ResourceManager.MultiServiceOlderVersions.Compute.VirtualMachines","azure.resourcemanager.multiserviceolderversions.combined.fluent.VirtualMachinesClient.beginCreateOrUpdate":"Azure.ResourceManager.MultiServiceOlderVersions.Compute.VirtualMachines.createOrUpdate","azure.resourcemanager.multiserviceolderversions.combined.fluent.VirtualMachinesClient.createOrUpdate":"Azure.ResourceManager.MultiServiceOlderVersions.Compute.VirtualMachines.createOrUpdate","azure.resourcemanager.multiserviceolderversions.combined.fluent.VirtualMachinesClient.getByResourceGroup":"Azure.ResourceManager.MultiServiceOlderVersions.Compute.VirtualMachines.get","azure.resourcemanager.multiserviceolderversions.combined.fluent.VirtualMachinesClient.getByResourceGroupWithResponse":"Azure.ResourceManager.MultiServiceOlderVersions.Compute.VirtualMachines.get","azure.resourcemanager.multiserviceolderversions.combined.fluent.models.DiskInner":"Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk.Disk","azure.resourcemanager.multiserviceolderversions.combined.fluent.models.VirtualMachineInner":"Azure.ResourceManager.MultiServiceOlderVersions.Compute.VirtualMachine","azure.resourcemanager.multiserviceolderversions.combined.implementation.CombinedBuilder":"Azure.ResourceManager.MultiServiceOlderVersions.Combined","azure.resourcemanager.multiserviceolderversions.combined.models.DiskProperties":"Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk.DiskProperties","azure.resourcemanager.multiserviceolderversions.combined.models.ResourceProvisioningState":"Azure.ResourceManager.ResourceProvisioningState","azure.resourcemanager.multiserviceolderversions.combined.models.VirtualMachineProperties":"Azure.ResourceManager.MultiServiceOlderVersions.Compute.VirtualMachineProperties"},"generatedFiles":["src/main/java/azure/resourcemanager/multiserviceolderversions/combined/CombinedManager.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/Combined.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/DisksClient.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/VirtualMachinesClient.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/models/DiskInner.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/models/VirtualMachineInner.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/models/package-info.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/fluent/package-info.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/CombinedBuilder.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/CombinedImpl.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/DiskImpl.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/DisksClientImpl.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/DisksImpl.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/ResourceManagerUtils.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/VirtualMachineImpl.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/VirtualMachinesClientImpl.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/VirtualMachinesImpl.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/implementation/package-info.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/Disk.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/DiskProperties.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/Disks.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/ResourceProvisioningState.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/VirtualMachine.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/VirtualMachineProperties.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/VirtualMachines.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/models/package-info.java","src/main/java/azure/resourcemanager/multiserviceolderversions/combined/package-info.java","src/main/java/module-info.java"]} \ No newline at end of file diff --git a/typespec-tests/src/main/resources/META-INF/azure-resourcemanager-combined-generated_metadata_shared-models.json b/typespec-tests/src/main/resources/META-INF/azure-resourcemanager-combined-generated_metadata_shared-models.json new file mode 100644 index 0000000000..3e3303bc35 --- /dev/null +++ b/typespec-tests/src/main/resources/META-INF/azure-resourcemanager-combined-generated_metadata_shared-models.json @@ -0,0 +1 @@ +{"flavor":"Azure","crossLanguageDefinitions":{"azure.resourcemanager.multiservicesharedmodels.combined.fluent.Combined":"Azure.ResourceManager.MultiServiceSharedModels.Combined","azure.resourcemanager.multiservicesharedmodels.combined.fluent.StorageAccountsClient":"Azure.ResourceManager.MultiServiceSharedModels.Storage.StorageAccounts","azure.resourcemanager.multiservicesharedmodels.combined.fluent.StorageAccountsClient.beginCreateOrUpdate":"Azure.ResourceManager.MultiServiceSharedModels.Storage.StorageAccounts.createOrUpdate","azure.resourcemanager.multiservicesharedmodels.combined.fluent.StorageAccountsClient.createOrUpdate":"Azure.ResourceManager.MultiServiceSharedModels.Storage.StorageAccounts.createOrUpdate","azure.resourcemanager.multiservicesharedmodels.combined.fluent.StorageAccountsClient.getByResourceGroup":"Azure.ResourceManager.MultiServiceSharedModels.Storage.StorageAccounts.get","azure.resourcemanager.multiservicesharedmodels.combined.fluent.StorageAccountsClient.getByResourceGroupWithResponse":"Azure.ResourceManager.MultiServiceSharedModels.Storage.StorageAccounts.get","azure.resourcemanager.multiservicesharedmodels.combined.fluent.VirtualMachinesClient":"Azure.ResourceManager.MultiServiceSharedModels.Compute.VirtualMachines","azure.resourcemanager.multiservicesharedmodels.combined.fluent.VirtualMachinesClient.beginCreateOrUpdate":"Azure.ResourceManager.MultiServiceSharedModels.Compute.VirtualMachines.createOrUpdate","azure.resourcemanager.multiservicesharedmodels.combined.fluent.VirtualMachinesClient.createOrUpdate":"Azure.ResourceManager.MultiServiceSharedModels.Compute.VirtualMachines.createOrUpdate","azure.resourcemanager.multiservicesharedmodels.combined.fluent.VirtualMachinesClient.getByResourceGroup":"Azure.ResourceManager.MultiServiceSharedModels.Compute.VirtualMachines.get","azure.resourcemanager.multiservicesharedmodels.combined.fluent.VirtualMachinesClient.getByResourceGroupWithResponse":"Azure.ResourceManager.MultiServiceSharedModels.Compute.VirtualMachines.get","azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.StorageAccountInner":"Azure.ResourceManager.MultiServiceSharedModels.Storage.StorageAccount","azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.VirtualMachineInner":"Azure.ResourceManager.MultiServiceSharedModels.Compute.VirtualMachine","azure.resourcemanager.multiservicesharedmodels.combined.implementation.CombinedBuilder":"Azure.ResourceManager.MultiServiceSharedModels.Combined","azure.resourcemanager.multiservicesharedmodels.combined.models.ResourceProvisioningState":"Azure.ResourceManager.ResourceProvisioningState","azure.resourcemanager.multiservicesharedmodels.combined.models.SharedMetadata":"Azure.ResourceManager.MultiServiceSharedModels.Shared.SharedMetadata","azure.resourcemanager.multiservicesharedmodels.combined.models.StorageAccountProperties":"Azure.ResourceManager.MultiServiceSharedModels.Storage.StorageAccountProperties","azure.resourcemanager.multiservicesharedmodels.combined.models.VirtualMachineProperties":"Azure.ResourceManager.MultiServiceSharedModels.Compute.VirtualMachineProperties"},"generatedFiles":["src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/CombinedManager.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/Combined.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/StorageAccountsClient.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/VirtualMachinesClient.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/models/StorageAccountInner.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/models/VirtualMachineInner.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/models/package-info.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/fluent/package-info.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/CombinedBuilder.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/CombinedImpl.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/ResourceManagerUtils.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/StorageAccountImpl.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/StorageAccountsClientImpl.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/StorageAccountsImpl.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/VirtualMachineImpl.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/VirtualMachinesClientImpl.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/VirtualMachinesImpl.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/implementation/package-info.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/ResourceProvisioningState.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/SharedMetadata.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/StorageAccount.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/StorageAccountProperties.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/StorageAccounts.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/VirtualMachine.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/VirtualMachineProperties.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/VirtualMachines.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/models/package-info.java","src/main/java/azure/resourcemanager/multiservicesharedmodels/combined/package-info.java","src/main/java/module-info.java"]} \ No newline at end of file diff --git a/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated_older-versions/proxy-config.json b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated_older-versions/proxy-config.json new file mode 100644 index 0000000000..05dc52000a --- /dev/null +++ b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated_older-versions/proxy-config.json @@ -0,0 +1 @@ +[["azure.resourcemanager.multiserviceolderversions.combined.implementation.DisksClientImpl$DisksService"],["azure.resourcemanager.multiserviceolderversions.combined.implementation.VirtualMachinesClientImpl$VirtualMachinesService"]] \ No newline at end of file diff --git a/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated_older-versions/reflect-config.json b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated_older-versions/reflect-config.json new file mode 100644 index 0000000000..0637a088a0 --- /dev/null +++ b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated_older-versions/reflect-config.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated_shared-models/proxy-config.json b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated_shared-models/proxy-config.json new file mode 100644 index 0000000000..8b395b0e6f --- /dev/null +++ b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated_shared-models/proxy-config.json @@ -0,0 +1 @@ +[["azure.resourcemanager.multiservicesharedmodels.combined.implementation.StorageAccountsClientImpl$StorageAccountsService"],["azure.resourcemanager.multiservicesharedmodels.combined.implementation.VirtualMachinesClientImpl$VirtualMachinesService"]] \ No newline at end of file diff --git a/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated_shared-models/reflect-config.json b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated_shared-models/reflect-config.json new file mode 100644 index 0000000000..0637a088a0 --- /dev/null +++ b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated_shared-models/reflect-config.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/typespec-tests/src/test/java/azure/resourcemanager/multiserviceolderversions/ArmMultiServiceOlderVersionsTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiserviceolderversions/ArmMultiServiceOlderVersionsTests.java new file mode 100644 index 0000000000..1a704aa3a3 --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiserviceolderversions/ArmMultiServiceOlderVersionsTests.java @@ -0,0 +1,39 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package azure.resourcemanager.multiserviceolderversions; + +import azure.resourcemanager.multiserviceolderversions.combined.CombinedManager; +import azure.resourcemanager.multiserviceolderversions.combined.models.DiskProperties; +import azure.resourcemanager.multiserviceolderversions.combined.models.VirtualMachineProperties; +import com.azure.core.management.Region; +import org.junit.jupiter.api.Test; +import org.utils.ArmUtils; + +public final class ArmMultiServiceOlderVersionsTests { + + private final CombinedManager manager + = CombinedManager.authenticate(ArmUtils.createTestHttpPipeline(), ArmUtils.getAzureProfile()); + + private static final String RESOURCE_GROUP_NAME = "test-rg"; + private static final Region REGION = Region.US_EAST; + + @Test + public void testCombinedClient() { + manager.disks() + .define("disk-old1") + .withRegion(REGION) + .withExistingResourceGroup(RESOURCE_GROUP_NAME) + .withProperties(new DiskProperties().withDiskSizeGB(128)) + .create(); + manager.disks().getByResourceGroup(RESOURCE_GROUP_NAME, "disk-old1"); + + manager.virtualMachines() + .define("vm-old1") + .withRegion(REGION) + .withExistingResourceGroup(RESOURCE_GROUP_NAME) + .withProperties(new VirtualMachineProperties().withSize("Standard_D2s_v3")) + .create(); + manager.virtualMachines().getByResourceGroup(RESOURCE_GROUP_NAME, "vm-old1"); + } +} diff --git a/typespec-tests/src/test/java/azure/resourcemanager/multiserviceolderversions/combined/generated/DiskInnerTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiserviceolderversions/combined/generated/DiskInnerTests.java new file mode 100644 index 0000000000..0d799efc91 --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiserviceolderversions/combined/generated/DiskInnerTests.java @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.generated; + +import azure.resourcemanager.multiserviceolderversions.combined.fluent.models.DiskInner; +import azure.resourcemanager.multiserviceolderversions.combined.models.DiskProperties; +import com.azure.core.util.BinaryData; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Assertions; + +public final class DiskInnerTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + DiskInner model = BinaryData.fromString( + "{\"properties\":{\"provisioningState\":\"Canceled\",\"diskSizeGB\":1911349374},\"location\":\"ufpo\",\"tags\":{\"qsoqijgkd\":\"izhwlrxy\"},\"id\":\"bpazlobcufpdzn\",\"name\":\"btcqq\",\"type\":\"nq\"}") + .toObject(DiskInner.class); + Assertions.assertEquals("ufpo", model.location()); + Assertions.assertEquals("izhwlrxy", model.tags().get("qsoqijgkd")); + Assertions.assertEquals(1911349374, model.properties().diskSizeGB()); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + DiskInner model = new DiskInner().withLocation("ufpo") + .withTags(mapOf("qsoqijgkd", "izhwlrxy")) + .withProperties(new DiskProperties().withDiskSizeGB(1911349374)); + model = BinaryData.fromObject(model).toObject(DiskInner.class); + Assertions.assertEquals("ufpo", model.location()); + Assertions.assertEquals("izhwlrxy", model.tags().get("qsoqijgkd")); + Assertions.assertEquals(1911349374, model.properties().diskSizeGB()); + } + + // Use "Map.of" if available + @SuppressWarnings("unchecked") + private static Map mapOf(Object... inputs) { + Map map = new HashMap<>(); + for (int i = 0; i < inputs.length; i += 2) { + String key = (String) inputs[i]; + T value = (T) inputs[i + 1]; + map.put(key, value); + } + return map; + } +} diff --git a/typespec-tests/src/test/java/azure/resourcemanager/multiserviceolderversions/combined/generated/DiskPropertiesTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiserviceolderversions/combined/generated/DiskPropertiesTests.java new file mode 100644 index 0000000000..c09cf61fb9 --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiserviceolderversions/combined/generated/DiskPropertiesTests.java @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.generated; + +import azure.resourcemanager.multiserviceolderversions.combined.models.DiskProperties; +import com.azure.core.util.BinaryData; +import org.junit.jupiter.api.Assertions; + +public final class DiskPropertiesTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + DiskProperties model = BinaryData.fromString("{\"provisioningState\":\"Succeeded\",\"diskSizeGB\":2127527772}") + .toObject(DiskProperties.class); + Assertions.assertEquals(2127527772, model.diskSizeGB()); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + DiskProperties model = new DiskProperties().withDiskSizeGB(2127527772); + model = BinaryData.fromObject(model).toObject(DiskProperties.class); + Assertions.assertEquals(2127527772, model.diskSizeGB()); + } +} diff --git a/typespec-tests/src/test/java/azure/resourcemanager/multiserviceolderversions/combined/generated/VirtualMachineInnerTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiserviceolderversions/combined/generated/VirtualMachineInnerTests.java new file mode 100644 index 0000000000..6a4592562a --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiserviceolderversions/combined/generated/VirtualMachineInnerTests.java @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.generated; + +import azure.resourcemanager.multiserviceolderversions.combined.fluent.models.VirtualMachineInner; +import azure.resourcemanager.multiserviceolderversions.combined.models.VirtualMachineProperties; +import com.azure.core.util.BinaryData; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Assertions; + +public final class VirtualMachineInnerTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + VirtualMachineInner model = BinaryData.fromString( + "{\"properties\":{\"provisioningState\":\"Succeeded\",\"size\":\"uv\"},\"location\":\"xpyb\",\"tags\":{\"sphrupidgs\":\"ehmtzop\"},\"id\":\"bb\",\"name\":\"jhphoyc\",\"type\":\"sx\"}") + .toObject(VirtualMachineInner.class); + Assertions.assertEquals("xpyb", model.location()); + Assertions.assertEquals("ehmtzop", model.tags().get("sphrupidgs")); + Assertions.assertEquals("uv", model.properties().size()); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + VirtualMachineInner model = new VirtualMachineInner().withLocation("xpyb") + .withTags(mapOf("sphrupidgs", "ehmtzop")) + .withProperties(new VirtualMachineProperties().withSize("uv")); + model = BinaryData.fromObject(model).toObject(VirtualMachineInner.class); + Assertions.assertEquals("xpyb", model.location()); + Assertions.assertEquals("ehmtzop", model.tags().get("sphrupidgs")); + Assertions.assertEquals("uv", model.properties().size()); + } + + // Use "Map.of" if available + @SuppressWarnings("unchecked") + private static Map mapOf(Object... inputs) { + Map map = new HashMap<>(); + for (int i = 0; i < inputs.length; i += 2) { + String key = (String) inputs[i]; + T value = (T) inputs[i + 1]; + map.put(key, value); + } + return map; + } +} diff --git a/typespec-tests/src/test/java/azure/resourcemanager/multiserviceolderversions/combined/generated/VirtualMachinePropertiesTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiserviceolderversions/combined/generated/VirtualMachinePropertiesTests.java new file mode 100644 index 0000000000..696397674e --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiserviceolderversions/combined/generated/VirtualMachinePropertiesTests.java @@ -0,0 +1,26 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiserviceolderversions.combined.generated; + +import azure.resourcemanager.multiserviceolderversions.combined.models.VirtualMachineProperties; +import com.azure.core.util.BinaryData; +import org.junit.jupiter.api.Assertions; + +public final class VirtualMachinePropertiesTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + VirtualMachineProperties model + = BinaryData.fromString("{\"provisioningState\":\"Canceled\",\"size\":\"dxbmtqioq\"}") + .toObject(VirtualMachineProperties.class); + Assertions.assertEquals("dxbmtqioq", model.size()); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + VirtualMachineProperties model = new VirtualMachineProperties().withSize("dxbmtqioq"); + model = BinaryData.fromObject(model).toObject(VirtualMachineProperties.class); + Assertions.assertEquals("dxbmtqioq", model.size()); + } +} diff --git a/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/ArmMultiServiceSharedModelsTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/ArmMultiServiceSharedModelsTests.java new file mode 100644 index 0000000000..7dd7e97fb3 --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/ArmMultiServiceSharedModelsTests.java @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package azure.resourcemanager.multiservicesharedmodels; + +import azure.resourcemanager.multiservicesharedmodels.combined.CombinedManager; +import azure.resourcemanager.multiservicesharedmodels.combined.models.SharedMetadata; +import azure.resourcemanager.multiservicesharedmodels.combined.models.StorageAccountProperties; +import azure.resourcemanager.multiservicesharedmodels.combined.models.VirtualMachineProperties; +import com.azure.core.management.Region; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import org.utils.ArmUtils; + +public final class ArmMultiServiceSharedModelsTests { + + private final CombinedManager manager + = CombinedManager.authenticate(ArmUtils.createTestHttpPipeline(), ArmUtils.getAzureProfile()); + + private static final String RESOURCE_GROUP_NAME = "test-rg"; + private static final Region REGION_STORAGE = Region.US_WEST; + private static final Region REGION_VM = Region.US_EAST; + + @Test + @Disabled("route in code is wrong: /Microsoft.Compute/storageAccounts/account1") + public void testCombinedClient() { + Map storageTags = new HashMap<>(); + storageTags.put("department", "engineering"); + SharedMetadata storageMetadata = new SharedMetadata().withCreatedBy("admin@example.com").withTags(storageTags); + + manager.storageAccounts() + .define("account1") + .withRegion(REGION_STORAGE) + .withExistingResourceGroup(RESOURCE_GROUP_NAME) + .withProperties(new StorageAccountProperties().withMetadata(storageMetadata)) + .create(); + manager.storageAccounts().getByResourceGroup(RESOURCE_GROUP_NAME, "account1"); + + Map vmTags = new HashMap<>(); + vmTags.put("environment", "production"); + SharedMetadata vmMetadata = new SharedMetadata().withCreatedBy("user@example.com").withTags(vmTags); + + manager.virtualMachines() + .define("vm-shared1") + .withRegion(REGION_VM) + .withExistingResourceGroup(RESOURCE_GROUP_NAME) + .withProperties(new VirtualMachineProperties().withMetadata(vmMetadata)) + .create(); + manager.virtualMachines().getByResourceGroup(RESOURCE_GROUP_NAME, "vm-shared1"); + } +} diff --git a/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/combined/generated/SharedMetadataTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/combined/generated/SharedMetadataTests.java new file mode 100644 index 0000000000..9032d3f2fc --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/combined/generated/SharedMetadataTests.java @@ -0,0 +1,47 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.generated; + +import azure.resourcemanager.multiservicesharedmodels.combined.models.SharedMetadata; +import com.azure.core.util.BinaryData; +import java.time.OffsetDateTime; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Assertions; + +public final class SharedMetadataTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + SharedMetadata model = BinaryData.fromString( + "{\"createdAt\":\"2021-04-06T23:33:47Z\",\"createdBy\":\"arhmofcqhsmy\",\"tags\":{\"ukcdmparcryuanzw\":\"dtmlxhekuksjt\",\"pmrqobm\":\"xzdxtayrlhmwh\",\"knryrtihfxtij\":\"u\"}}") + .toObject(SharedMetadata.class); + Assertions.assertEquals(OffsetDateTime.parse("2021-04-06T23:33:47Z"), model.createdAt()); + Assertions.assertEquals("arhmofcqhsmy", model.createdBy()); + Assertions.assertEquals("dtmlxhekuksjt", model.tags().get("ukcdmparcryuanzw")); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + SharedMetadata model = new SharedMetadata().withCreatedAt(OffsetDateTime.parse("2021-04-06T23:33:47Z")) + .withCreatedBy("arhmofcqhsmy") + .withTags(mapOf("ukcdmparcryuanzw", "dtmlxhekuksjt", "pmrqobm", "xzdxtayrlhmwh", "knryrtihfxtij", "u")); + model = BinaryData.fromObject(model).toObject(SharedMetadata.class); + Assertions.assertEquals(OffsetDateTime.parse("2021-04-06T23:33:47Z"), model.createdAt()); + Assertions.assertEquals("arhmofcqhsmy", model.createdBy()); + Assertions.assertEquals("dtmlxhekuksjt", model.tags().get("ukcdmparcryuanzw")); + } + + // Use "Map.of" if available + @SuppressWarnings("unchecked") + private static Map mapOf(Object... inputs) { + Map map = new HashMap<>(); + for (int i = 0; i < inputs.length; i += 2) { + String key = (String) inputs[i]; + T value = (T) inputs[i + 1]; + map.put(key, value); + } + return map; + } +} diff --git a/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/combined/generated/StorageAccountInnerTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/combined/generated/StorageAccountInnerTests.java new file mode 100644 index 0000000000..20c316abb2 --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/combined/generated/StorageAccountInnerTests.java @@ -0,0 +1,58 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.generated; + +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.StorageAccountInner; +import azure.resourcemanager.multiservicesharedmodels.combined.models.SharedMetadata; +import azure.resourcemanager.multiservicesharedmodels.combined.models.StorageAccountProperties; +import com.azure.core.util.BinaryData; +import java.time.OffsetDateTime; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Assertions; + +public final class StorageAccountInnerTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + StorageAccountInner model = BinaryData.fromString( + "{\"properties\":{\"provisioningState\":\"Canceled\",\"metadata\":{\"createdAt\":\"2021-10-14T13:51:33Z\",\"createdBy\":\"symglzufcyz\",\"tags\":{\"s\":\"dbihanufhfcbj\",\"xqhabi\":\"git\"}}},\"location\":\"ikxwc\",\"tags\":{\"n\":\"scnpqxuhivy\",\"rkxvdum\":\"wby\"},\"id\":\"grtfwvu\",\"name\":\"xgaudccs\",\"type\":\"h\"}") + .toObject(StorageAccountInner.class); + Assertions.assertEquals("ikxwc", model.location()); + Assertions.assertEquals("scnpqxuhivy", model.tags().get("n")); + Assertions.assertEquals(OffsetDateTime.parse("2021-10-14T13:51:33Z"), + model.properties().metadata().createdAt()); + Assertions.assertEquals("symglzufcyz", model.properties().metadata().createdBy()); + Assertions.assertEquals("dbihanufhfcbj", model.properties().metadata().tags().get("s")); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + StorageAccountInner model = new StorageAccountInner().withLocation("ikxwc") + .withTags(mapOf("n", "scnpqxuhivy", "rkxvdum", "wby")) + .withProperties(new StorageAccountProperties() + .withMetadata(new SharedMetadata().withCreatedAt(OffsetDateTime.parse("2021-10-14T13:51:33Z")) + .withCreatedBy("symglzufcyz") + .withTags(mapOf("s", "dbihanufhfcbj", "xqhabi", "git")))); + model = BinaryData.fromObject(model).toObject(StorageAccountInner.class); + Assertions.assertEquals("ikxwc", model.location()); + Assertions.assertEquals("scnpqxuhivy", model.tags().get("n")); + Assertions.assertEquals(OffsetDateTime.parse("2021-10-14T13:51:33Z"), + model.properties().metadata().createdAt()); + Assertions.assertEquals("symglzufcyz", model.properties().metadata().createdBy()); + Assertions.assertEquals("dbihanufhfcbj", model.properties().metadata().tags().get("s")); + } + + // Use "Map.of" if available + @SuppressWarnings("unchecked") + private static Map mapOf(Object... inputs) { + Map map = new HashMap<>(); + for (int i = 0; i < inputs.length; i += 2) { + String key = (String) inputs[i]; + T value = (T) inputs[i + 1]; + map.put(key, value); + } + return map; + } +} diff --git a/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/combined/generated/StorageAccountPropertiesTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/combined/generated/StorageAccountPropertiesTests.java new file mode 100644 index 0000000000..78f8a9c2c2 --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/combined/generated/StorageAccountPropertiesTests.java @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.generated; + +import azure.resourcemanager.multiservicesharedmodels.combined.models.SharedMetadata; +import azure.resourcemanager.multiservicesharedmodels.combined.models.StorageAccountProperties; +import com.azure.core.util.BinaryData; +import java.time.OffsetDateTime; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Assertions; + +public final class StorageAccountPropertiesTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + StorageAccountProperties model = BinaryData.fromString( + "{\"provisioningState\":\"Canceled\",\"metadata\":{\"createdAt\":\"2021-08-18T11:52:54Z\",\"createdBy\":\"hkryhtn\",\"tags\":{\"okjye\":\"zw\",\"jnchgej\":\"kkvnipjox\",\"huxinpmqnj\":\"podmailzydehojwy\"}}}") + .toObject(StorageAccountProperties.class); + Assertions.assertEquals(OffsetDateTime.parse("2021-08-18T11:52:54Z"), model.metadata().createdAt()); + Assertions.assertEquals("hkryhtn", model.metadata().createdBy()); + Assertions.assertEquals("zw", model.metadata().tags().get("okjye")); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + StorageAccountProperties model = new StorageAccountProperties() + .withMetadata(new SharedMetadata().withCreatedAt(OffsetDateTime.parse("2021-08-18T11:52:54Z")) + .withCreatedBy("hkryhtn") + .withTags(mapOf("okjye", "zw", "jnchgej", "kkvnipjox", "huxinpmqnj", "podmailzydehojwy"))); + model = BinaryData.fromObject(model).toObject(StorageAccountProperties.class); + Assertions.assertEquals(OffsetDateTime.parse("2021-08-18T11:52:54Z"), model.metadata().createdAt()); + Assertions.assertEquals("hkryhtn", model.metadata().createdBy()); + Assertions.assertEquals("zw", model.metadata().tags().get("okjye")); + } + + // Use "Map.of" if available + @SuppressWarnings("unchecked") + private static Map mapOf(Object... inputs) { + Map map = new HashMap<>(); + for (int i = 0; i < inputs.length; i += 2) { + String key = (String) inputs[i]; + T value = (T) inputs[i + 1]; + map.put(key, value); + } + return map; + } +} diff --git a/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/combined/generated/VirtualMachineInnerTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/combined/generated/VirtualMachineInnerTests.java new file mode 100644 index 0000000000..b848baf9f8 --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/combined/generated/VirtualMachineInnerTests.java @@ -0,0 +1,60 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.generated; + +import azure.resourcemanager.multiservicesharedmodels.combined.fluent.models.VirtualMachineInner; +import azure.resourcemanager.multiservicesharedmodels.combined.models.SharedMetadata; +import azure.resourcemanager.multiservicesharedmodels.combined.models.VirtualMachineProperties; +import com.azure.core.util.BinaryData; +import java.time.OffsetDateTime; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Assertions; + +public final class VirtualMachineInnerTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + VirtualMachineInner model = BinaryData.fromString( + "{\"properties\":{\"provisioningState\":\"Succeeded\",\"metadata\":{\"createdAt\":\"2021-07-30T08:26:42Z\",\"createdBy\":\"jxpybczmeh\",\"tags\":{\"phrupidgsybbejhp\":\"opb\",\"ioq\":\"oycmsxaobhdxbmt\",\"p\":\"zehtbmu\",\"hwlrx\":\"wnoi\"}}},\"location\":\"qsoqijgkd\",\"tags\":{\"qqjnqgl\":\"azlobcufpdznrbt\",\"foooj\":\"qgn\",\"saagdf\":\"wifsq\"},\"id\":\"glzlhjxrifkwmrv\",\"name\":\"tsizntocipaoua\",\"type\":\"psqucmpoyf\"}") + .toObject(VirtualMachineInner.class); + Assertions.assertEquals("qsoqijgkd", model.location()); + Assertions.assertEquals("azlobcufpdznrbt", model.tags().get("qqjnqgl")); + Assertions.assertEquals(OffsetDateTime.parse("2021-07-30T08:26:42Z"), + model.properties().metadata().createdAt()); + Assertions.assertEquals("jxpybczmeh", model.properties().metadata().createdBy()); + Assertions.assertEquals("opb", model.properties().metadata().tags().get("phrupidgsybbejhp")); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + VirtualMachineInner model + = new VirtualMachineInner().withLocation("qsoqijgkd") + .withTags(mapOf("qqjnqgl", "azlobcufpdznrbt", "foooj", "qgn", "saagdf", "wifsq")) + .withProperties(new VirtualMachineProperties().withMetadata(new SharedMetadata() + .withCreatedAt(OffsetDateTime.parse("2021-07-30T08:26:42Z")) + .withCreatedBy("jxpybczmeh") + .withTags( + mapOf("phrupidgsybbejhp", "opb", "ioq", "oycmsxaobhdxbmt", "p", "zehtbmu", "hwlrx", "wnoi")))); + model = BinaryData.fromObject(model).toObject(VirtualMachineInner.class); + Assertions.assertEquals("qsoqijgkd", model.location()); + Assertions.assertEquals("azlobcufpdznrbt", model.tags().get("qqjnqgl")); + Assertions.assertEquals(OffsetDateTime.parse("2021-07-30T08:26:42Z"), + model.properties().metadata().createdAt()); + Assertions.assertEquals("jxpybczmeh", model.properties().metadata().createdBy()); + Assertions.assertEquals("opb", model.properties().metadata().tags().get("phrupidgsybbejhp")); + } + + // Use "Map.of" if available + @SuppressWarnings("unchecked") + private static Map mapOf(Object... inputs) { + Map map = new HashMap<>(); + for (int i = 0; i < inputs.length; i += 2) { + String key = (String) inputs[i]; + T value = (T) inputs[i + 1]; + map.put(key, value); + } + return map; + } +} diff --git a/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/combined/generated/VirtualMachinePropertiesTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/combined/generated/VirtualMachinePropertiesTests.java new file mode 100644 index 0000000000..81302f836b --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiservicesharedmodels/combined/generated/VirtualMachinePropertiesTests.java @@ -0,0 +1,49 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservicesharedmodels.combined.generated; + +import azure.resourcemanager.multiservicesharedmodels.combined.models.SharedMetadata; +import azure.resourcemanager.multiservicesharedmodels.combined.models.VirtualMachineProperties; +import com.azure.core.util.BinaryData; +import java.time.OffsetDateTime; +import java.util.HashMap; +import java.util.Map; +import org.junit.jupiter.api.Assertions; + +public final class VirtualMachinePropertiesTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + VirtualMachineProperties model = BinaryData.fromString( + "{\"provisioningState\":\"Failed\",\"metadata\":{\"createdAt\":\"2021-01-23T06:12:50Z\",\"createdBy\":\"ygjofjdd\",\"tags\":{\"upewnwreitjzy\":\"rd\"}}}") + .toObject(VirtualMachineProperties.class); + Assertions.assertEquals(OffsetDateTime.parse("2021-01-23T06:12:50Z"), model.metadata().createdAt()); + Assertions.assertEquals("ygjofjdd", model.metadata().createdBy()); + Assertions.assertEquals("rd", model.metadata().tags().get("upewnwreitjzy")); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + VirtualMachineProperties model = new VirtualMachineProperties() + .withMetadata(new SharedMetadata().withCreatedAt(OffsetDateTime.parse("2021-01-23T06:12:50Z")) + .withCreatedBy("ygjofjdd") + .withTags(mapOf("upewnwreitjzy", "rd"))); + model = BinaryData.fromObject(model).toObject(VirtualMachineProperties.class); + Assertions.assertEquals(OffsetDateTime.parse("2021-01-23T06:12:50Z"), model.metadata().createdAt()); + Assertions.assertEquals("ygjofjdd", model.metadata().createdBy()); + Assertions.assertEquals("rd", model.metadata().tags().get("upewnwreitjzy")); + } + + // Use "Map.of" if available + @SuppressWarnings("unchecked") + private static Map mapOf(Object... inputs) { + Map map = new HashMap<>(); + for (int i = 0; i < inputs.length; i += 2) { + String key = (String) inputs[i]; + T value = (T) inputs[i + 1]; + map.put(key, value); + } + return map; + } +}