From ec3b06938c837b3197ba4e3ffb0985cf9b120f87 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Dec 2025 04:35:23 +0000 Subject: [PATCH 1/6] Initial plan From 0c07522e1d15093ad8b63f3a628146b3064fe77d Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Fri, 19 Dec 2025 04:40:17 +0000 Subject: [PATCH 2/6] Update Node.js dependencies and changelog date Co-authored-by: weidongxu-microsoft <53292327+weidongxu-microsoft@users.noreply.github.com> --- core | 2 +- typespec-extension/changelog.md | 2 +- typespec-extension/package-lock.json | 22 +++++++++++----------- typespec-extension/package.json | 8 ++++---- typespec-tests/package.json | 4 ++-- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/core b/core index 9f01672ff7..a6e5932de8 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit 9f01672ff76130414b77af07c6cd53e339e6d85a +Subproject commit a6e5932de8aa4a0e07434295b6f1b5c61d8d867a diff --git a/typespec-extension/changelog.md b/typespec-extension/changelog.md index 97f9274fac..084bd2a73c 100644 --- a/typespec-extension/changelog.md +++ b/typespec-extension/changelog.md @@ -1,6 +1,6 @@ # Release History -## 0.37.4 (2025-12-18) +## 0.37.4 (2025-12-19) Compatible with compiler 1.7.1. diff --git a/typespec-extension/package-lock.json b/typespec-extension/package-lock.json index 8a309be0ce..6b2c9977c4 100644 --- a/typespec-extension/package-lock.json +++ b/typespec-extension/package-lock.json @@ -14,11 +14,11 @@ "lodash": "~4.17.21" }, "devDependencies": { - "@azure-tools/typespec-autorest": "0.63.0", + "@azure-tools/typespec-autorest": "0.63.1", "@azure-tools/typespec-azure-core": "0.63.0", "@azure-tools/typespec-azure-resource-manager": "0.63.0", "@azure-tools/typespec-azure-rulesets": "0.63.0", - "@azure-tools/typespec-client-generator-core": "0.63.0", + "@azure-tools/typespec-client-generator-core": "0.63.1", "@azure-tools/typespec-liftr-base": "0.11.0", "@microsoft/api-extractor": "^7.55.2", "@types/js-yaml": "~4.0.9", @@ -53,11 +53,11 @@ "node": ">=20.0.0" }, "peerDependencies": { - "@azure-tools/typespec-autorest": ">=0.63.0 <1.0.0", + "@azure-tools/typespec-autorest": ">=0.63.1 <1.0.0", "@azure-tools/typespec-azure-core": ">=0.63.0 <1.0.0", "@azure-tools/typespec-azure-resource-manager": ">=0.63.0 <1.0.0", "@azure-tools/typespec-azure-rulesets": ">=0.63.0 <1.0.0", - "@azure-tools/typespec-client-generator-core": ">=0.63.0 <1.0.0", + "@azure-tools/typespec-client-generator-core": ">=0.63.1 <1.0.0", "@azure-tools/typespec-liftr-base": ">=0.11.0 <1.0.0", "@typespec/compiler": "^1.7.1", "@typespec/http": "^1.7.0", @@ -154,9 +154,9 @@ } }, "node_modules/@azure-tools/typespec-autorest": { - "version": "0.63.0", - "resolved": "https://registry.npmjs.org/@azure-tools/typespec-autorest/-/typespec-autorest-0.63.0.tgz", - "integrity": "sha512-E04eX5axqua+bVs8QH1z74Wrq+XjO6tInq6d6EhjBNQAcRyFCJNxJHqcJkzMWNy1ID/iIGNXyRG/elK2AdegZg==", + "version": "0.63.1", + "resolved": "https://registry.npmjs.org/@azure-tools/typespec-autorest/-/typespec-autorest-0.63.1.tgz", + "integrity": "sha512-Nem51jk2eURxa5PPEEUjdguxAEwNIyxTi3ac/GOo/B3SgwIa3WAOpwWqQPyGLPD2hHRKa2pm9FsPu6aLPmgeCQ==", "dev": true, "license": "MIT", "engines": { @@ -165,7 +165,7 @@ "peerDependencies": { "@azure-tools/typespec-azure-core": "^0.63.0", "@azure-tools/typespec-azure-resource-manager": "^0.63.0", - "@azure-tools/typespec-client-generator-core": "^0.63.0", + "@azure-tools/typespec-client-generator-core": "^0.63.1", "@typespec/compiler": "^1.7.0", "@typespec/http": "^1.7.0", "@typespec/openapi": "^1.7.0", @@ -233,9 +233,9 @@ } }, "node_modules/@azure-tools/typespec-client-generator-core": { - "version": "0.63.0", - "resolved": "https://registry.npmjs.org/@azure-tools/typespec-client-generator-core/-/typespec-client-generator-core-0.63.0.tgz", - "integrity": "sha512-zpvFvjCjNW+GWzHBV7vJ2E1PKXrmyNqp7FQiYo/D7PJBVTXNtOyIKqqo043ktAaWihbr8cl5QguuNSoBAKL0+Q==", + "version": "0.63.1", + "resolved": "https://registry.npmjs.org/@azure-tools/typespec-client-generator-core/-/typespec-client-generator-core-0.63.1.tgz", + "integrity": "sha512-/LMrPVKrzPRBicjVSz+zqC/EBysqbIKgjfoAxMDXa4nmJchzxls+hgvprAZsCAJy5uEeshOn7WdNT/aQkBQRXw==", "dev": true, "license": "MIT", "dependencies": { diff --git a/typespec-extension/package.json b/typespec-extension/package.json index 9f11f8ae0a..79aca2d864 100644 --- a/typespec-extension/package.json +++ b/typespec-extension/package.json @@ -47,11 +47,11 @@ "generator/http-client-generator/target/classes/PerfAutomation.jfc" ], "peerDependencies": { - "@azure-tools/typespec-autorest": ">=0.63.0 <1.0.0", + "@azure-tools/typespec-autorest": ">=0.63.1 <1.0.0", "@azure-tools/typespec-azure-core": ">=0.63.0 <1.0.0", "@azure-tools/typespec-azure-resource-manager": ">=0.63.0 <1.0.0", "@azure-tools/typespec-azure-rulesets": ">=0.63.0 <1.0.0", - "@azure-tools/typespec-client-generator-core": ">=0.63.0 <1.0.0", + "@azure-tools/typespec-client-generator-core": ">=0.63.1 <1.0.0", "@azure-tools/typespec-liftr-base": ">=0.11.0 <1.0.0", "@typespec/compiler": "^1.7.1", "@typespec/http": "^1.7.0", @@ -66,11 +66,11 @@ "lodash": "~4.17.21" }, "devDependencies": { - "@azure-tools/typespec-autorest": "0.63.0", + "@azure-tools/typespec-autorest": "0.63.1", "@azure-tools/typespec-azure-core": "0.63.0", "@azure-tools/typespec-azure-resource-manager": "0.63.0", "@azure-tools/typespec-azure-rulesets": "0.63.0", - "@azure-tools/typespec-client-generator-core": "0.63.0", + "@azure-tools/typespec-client-generator-core": "0.63.1", "@azure-tools/typespec-liftr-base": "0.11.0", "@microsoft/api-extractor": "^7.55.2", "@types/js-yaml": "~4.0.9", diff --git a/typespec-tests/package.json b/typespec-tests/package.json index 3c1f3f0313..6f6e8e2078 100644 --- a/typespec-tests/package.json +++ b/typespec-tests/package.json @@ -31,9 +31,9 @@ "@typespec/sse": "0.77.0", "@typespec/streams": "0.77.0", "@azure-tools/typespec-azure-core": "0.63.0", - "@azure-tools/typespec-client-generator-core": "0.63.0", + "@azure-tools/typespec-client-generator-core": "0.63.1", "@azure-tools/typespec-azure-resource-manager": "0.63.0", - "@azure-tools/typespec-autorest": "0.63.0", + "@azure-tools/typespec-autorest": "0.63.1", "@azure-tools/typespec-liftr-base": "0.11.0" }, "private": true From 2f883f797bde8ed381e2e8cafaf66d7590856735 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 19 Dec 2025 17:01:32 +0800 Subject: [PATCH 3/6] Update changelog.md --- typespec-extension/changelog.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typespec-extension/changelog.md b/typespec-extension/changelog.md index 084bd2a73c..97f9274fac 100644 --- a/typespec-extension/changelog.md +++ b/typespec-extension/changelog.md @@ -1,6 +1,6 @@ # Release History -## 0.37.4 (2025-12-19) +## 0.37.4 (2025-12-18) Compatible with compiler 1.7.1. From 96217d5fe471b6a07380549fe4210e7998ffc891 Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 19 Dec 2025 18:16:43 +0800 Subject: [PATCH 4/6] core on branch --- core | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core b/core index a6e5932de8..f1ba1c92ac 160000 --- a/core +++ b/core @@ -1 +1 @@ -Subproject commit a6e5932de8aa4a0e07434295b6f1b5c61d8d867a +Subproject commit f1ba1c92ac80fc615cf77bcd3b9c6a19b7979440 From aa34c7605f4dee4f9f556168ce7e9a642fa4a76f Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 19 Dec 2025 18:18:47 +0800 Subject: [PATCH 5/6] sync script --- typespec-tests/Generate.ps1 | 88 +++++++++++++++++++++---------------- typespec-tests/package.json | 2 +- 2 files changed, 51 insertions(+), 39 deletions(-) diff --git a/typespec-tests/Generate.ps1 b/typespec-tests/Generate.ps1 index 0a874a5aa2..f056594536 100644 --- a/typespec-tests/Generate.ps1 +++ b/typespec-tests/Generate.ps1 @@ -153,55 +153,67 @@ $generateScript = { } } -./Setup.ps1 +Push-Location $PSScriptRoot +try { + ./Setup.ps1 -New-Item -Path ./existingcode/src/main/java/tsptest/ -ItemType Directory -Force | Out-Null + New-Item -Path ./existingcode/src/main/java/tsptest/ -ItemType Directory -Force | Out-Null -if (Test-Path ./src/main/java/tsptest/partialupdate) { - Copy-Item -Path ./src/main/java/tsptest/partialupdate -Destination ./existingcode/src/main/java/tsptest/partialupdate -Recurse -Force -} + if (Test-Path ./src/main/java/tsptest/partialupdate) { + Copy-Item -Path ./src/main/java/tsptest/partialupdate -Destination ./existingcode/src/main/java/tsptest/partialupdate -Recurse -Force + } -if (Test-Path ./src/main) { - Remove-Item ./src/main -Recurse -Force -} -if (Test-Path ./src/samples) { - Remove-Item ./src/samples -Recurse -Force -} -if (Test-Path ./src/test) { - Get-ChildItem -Path ./src/test -Recurse -Directory | Where-Object {$_.Name -match "^generated$"} | Remove-Item -Recurse -Force -} -if (Test-Path ./tsp-output) { - Remove-Item ./tsp-output -Recurse -Force -} + if (Test-Path ./src/main) { + Remove-Item ./src/main -Recurse -Force + } + if (Test-Path ./src/samples) { + Remove-Item ./src/samples -Recurse -Force + } + if (Test-Path ./src/test) { + Get-ChildItem -Path ./src/test -Recurse -Directory | Where-Object {$_.Name -match "^generated$"} | Remove-Item -Recurse -Force + } + if (Test-Path ./tsp-output) { + Remove-Item ./tsp-output -Recurse -Force + } -# generate for other local test sources except partial update -$job = Get-Item ./tsp/* -Filter "*.tsp" -Exclude "*partialupdate*" | ForEach-Object -Parallel $generateScript -ThrottleLimit $Parallelization -AsJob + # generate for other local test sources except partial update + $job = Get-Item ./tsp/* -Filter "*.tsp" -Exclude "*partialupdate*" | ForEach-Object -Parallel $generateScript -ThrottleLimit $Parallelization -AsJob -$job | Wait-Job -Timeout 600 -$job | Receive-Job + $job | Wait-Job -Timeout 600 + $job | Receive-Job -# partial update test -npx --no-install tsp compile ./tsp/partialupdate.tsp --option="@azure-tools/typespec-java.emitter-output-dir={project-root}/existingcode" -Copy-Item -Path ./existingcode/src/main/java/tsptest/partialupdate -Destination ./src/main/java/tsptest/partialupdate -Recurse -Force -Remove-Item ./existingcode -Recurse -Force + # partial update test + npx --no-install tsp compile ./tsp/partialupdate.tsp --option="@azure-tools/typespec-java.emitter-output-dir={project-root}/existingcode" + Copy-Item -Path ./existingcode/src/main/java/tsptest/partialupdate -Destination ./src/main/java/tsptest/partialupdate -Recurse -Force + Remove-Item ./existingcode -Recurse -Force -# generate for http-specs/azure-http-specs test sources -Copy-Item -Path node_modules/@typespec/http-specs/specs -Destination ./ -Recurse -Force -Copy-Item -Path node_modules/@azure-tools/azure-http-specs/specs -Destination ./ -Recurse -Force -# remove xml tests, emitter has not supported xml model -Remove-Item ./specs/payload/xml -Recurse -Force + # generate for http-specs/azure-http-specs test sources + Copy-Item -Path node_modules/@typespec/http-specs/specs -Destination ./ -Recurse -Force + Copy-Item -Path node_modules/@azure-tools/azure-http-specs/specs -Destination ./ -Recurse -Force + # remove xml tests, emitter has not supported xml model + Remove-Item ./specs/payload/xml -Recurse -Force -$job = (Get-ChildItem ./specs -Include "main.tsp","old.tsp" -File -Recurse) | ForEach-Object -Parallel $generateScript -ThrottleLimit $Parallelization -AsJob + $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 + } -$job | Wait-Job -Timeout 1200 -$job | Receive-Job + $job = $specFiles | ForEach-Object -Parallel $generateScript -ThrottleLimit $Parallelization -AsJob -Remove-Item ./specs -Recurse -Force + $job | Wait-Job -Timeout 1200 + $job | Receive-Job -Copy-Item -Path ./tsp-output/*/src -Destination ./ -Recurse -Force -Exclude @("ReadmeSamples.java", "module-info.java") + Remove-Item ./specs -Recurse -Force -Remove-Item ./tsp-output -Recurse -Force + Copy-Item -Path ./tsp-output/*/src -Destination ./ -Recurse -Force -Exclude @("ReadmeSamples.java", "module-info.java") -if ($ExitCode -ne 0) { - throw "Failed to generate from tsp" + Remove-Item ./tsp-output -Recurse -Force + + if ($ExitCode -ne 0) { + throw "Failed to generate from tsp" + } +} finally { + Pop-Location } diff --git a/typespec-tests/package.json b/typespec-tests/package.json index 6f6e8e2078..de0ece92a9 100644 --- a/typespec-tests/package.json +++ b/typespec-tests/package.json @@ -12,7 +12,7 @@ "@typespec/spec-api": "0.1.0-alpha.11", "@typespec/spector": "0.1.0-alpha.21", "@typespec/http-specs": "0.1.0-alpha.29", - "@azure-tools/azure-http-specs": "0.1.0-alpha.33", + "@azure-tools/azure-http-specs": "0.1.0-alpha.34", "@azure-tools/typespec-java": "file:/../typespec-extension/azure-tools-typespec-java-0.37.4.tgz" }, "devDependencies": { From c2699baee9dc4a0b0ffa36a6f3e89a0b2238026b Mon Sep 17 00:00:00 2001 From: Weidong Xu Date: Fri, 19 Dec 2025 18:20:45 +0800 Subject: [PATCH 6/6] sync tests --- .../combined/CombinedManager.java | 298 +++++++++++++++ .../combined/fluent/Combined.java | 62 +++ .../combined/fluent/DisksClient.java | 105 ++++++ .../fluent/VirtualMachinesClient.java | 111 ++++++ .../combined/fluent/models/DiskInner.java | 181 +++++++++ .../fluent/models/VirtualMachineInner.java | 181 +++++++++ .../combined/fluent/models/package-info.java | 9 + .../combined/fluent/package-info.java | 9 + .../implementation/CombinedBuilder.java | 138 +++++++ .../combined/implementation/CombinedImpl.java | 324 ++++++++++++++++ .../combined/implementation/DiskImpl.java | 163 ++++++++ .../implementation/DisksClientImpl.java | 340 +++++++++++++++++ .../combined/implementation/DisksImpl.java | 88 +++++ .../implementation/ResourceManagerUtils.java | 195 ++++++++++ .../implementation/VirtualMachineImpl.java | 164 ++++++++ .../VirtualMachinesClientImpl.java | 356 ++++++++++++++++++ .../implementation/VirtualMachinesImpl.java | 89 +++++ .../combined/implementation/package-info.java | 9 + .../multiservice/combined/models/Disk.java | 265 +++++++++++++ .../combined/models/DiskProperties.java | 74 ++++ .../multiservice/combined/models/Disks.java | 69 ++++ .../models/ResourceProvisioningState.java | 56 +++ .../combined/models/VirtualMachine.java | 265 +++++++++++++ .../models/VirtualMachineProperties.java | 74 ++++ .../combined/models/VirtualMachines.java | 69 ++++ .../combined/models/package-info.java | 9 + .../multiservice/combined/package-info.java | 9 + .../multiservice/combined/BarAsyncClient.java | 72 ++++ .../multiservice/combined/BarClient.java | 69 ++++ .../combined/CombinedBuilder.java | 328 ++++++++++++++++ .../multiservice/combined/FooAsyncClient.java | 72 ++++ .../multiservice/combined/FooClient.java | 69 ++++ .../combined/ServiceAServiceVersion.java | 45 +++ .../combined/implementation/BarsImpl.java | 117 ++++++ .../combined/implementation/CombinedImpl.java | 142 +++++++ .../combined/implementation/FoosImpl.java | 117 ++++++ .../combined/implementation/package-info.java | 10 + .../multiservice/combined/package-info.java | 10 + .../proxy-config.json | 1 + .../reflect-config.json | 1 + ...ourcemanager-combined-generated.properties | 1 + .../service-multiservice-combined.properties | 2 + .../combined/generated/DiskInnerTests.java | 45 +++ .../generated/DiskPropertiesTests.java | 22 ++ .../generated/VirtualMachineInnerTests.java | 45 +++ .../VirtualMachinePropertiesTests.java | 22 ++ .../combined/generated/CombinedTestBase.java | 46 +++ 47 files changed, 4948 insertions(+) create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/CombinedManager.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/Combined.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/DisksClient.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/VirtualMachinesClient.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/models/DiskInner.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/models/VirtualMachineInner.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/models/package-info.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/package-info.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/CombinedBuilder.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/CombinedImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/DiskImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/DisksClientImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/DisksImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/ResourceManagerUtils.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/VirtualMachineImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/VirtualMachinesClientImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/VirtualMachinesImpl.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/package-info.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/Disk.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/DiskProperties.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/Disks.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/ResourceProvisioningState.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/VirtualMachine.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/VirtualMachineProperties.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/VirtualMachines.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/package-info.java create mode 100644 typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/package-info.java create mode 100644 typespec-tests/src/main/java/service/multiservice/combined/BarAsyncClient.java create mode 100644 typespec-tests/src/main/java/service/multiservice/combined/BarClient.java create mode 100644 typespec-tests/src/main/java/service/multiservice/combined/CombinedBuilder.java create mode 100644 typespec-tests/src/main/java/service/multiservice/combined/FooAsyncClient.java create mode 100644 typespec-tests/src/main/java/service/multiservice/combined/FooClient.java create mode 100644 typespec-tests/src/main/java/service/multiservice/combined/ServiceAServiceVersion.java create mode 100644 typespec-tests/src/main/java/service/multiservice/combined/implementation/BarsImpl.java create mode 100644 typespec-tests/src/main/java/service/multiservice/combined/implementation/CombinedImpl.java create mode 100644 typespec-tests/src/main/java/service/multiservice/combined/implementation/FoosImpl.java create mode 100644 typespec-tests/src/main/java/service/multiservice/combined/implementation/package-info.java create mode 100644 typespec-tests/src/main/java/service/multiservice/combined/package-info.java create mode 100644 typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated/proxy-config.json create mode 100644 typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated/reflect-config.json create mode 100644 typespec-tests/src/main/resources/azure-resourcemanager-combined-generated.properties create mode 100644 typespec-tests/src/main/resources/service-multiservice-combined.properties create mode 100644 typespec-tests/src/test/java/azure/resourcemanager/multiservice/combined/generated/DiskInnerTests.java create mode 100644 typespec-tests/src/test/java/azure/resourcemanager/multiservice/combined/generated/DiskPropertiesTests.java create mode 100644 typespec-tests/src/test/java/azure/resourcemanager/multiservice/combined/generated/VirtualMachineInnerTests.java create mode 100644 typespec-tests/src/test/java/azure/resourcemanager/multiservice/combined/generated/VirtualMachinePropertiesTests.java create mode 100644 typespec-tests/src/test/java/service/multiservice/combined/generated/CombinedTestBase.java diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/CombinedManager.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/CombinedManager.java new file mode 100644 index 0000000000..ba46e7c64d --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.combined; + +import azure.resourcemanager.multiservice.combined.fluent.Combined; +import azure.resourcemanager.multiservice.combined.implementation.CombinedBuilder; +import azure.resourcemanager.multiservice.combined.implementation.DisksImpl; +import azure.resourcemanager.multiservice.combined.implementation.VirtualMachinesImpl; +import azure.resourcemanager.multiservice.combined.models.Disks; +import azure.resourcemanager.multiservice.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.multiservice.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/multiservice/combined/fluent/Combined.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/Combined.java new file mode 100644 index 0000000000..34d52fe5aa --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/Combined.java @@ -0,0 +1,62 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservice.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 Version parameter. + * + * @return the apiVersion value. + */ + String getApiVersion(); + + /** + * Gets The ID of the target subscription. The value must be an UUID. + * + * @return the subscriptionId value. + */ + String getSubscriptionId(); + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + HttpPipeline getHttpPipeline(); + + /** + * Gets The default poll interval for long-running operation. + * + * @return the defaultPollInterval value. + */ + Duration getDefaultPollInterval(); + + /** + * Gets the 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/multiservice/combined/fluent/DisksClient.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/DisksClient.java new file mode 100644 index 0000000000..0abf504509 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.combined.fluent; + +import azure.resourcemanager.multiservice.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/multiservice/combined/fluent/VirtualMachinesClient.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/VirtualMachinesClient.java new file mode 100644 index 0000000000..7f05b08e0b --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.combined.fluent; + +import azure.resourcemanager.multiservice.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/multiservice/combined/fluent/models/DiskInner.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/models/DiskInner.java new file mode 100644 index 0000000000..7a464f689e --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.combined.fluent.models; + +import azure.resourcemanager.multiservice.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/multiservice/combined/fluent/models/VirtualMachineInner.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/models/VirtualMachineInner.java new file mode 100644 index 0000000000..ecb75d3726 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.combined.fluent.models; + +import azure.resourcemanager.multiservice.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/multiservice/combined/fluent/models/package-info.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/models/package-info.java new file mode 100644 index 0000000000..a418da6f4e --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.combined.fluent.models; diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/package-info.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/fluent/package-info.java new file mode 100644 index 0000000000..b51da8a120 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.combined.fluent; diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/CombinedBuilder.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/CombinedBuilder.java new file mode 100644 index 0000000000..77d2d28800 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.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/multiservice/combined/implementation/CombinedImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/CombinedImpl.java new file mode 100644 index 0000000000..4e1282d491 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/CombinedImpl.java @@ -0,0 +1,324 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservice.combined.implementation; + +import azure.resourcemanager.multiservice.combined.fluent.Combined; +import azure.resourcemanager.multiservice.combined.fluent.DisksClient; +import azure.resourcemanager.multiservice.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; + } + + /** + * Version parameter. + */ + private final String apiVersion; + + /** + * Gets Version parameter. + * + * @return the apiVersion value. + */ + public String getApiVersion() { + return this.apiVersion; + } + + /** + * The ID of the target subscription. The value must be an UUID. + */ + private final String subscriptionId; + + /** + * Gets The ID of the target subscription. The value must be an UUID. + * + * @return the subscriptionId value. + */ + public String getSubscriptionId() { + return this.subscriptionId; + } + + /** + * The HTTP pipeline to send requests through. + */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The serializer to serialize an object into a string. + */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * The default poll interval for long-running operation. + */ + private final Duration defaultPollInterval; + + /** + * Gets The default poll interval for long-running operation. + * + * @return the defaultPollInterval value. + */ + public Duration getDefaultPollInterval() { + return this.defaultPollInterval; + } + + /** + * The 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.apiVersion = "2025-04-01"; + 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/multiservice/combined/implementation/DiskImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/DiskImpl.java new file mode 100644 index 0000000000..a2602710bb --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/DiskImpl.java @@ -0,0 +1,163 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservice.combined.implementation; + +import azure.resourcemanager.multiservice.combined.fluent.models.DiskInner; +import azure.resourcemanager.multiservice.combined.models.Disk; +import azure.resourcemanager.multiservice.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.multiservice.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.multiservice.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.multiservice.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.multiservice.combined.CombinedManager serviceManager) { + this.innerObject = innerObject; + this.serviceManager = serviceManager; + this.resourceGroupName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "resourceGroups"); + this.diskName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "disks"); + } + + 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/multiservice/combined/implementation/DisksClientImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/DisksClientImpl.java new file mode 100644 index 0000000000..d46361c0be --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/DisksClientImpl.java @@ -0,0 +1,340 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservice.combined.implementation; + +import azure.resourcemanager.multiservice.combined.fluent.DisksClient; +import azure.resourcemanager.multiservice.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/disks/{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/disks/{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/disks/{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/disks/{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 accept = "application/json"; + return FluxUtil + .withContext(context -> service.getByResourceGroup(this.client.getEndpoint(), this.client.getApiVersion(), + 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 accept = "application/json"; + return service.getByResourceGroupSync(this.client.getEndpoint(), this.client.getApiVersion(), + 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 contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), this.client.getApiVersion(), + 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 contentType = "application/json"; + final String accept = "application/json"; + return service.createOrUpdateSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, diskName, contentType, accept, resource, Context.NONE); + } + + /** + * 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 contentType = "application/json"; + final String accept = "application/json"; + return service.createOrUpdateSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, diskName, contentType, accept, resource, context); + } + + /** + * 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/multiservice/combined/implementation/DisksImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/DisksImpl.java new file mode 100644 index 0000000000..dc239f5146 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.combined.implementation; + +import azure.resourcemanager.multiservice.combined.fluent.DisksClient; +import azure.resourcemanager.multiservice.combined.fluent.models.DiskInner; +import azure.resourcemanager.multiservice.combined.models.Disk; +import azure.resourcemanager.multiservice.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.multiservice.combined.CombinedManager serviceManager; + + public DisksImpl(DisksClient innerClient, + azure.resourcemanager.multiservice.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, "disks"); + if (diskName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'disks'.", 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, "disks"); + if (diskName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'disks'.", id))); + } + return this.getByResourceGroupWithResponse(resourceGroupName, diskName, context); + } + + private DisksClient serviceClient() { + return this.innerClient; + } + + private azure.resourcemanager.multiservice.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/multiservice/combined/implementation/ResourceManagerUtils.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/ResourceManagerUtils.java new file mode 100644 index 0000000000..0c6500fe0e --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.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/multiservice/combined/implementation/VirtualMachineImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/VirtualMachineImpl.java new file mode 100644 index 0000000000..c168f6217d --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/VirtualMachineImpl.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.multiservice.combined.implementation; + +import azure.resourcemanager.multiservice.combined.fluent.models.VirtualMachineInner; +import azure.resourcemanager.multiservice.combined.models.VirtualMachine; +import azure.resourcemanager.multiservice.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.multiservice.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.multiservice.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.multiservice.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.multiservice.combined.CombinedManager serviceManager) { + this.innerObject = innerObject; + this.serviceManager = serviceManager; + this.resourceGroupName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "resourceGroups"); + this.vmName = ResourceManagerUtils.getValueFromIdByName(innerObject.id(), "virtualMachines"); + } + + 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/multiservice/combined/implementation/VirtualMachinesClientImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/VirtualMachinesClientImpl.java new file mode 100644 index 0000000000..2553053f80 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/VirtualMachinesClientImpl.java @@ -0,0 +1,356 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservice.combined.implementation; + +import azure.resourcemanager.multiservice.combined.fluent.VirtualMachinesClient; +import azure.resourcemanager.multiservice.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/virtualMachines/{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/virtualMachines/{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/virtualMachines/{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/virtualMachines/{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 accept = "application/json"; + return FluxUtil + .withContext(context -> service.getByResourceGroup(this.client.getEndpoint(), this.client.getApiVersion(), + 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 accept = "application/json"; + return service.getByResourceGroupSync(this.client.getEndpoint(), this.client.getApiVersion(), + 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 contentType = "application/json"; + final String accept = "application/json"; + return FluxUtil + .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), this.client.getApiVersion(), + 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 contentType = "application/json"; + final String accept = "application/json"; + return service.createOrUpdateSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, vmName, contentType, accept, resource, Context.NONE); + } + + /** + * 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 contentType = "application/json"; + final String accept = "application/json"; + return service.createOrUpdateSync(this.client.getEndpoint(), this.client.getApiVersion(), + this.client.getSubscriptionId(), resourceGroupName, vmName, contentType, accept, resource, context); + } + + /** + * 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/multiservice/combined/implementation/VirtualMachinesImpl.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/VirtualMachinesImpl.java new file mode 100644 index 0000000000..05f4cd048c --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.combined.implementation; + +import azure.resourcemanager.multiservice.combined.fluent.VirtualMachinesClient; +import azure.resourcemanager.multiservice.combined.fluent.models.VirtualMachineInner; +import azure.resourcemanager.multiservice.combined.models.VirtualMachine; +import azure.resourcemanager.multiservice.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.multiservice.combined.CombinedManager serviceManager; + + public VirtualMachinesImpl(VirtualMachinesClient innerClient, + azure.resourcemanager.multiservice.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, "virtualMachines"); + if (vmName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'virtualMachines'.", 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, "virtualMachines"); + if (vmName == null) { + throw LOGGER.logExceptionAsError(new IllegalArgumentException( + String.format("The resource ID '%s' is not valid. Missing path segment 'virtualMachines'.", id))); + } + return this.getByResourceGroupWithResponse(resourceGroupName, vmName, context); + } + + private VirtualMachinesClient serviceClient() { + return this.innerClient; + } + + private azure.resourcemanager.multiservice.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/multiservice/combined/implementation/package-info.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/implementation/package-info.java new file mode 100644 index 0000000000..09f6feb1b9 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.combined.implementation; diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/Disk.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/Disk.java new file mode 100644 index 0000000000..b2ce33a9b7 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.combined.models; + +import azure.resourcemanager.multiservice.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.multiservice.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/multiservice/combined/models/DiskProperties.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/DiskProperties.java new file mode 100644 index 0000000000..14fbcecb49 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/DiskProperties.java @@ -0,0 +1,74 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservice.combined.models; + +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * Disk resource properties. + */ +@Immutable +public final class DiskProperties implements JsonSerializable { + /* + * The provisioningState property. + */ + private ResourceProvisioningState provisioningState; + + /** + * 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; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + 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 { + reader.skipChildren(); + } + } + + return deserializedDiskProperties; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/Disks.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/Disks.java new file mode 100644 index 0000000000..57b4ce0d91 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.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/multiservice/combined/models/ResourceProvisioningState.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/ResourceProvisioningState.java new file mode 100644 index 0000000000..22f4daccb3 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.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/multiservice/combined/models/VirtualMachine.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/VirtualMachine.java new file mode 100644 index 0000000000..3653056590 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.combined.models; + +import azure.resourcemanager.multiservice.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.multiservice.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/multiservice/combined/models/VirtualMachineProperties.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/VirtualMachineProperties.java new file mode 100644 index 0000000000..d911aed030 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/VirtualMachineProperties.java @@ -0,0 +1,74 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservice.combined.models; + +import com.azure.core.annotation.Immutable; +import com.azure.json.JsonReader; +import com.azure.json.JsonSerializable; +import com.azure.json.JsonToken; +import com.azure.json.JsonWriter; +import java.io.IOException; + +/** + * The VirtualMachineProperties model. + */ +@Immutable +public final class VirtualMachineProperties implements JsonSerializable { + /* + * The provisioningState property. + */ + private ResourceProvisioningState provisioningState; + + /** + * 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; + } + + /** + * {@inheritDoc} + */ + @Override + public JsonWriter toJson(JsonWriter jsonWriter) throws IOException { + jsonWriter.writeStartObject(); + 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 { + reader.skipChildren(); + } + } + + return deserializedVirtualMachineProperties; + }); + } +} diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/VirtualMachines.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/VirtualMachines.java new file mode 100644 index 0000000000..cee367106b --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.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/multiservice/combined/models/package-info.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/models/package-info.java new file mode 100644 index 0000000000..39b4e2b7bc --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.combined.models; diff --git a/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/package-info.java b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/combined/package-info.java new file mode 100644 index 0000000000..21bfd17684 --- /dev/null +++ b/typespec-tests/src/main/java/azure/resourcemanager/multiservice/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.multiservice.combined; diff --git a/typespec-tests/src/main/java/service/multiservice/combined/BarAsyncClient.java b/typespec-tests/src/main/java/service/multiservice/combined/BarAsyncClient.java new file mode 100644 index 0000000000..9211574695 --- /dev/null +++ b/typespec-tests/src/main/java/service/multiservice/combined/BarAsyncClient.java @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package service.multiservice.combined; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; +import service.multiservice.combined.implementation.BarsImpl; + +/** + * Initializes a new instance of the asynchronous Combined type. + */ +@ServiceClient(builder = CombinedBuilder.class, isAsync = true) +public final class BarAsyncClient { + @Generated + private final BarsImpl serviceClient; + + /** + * Initializes an instance of BarAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + BarAsyncClient(BarsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The test operation. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> testWithResponse(RequestOptions requestOptions) { + return this.serviceClient.testWithResponseAsync(requestOptions); + } + + /** + * The test operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return A {@link Mono} that completes when a successful response is received. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono test() { + // Generated convenience method for testWithResponse + RequestOptions requestOptions = new RequestOptions(); + return testWithResponse(requestOptions).flatMap(FluxUtil::toMono); + } +} diff --git a/typespec-tests/src/main/java/service/multiservice/combined/BarClient.java b/typespec-tests/src/main/java/service/multiservice/combined/BarClient.java new file mode 100644 index 0000000000..03b812e715 --- /dev/null +++ b/typespec-tests/src/main/java/service/multiservice/combined/BarClient.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 service.multiservice.combined; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import service.multiservice.combined.implementation.BarsImpl; + +/** + * Initializes a new instance of the synchronous Combined type. + */ +@ServiceClient(builder = CombinedBuilder.class) +public final class BarClient { + @Generated + private final BarsImpl serviceClient; + + /** + * Initializes an instance of BarClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + BarClient(BarsImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The test operation. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response testWithResponse(RequestOptions requestOptions) { + return this.serviceClient.testWithResponse(requestOptions); + } + + /** + * The test operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public void test() { + // Generated convenience method for testWithResponse + RequestOptions requestOptions = new RequestOptions(); + testWithResponse(requestOptions).getValue(); + } +} diff --git a/typespec-tests/src/main/java/service/multiservice/combined/CombinedBuilder.java b/typespec-tests/src/main/java/service/multiservice/combined/CombinedBuilder.java new file mode 100644 index 0000000000..cc8acd00b7 --- /dev/null +++ b/typespec-tests/src/main/java/service/multiservice/combined/CombinedBuilder.java @@ -0,0 +1,328 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package service.multiservice.combined; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.client.traits.ConfigurationTrait; +import com.azure.core.client.traits.EndpointTrait; +import com.azure.core.client.traits.HttpTrait; +import com.azure.core.http.HttpClient; +import com.azure.core.http.HttpHeaders; +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.HttpPipelinePosition; +import com.azure.core.http.policy.AddDatePolicy; +import com.azure.core.http.policy.AddHeadersFromContextPolicy; +import com.azure.core.http.policy.AddHeadersPolicy; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpLoggingPolicy; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.http.policy.HttpPolicyProviders; +import com.azure.core.http.policy.RequestIdPolicy; +import com.azure.core.http.policy.RetryOptions; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.ClientOptions; +import com.azure.core.util.Configuration; +import com.azure.core.util.CoreUtils; +import com.azure.core.util.builder.ClientBuilderUtil; +import com.azure.core.util.logging.ClientLogger; +import com.azure.core.util.serializer.JacksonAdapter; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Objects; +import service.multiservice.combined.implementation.CombinedImpl; + +/** + * A builder for creating a new instance of the Combined type. + */ +@ServiceClientBuilder(serviceClients = { FooClient.class, BarClient.class, FooAsyncClient.class, BarAsyncClient.class }) +public final class CombinedBuilder + implements HttpTrait, ConfigurationTrait, EndpointTrait { + @Generated + private static final String SDK_NAME = "name"; + + @Generated + private static final String SDK_VERSION = "version"; + + @Generated + private static final Map PROPERTIES + = CoreUtils.getProperties("service-multiservice-combined.properties"); + + @Generated + private final List pipelinePolicies; + + /** + * Create an instance of the CombinedBuilder. + */ + @Generated + public CombinedBuilder() { + this.pipelinePolicies = new ArrayList<>(); + } + + /* + * The HTTP client used to send the request. + */ + @Generated + private HttpClient httpClient; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public CombinedBuilder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /* + * The HTTP pipeline to send requests through. + */ + @Generated + private HttpPipeline pipeline; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public CombinedBuilder pipeline(HttpPipeline pipeline) { + if (this.pipeline != null && pipeline == null) { + LOGGER.atInfo().log("HttpPipeline is being set to 'null' when it was previously configured."); + } + this.pipeline = pipeline; + return this; + } + + /* + * The logging configuration for HTTP requests and responses. + */ + @Generated + private HttpLogOptions httpLogOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public CombinedBuilder httpLogOptions(HttpLogOptions httpLogOptions) { + this.httpLogOptions = httpLogOptions; + return this; + } + + /* + * The client options such as application ID and custom headers to set on a request. + */ + @Generated + private ClientOptions clientOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public CombinedBuilder clientOptions(ClientOptions clientOptions) { + this.clientOptions = clientOptions; + return this; + } + + /* + * The retry options to configure retry policy for failed requests. + */ + @Generated + private RetryOptions retryOptions; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public CombinedBuilder retryOptions(RetryOptions retryOptions) { + this.retryOptions = retryOptions; + return this; + } + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public CombinedBuilder addPolicy(HttpPipelinePolicy customPolicy) { + Objects.requireNonNull(customPolicy, "'customPolicy' cannot be null."); + pipelinePolicies.add(customPolicy); + return this; + } + + /* + * The configuration store that is used during construction of the service client. + */ + @Generated + private Configuration configuration; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public CombinedBuilder configuration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + /* + * The service endpoint + */ + @Generated + private String endpoint; + + /** + * {@inheritDoc}. + */ + @Generated + @Override + public CombinedBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /* + * Service version + */ + @Generated + private ServiceAServiceVersion serviceVersion; + + /** + * Sets Service version. + * + * @param serviceVersion the serviceVersion value. + * @return the CombinedBuilder. + */ + @Generated + public CombinedBuilder serviceVersion(ServiceAServiceVersion serviceVersion) { + this.serviceVersion = serviceVersion; + return this; + } + + /* + * The retry policy that will attempt to retry failed requests, if applicable. + */ + @Generated + private RetryPolicy retryPolicy; + + /** + * Sets The retry policy that will attempt to retry failed requests, if applicable. + * + * @param retryPolicy the retryPolicy value. + * @return the CombinedBuilder. + */ + @Generated + public CombinedBuilder retryPolicy(RetryPolicy retryPolicy) { + this.retryPolicy = retryPolicy; + return this; + } + + /** + * Builds an instance of CombinedImpl with the provided parameters. + * + * @return an instance of CombinedImpl. + */ + @Generated + private CombinedImpl buildInnerClient() { + this.validateClient(); + HttpPipeline localPipeline = (pipeline != null) ? pipeline : createHttpPipeline(); + String localEndpoint = (endpoint != null) ? endpoint : "http://localhost:3000"; + ServiceAServiceVersion localServiceVersion + = (serviceVersion != null) ? serviceVersion : ServiceAServiceVersion.getLatest(); + CombinedImpl client = new CombinedImpl(localPipeline, JacksonAdapter.createDefaultSerializerAdapter(), + localEndpoint, localServiceVersion); + return client; + } + + @Generated + private void validateClient() { + // This method is invoked from 'buildInnerClient'/'buildClient' method. + // Developer can customize this method, to validate that the necessary conditions are met for the new client. + } + + @Generated + private HttpPipeline createHttpPipeline() { + Configuration buildConfiguration + = (configuration == null) ? Configuration.getGlobalConfiguration() : configuration; + HttpLogOptions localHttpLogOptions = this.httpLogOptions == null ? new HttpLogOptions() : this.httpLogOptions; + ClientOptions localClientOptions = this.clientOptions == null ? new ClientOptions() : this.clientOptions; + List policies = new ArrayList<>(); + String clientName = PROPERTIES.getOrDefault(SDK_NAME, "UnknownName"); + String clientVersion = PROPERTIES.getOrDefault(SDK_VERSION, "UnknownVersion"); + String applicationId = CoreUtils.getApplicationId(localClientOptions, localHttpLogOptions); + policies.add(new UserAgentPolicy(applicationId, clientName, clientVersion, buildConfiguration)); + policies.add(new RequestIdPolicy()); + policies.add(new AddHeadersFromContextPolicy()); + HttpHeaders headers = CoreUtils.createHttpHeadersFromClientOptions(localClientOptions); + if (headers != null) { + policies.add(new AddHeadersPolicy(headers)); + } + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_CALL) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addBeforeRetryPolicies(policies); + policies.add(ClientBuilderUtil.validateAndGetRetryPolicy(retryPolicy, retryOptions, new RetryPolicy())); + policies.add(new AddDatePolicy()); + this.pipelinePolicies.stream() + .filter(p -> p.getPipelinePosition() == HttpPipelinePosition.PER_RETRY) + .forEach(p -> policies.add(p)); + HttpPolicyProviders.addAfterRetryPolicies(policies); + policies.add(new HttpLoggingPolicy(localHttpLogOptions)); + HttpPipeline httpPipeline = new HttpPipelineBuilder().policies(policies.toArray(new HttpPipelinePolicy[0])) + .httpClient(httpClient) + .clientOptions(localClientOptions) + .build(); + return httpPipeline; + } + + /** + * Builds an instance of FooAsyncClient class. + * + * @return an instance of FooAsyncClient. + */ + @Generated + public FooAsyncClient buildFooAsyncClient() { + return new FooAsyncClient(buildInnerClient().getFoos()); + } + + /** + * Builds an instance of BarAsyncClient class. + * + * @return an instance of BarAsyncClient. + */ + @Generated + public BarAsyncClient buildBarAsyncClient() { + return new BarAsyncClient(buildInnerClient().getBars()); + } + + /** + * Builds an instance of FooClient class. + * + * @return an instance of FooClient. + */ + @Generated + public FooClient buildFooClient() { + return new FooClient(buildInnerClient().getFoos()); + } + + /** + * Builds an instance of BarClient class. + * + * @return an instance of BarClient. + */ + @Generated + public BarClient buildBarClient() { + return new BarClient(buildInnerClient().getBars()); + } + + private static final ClientLogger LOGGER = new ClientLogger(CombinedBuilder.class); +} diff --git a/typespec-tests/src/main/java/service/multiservice/combined/FooAsyncClient.java b/typespec-tests/src/main/java/service/multiservice/combined/FooAsyncClient.java new file mode 100644 index 0000000000..34f3161e6a --- /dev/null +++ b/typespec-tests/src/main/java/service/multiservice/combined/FooAsyncClient.java @@ -0,0 +1,72 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package service.multiservice.combined; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; +import service.multiservice.combined.implementation.FoosImpl; + +/** + * Initializes a new instance of the asynchronous Combined type. + */ +@ServiceClient(builder = CombinedBuilder.class, isAsync = true) +public final class FooAsyncClient { + @Generated + private final FoosImpl serviceClient; + + /** + * Initializes an instance of FooAsyncClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + FooAsyncClient(FoosImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The test operation. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> testWithResponse(RequestOptions requestOptions) { + return this.serviceClient.testWithResponseAsync(requestOptions); + } + + /** + * The test operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + * @return A {@link Mono} that completes when a successful response is received. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono test() { + // Generated convenience method for testWithResponse + RequestOptions requestOptions = new RequestOptions(); + return testWithResponse(requestOptions).flatMap(FluxUtil::toMono); + } +} diff --git a/typespec-tests/src/main/java/service/multiservice/combined/FooClient.java b/typespec-tests/src/main/java/service/multiservice/combined/FooClient.java new file mode 100644 index 0000000000..98a2d8c872 --- /dev/null +++ b/typespec-tests/src/main/java/service/multiservice/combined/FooClient.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 service.multiservice.combined; + +import com.azure.core.annotation.Generated; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceClient; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import service.multiservice.combined.implementation.FoosImpl; + +/** + * Initializes a new instance of the synchronous Combined type. + */ +@ServiceClient(builder = CombinedBuilder.class) +public final class FooClient { + @Generated + private final FoosImpl serviceClient; + + /** + * Initializes an instance of FooClient class. + * + * @param serviceClient the service client implementation. + */ + @Generated + FooClient(FoosImpl serviceClient) { + this.serviceClient = serviceClient; + } + + /** + * The test operation. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response}. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public Response testWithResponse(RequestOptions requestOptions) { + return this.serviceClient.testWithResponse(requestOptions); + } + + /** + * The test operation. + * + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent. + */ + @Generated + @ServiceMethod(returns = ReturnType.SINGLE) + public void test() { + // Generated convenience method for testWithResponse + RequestOptions requestOptions = new RequestOptions(); + testWithResponse(requestOptions).getValue(); + } +} diff --git a/typespec-tests/src/main/java/service/multiservice/combined/ServiceAServiceVersion.java b/typespec-tests/src/main/java/service/multiservice/combined/ServiceAServiceVersion.java new file mode 100644 index 0000000000..a400682653 --- /dev/null +++ b/typespec-tests/src/main/java/service/multiservice/combined/ServiceAServiceVersion.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package service.multiservice.combined; + +import com.azure.core.util.ServiceVersion; + +/** + * Service version of ServiceAClient. + */ +public enum ServiceAServiceVersion implements ServiceVersion { + /** + * Enum value av1. + */ + VAV1("av1"), + + /** + * Enum value av2. + */ + VAV2("av2"); + + private final String version; + + ServiceAServiceVersion(String version) { + this.version = version; + } + + /** + * {@inheritDoc} + */ + @Override + public String getVersion() { + return this.version; + } + + /** + * Gets the latest service version supported by this client library. + * + * @return The latest {@link ServiceAServiceVersion}. + */ + public static ServiceAServiceVersion getLatest() { + return VAV2; + } +} diff --git a/typespec-tests/src/main/java/service/multiservice/combined/implementation/BarsImpl.java b/typespec-tests/src/main/java/service/multiservice/combined/implementation/BarsImpl.java new file mode 100644 index 0000000000..21ae41f7af --- /dev/null +++ b/typespec-tests/src/main/java/service/multiservice/combined/implementation/BarsImpl.java @@ -0,0 +1,117 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package service.multiservice.combined.implementation; + +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; +import service.multiservice.combined.ServiceAServiceVersion; + +/** + * An instance of this class provides access to all the operations defined in Bars. + */ +public final class BarsImpl { + /** + * The proxy service used to perform REST calls. + */ + private final BarsService service; + + /** + * The service client containing this operation class. + */ + private final CombinedImpl client; + + /** + * Initializes an instance of BarsImpl. + * + * @param client the instance of the service client containing this operation class. + */ + BarsImpl(CombinedImpl client) { + this.service = RestProxy.create(BarsService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * Gets Service version. + * + * @return the serviceVersion value. + */ + public ServiceAServiceVersion getServiceVersion() { + return client.getServiceVersion(); + } + + /** + * The interface defining all the services for CombinedBars to be used by the proxy service to perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "CombinedBars") + public interface BarsService { + @Get("/service/multi-service/service-b/bar/test") + @ExpectedResponses({ 204 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> test(@HostParam("endpoint") String endpoint, @QueryParam("api-version") String apiVersion, + RequestOptions requestOptions, Context context); + + @Get("/service/multi-service/service-b/bar/test") + @ExpectedResponses({ 204 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response testSync(@HostParam("endpoint") String endpoint, @QueryParam("api-version") String apiVersion, + RequestOptions requestOptions, Context context); + } + + /** + * The test operation. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> testWithResponseAsync(RequestOptions requestOptions) { + return FluxUtil.withContext(context -> service.test(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), requestOptions, context)); + } + + /** + * The test operation. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response testWithResponse(RequestOptions requestOptions) { + return service.testSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), requestOptions, + Context.NONE); + } +} diff --git a/typespec-tests/src/main/java/service/multiservice/combined/implementation/CombinedImpl.java b/typespec-tests/src/main/java/service/multiservice/combined/implementation/CombinedImpl.java new file mode 100644 index 0000000000..8c18060258 --- /dev/null +++ b/typespec-tests/src/main/java/service/multiservice/combined/implementation/CombinedImpl.java @@ -0,0 +1,142 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package service.multiservice.combined.implementation; + +import com.azure.core.http.HttpPipeline; +import com.azure.core.http.HttpPipelineBuilder; +import com.azure.core.http.policy.RetryPolicy; +import com.azure.core.http.policy.UserAgentPolicy; +import com.azure.core.util.serializer.JacksonAdapter; +import com.azure.core.util.serializer.SerializerAdapter; +import service.multiservice.combined.ServiceAServiceVersion; + +/** + * Initializes a new instance of the Combined type. + */ +public final class CombinedImpl { + /** + * Service host. + */ + private final String endpoint; + + /** + * Gets Service host. + * + * @return the endpoint value. + */ + public String getEndpoint() { + return this.endpoint; + } + + /** + * Service version. + */ + private final ServiceAServiceVersion serviceVersion; + + /** + * Gets Service version. + * + * @return the serviceVersion value. + */ + public ServiceAServiceVersion getServiceVersion() { + return this.serviceVersion; + } + + /** + * The HTTP pipeline to send requests through. + */ + private final HttpPipeline httpPipeline; + + /** + * Gets The HTTP pipeline to send requests through. + * + * @return the httpPipeline value. + */ + public HttpPipeline getHttpPipeline() { + return this.httpPipeline; + } + + /** + * The serializer to serialize an object into a string. + */ + private final SerializerAdapter serializerAdapter; + + /** + * Gets The serializer to serialize an object into a string. + * + * @return the serializerAdapter value. + */ + public SerializerAdapter getSerializerAdapter() { + return this.serializerAdapter; + } + + /** + * The FoosImpl object to access its operations. + */ + private final FoosImpl foos; + + /** + * Gets the FoosImpl object to access its operations. + * + * @return the FoosImpl object. + */ + public FoosImpl getFoos() { + return this.foos; + } + + /** + * The BarsImpl object to access its operations. + */ + private final BarsImpl bars; + + /** + * Gets the BarsImpl object to access its operations. + * + * @return the BarsImpl object. + */ + public BarsImpl getBars() { + return this.bars; + } + + /** + * Initializes an instance of Combined client. + * + * @param endpoint Service host. + * @param serviceVersion Service version. + */ + public CombinedImpl(String endpoint, ServiceAServiceVersion serviceVersion) { + this(new HttpPipelineBuilder().policies(new UserAgentPolicy(), new RetryPolicy()).build(), + JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion); + } + + /** + * Initializes an instance of Combined client. + * + * @param httpPipeline The HTTP pipeline to send requests through. + * @param endpoint Service host. + * @param serviceVersion Service version. + */ + public CombinedImpl(HttpPipeline httpPipeline, String endpoint, ServiceAServiceVersion serviceVersion) { + this(httpPipeline, JacksonAdapter.createDefaultSerializerAdapter(), endpoint, serviceVersion); + } + + /** + * 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 endpoint Service host. + * @param serviceVersion Service version. + */ + public CombinedImpl(HttpPipeline httpPipeline, SerializerAdapter serializerAdapter, String endpoint, + ServiceAServiceVersion serviceVersion) { + this.httpPipeline = httpPipeline; + this.serializerAdapter = serializerAdapter; + this.endpoint = endpoint; + this.serviceVersion = serviceVersion; + this.foos = new FoosImpl(this); + this.bars = new BarsImpl(this); + } +} diff --git a/typespec-tests/src/main/java/service/multiservice/combined/implementation/FoosImpl.java b/typespec-tests/src/main/java/service/multiservice/combined/implementation/FoosImpl.java new file mode 100644 index 0000000000..59071060d4 --- /dev/null +++ b/typespec-tests/src/main/java/service/multiservice/combined/implementation/FoosImpl.java @@ -0,0 +1,117 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package service.multiservice.combined.implementation; + +import com.azure.core.annotation.ExpectedResponses; +import com.azure.core.annotation.Get; +import com.azure.core.annotation.Host; +import com.azure.core.annotation.HostParam; +import com.azure.core.annotation.QueryParam; +import com.azure.core.annotation.ReturnType; +import com.azure.core.annotation.ServiceInterface; +import com.azure.core.annotation.ServiceMethod; +import com.azure.core.annotation.UnexpectedResponseExceptionType; +import com.azure.core.exception.ClientAuthenticationException; +import com.azure.core.exception.HttpResponseException; +import com.azure.core.exception.ResourceModifiedException; +import com.azure.core.exception.ResourceNotFoundException; +import com.azure.core.http.rest.RequestOptions; +import com.azure.core.http.rest.Response; +import com.azure.core.http.rest.RestProxy; +import com.azure.core.util.Context; +import com.azure.core.util.FluxUtil; +import reactor.core.publisher.Mono; +import service.multiservice.combined.ServiceAServiceVersion; + +/** + * An instance of this class provides access to all the operations defined in Foos. + */ +public final class FoosImpl { + /** + * The proxy service used to perform REST calls. + */ + private final FoosService service; + + /** + * The service client containing this operation class. + */ + private final CombinedImpl client; + + /** + * Initializes an instance of FoosImpl. + * + * @param client the instance of the service client containing this operation class. + */ + FoosImpl(CombinedImpl client) { + this.service = RestProxy.create(FoosService.class, client.getHttpPipeline(), client.getSerializerAdapter()); + this.client = client; + } + + /** + * Gets Service version. + * + * @return the serviceVersion value. + */ + public ServiceAServiceVersion getServiceVersion() { + return client.getServiceVersion(); + } + + /** + * The interface defining all the services for CombinedFoos to be used by the proxy service to perform REST calls. + */ + @Host("{endpoint}") + @ServiceInterface(name = "CombinedFoos") + public interface FoosService { + @Get("/service/multi-service/service-a/foo/test") + @ExpectedResponses({ 204 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Mono> test(@HostParam("endpoint") String endpoint, @QueryParam("api-version") String apiVersion, + RequestOptions requestOptions, Context context); + + @Get("/service/multi-service/service-a/foo/test") + @ExpectedResponses({ 204 }) + @UnexpectedResponseExceptionType(value = ClientAuthenticationException.class, code = { 401 }) + @UnexpectedResponseExceptionType(value = ResourceNotFoundException.class, code = { 404 }) + @UnexpectedResponseExceptionType(value = ResourceModifiedException.class, code = { 409 }) + @UnexpectedResponseExceptionType(HttpResponseException.class) + Response testSync(@HostParam("endpoint") String endpoint, @QueryParam("api-version") String apiVersion, + RequestOptions requestOptions, Context context); + } + + /** + * The test operation. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response} on successful completion of {@link Mono}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Mono> testWithResponseAsync(RequestOptions requestOptions) { + return FluxUtil.withContext(context -> service.test(this.client.getEndpoint(), + this.client.getServiceVersion().getVersion(), requestOptions, context)); + } + + /** + * The test operation. + * + * @param requestOptions The options to configure the HTTP request before HTTP client sends it. + * @throws HttpResponseException thrown if the request is rejected by server. + * @throws ClientAuthenticationException thrown if the request is rejected by server on status code 401. + * @throws ResourceNotFoundException thrown if the request is rejected by server on status code 404. + * @throws ResourceModifiedException thrown if the request is rejected by server on status code 409. + * @return the {@link Response}. + */ + @ServiceMethod(returns = ReturnType.SINGLE) + public Response testWithResponse(RequestOptions requestOptions) { + return service.testSync(this.client.getEndpoint(), this.client.getServiceVersion().getVersion(), requestOptions, + Context.NONE); + } +} diff --git a/typespec-tests/src/main/java/service/multiservice/combined/implementation/package-info.java b/typespec-tests/src/main/java/service/multiservice/combined/implementation/package-info.java new file mode 100644 index 0000000000..abf0c574d6 --- /dev/null +++ b/typespec-tests/src/main/java/service/multiservice/combined/implementation/package-info.java @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * + * Package containing the implementations for ServiceA. + * + */ +package service.multiservice.combined.implementation; diff --git a/typespec-tests/src/main/java/service/multiservice/combined/package-info.java b/typespec-tests/src/main/java/service/multiservice/combined/package-info.java new file mode 100644 index 0000000000..79ea8b07e7 --- /dev/null +++ b/typespec-tests/src/main/java/service/multiservice/combined/package-info.java @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +/** + * + * Package containing the classes for ServiceA. + * + */ +package service.multiservice.combined; diff --git a/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated/proxy-config.json b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated/proxy-config.json new file mode 100644 index 0000000000..425f1c93bd --- /dev/null +++ b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated/proxy-config.json @@ -0,0 +1 @@ +[["azure.resourcemanager.multiservice.combined.implementation.DisksClientImpl$DisksService"],["azure.resourcemanager.multiservice.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/reflect-config.json b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated/reflect-config.json new file mode 100644 index 0000000000..0637a088a0 --- /dev/null +++ b/typespec-tests/src/main/resources/META-INF/native-image/com.azure.resourcemanager/azure-resourcemanager-combined-generated/reflect-config.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/typespec-tests/src/main/resources/azure-resourcemanager-combined-generated.properties b/typespec-tests/src/main/resources/azure-resourcemanager-combined-generated.properties new file mode 100644 index 0000000000..defbd48204 --- /dev/null +++ b/typespec-tests/src/main/resources/azure-resourcemanager-combined-generated.properties @@ -0,0 +1 @@ +version=${project.version} diff --git a/typespec-tests/src/main/resources/service-multiservice-combined.properties b/typespec-tests/src/main/resources/service-multiservice-combined.properties new file mode 100644 index 0000000000..ca812989b4 --- /dev/null +++ b/typespec-tests/src/main/resources/service-multiservice-combined.properties @@ -0,0 +1,2 @@ +name=${project.artifactId} +version=${project.version} diff --git a/typespec-tests/src/test/java/azure/resourcemanager/multiservice/combined/generated/DiskInnerTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiservice/combined/generated/DiskInnerTests.java new file mode 100644 index 0000000000..531354b48f --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiservice/combined/generated/DiskInnerTests.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservice.combined.generated; + +import azure.resourcemanager.multiservice.combined.fluent.models.DiskInner; +import azure.resourcemanager.multiservice.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\":\"Succeeded\"},\"location\":\"zhwlrxy\",\"tags\":{\"obcu\":\"oqijgkdmbpaz\",\"qgn\":\"pdznrbtcqqjnqgl\"},\"id\":\"foooj\",\"name\":\"wifsq\",\"type\":\"saagdf\"}") + .toObject(DiskInner.class); + Assertions.assertEquals("zhwlrxy", model.location()); + Assertions.assertEquals("oqijgkdmbpaz", model.tags().get("obcu")); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + DiskInner model = new DiskInner().withLocation("zhwlrxy") + .withTags(mapOf("obcu", "oqijgkdmbpaz", "qgn", "pdznrbtcqqjnqgl")) + .withProperties(new DiskProperties()); + model = BinaryData.fromObject(model).toObject(DiskInner.class); + Assertions.assertEquals("zhwlrxy", model.location()); + Assertions.assertEquals("oqijgkdmbpaz", model.tags().get("obcu")); + } + + // 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/multiservice/combined/generated/DiskPropertiesTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiservice/combined/generated/DiskPropertiesTests.java new file mode 100644 index 0000000000..1afcf64161 --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiservice/combined/generated/DiskPropertiesTests.java @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservice.combined.generated; + +import azure.resourcemanager.multiservice.combined.models.DiskProperties; +import com.azure.core.util.BinaryData; + +public final class DiskPropertiesTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + DiskProperties model + = BinaryData.fromString("{\"provisioningState\":\"Failed\"}").toObject(DiskProperties.class); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + DiskProperties model = new DiskProperties(); + model = BinaryData.fromObject(model).toObject(DiskProperties.class); + } +} diff --git a/typespec-tests/src/test/java/azure/resourcemanager/multiservice/combined/generated/VirtualMachineInnerTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiservice/combined/generated/VirtualMachineInnerTests.java new file mode 100644 index 0000000000..88ae3ff1b4 --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiservice/combined/generated/VirtualMachineInnerTests.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservice.combined.generated; + +import azure.resourcemanager.multiservice.combined.fluent.models.VirtualMachineInner; +import azure.resourcemanager.multiservice.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\"},\"location\":\"uv\",\"tags\":{\"phrupidgsybbejhp\":\"pybczmehmtzopb\"},\"id\":\"oycmsxaobhdxbmt\",\"name\":\"ioq\",\"type\":\"zehtbmu\"}") + .toObject(VirtualMachineInner.class); + Assertions.assertEquals("uv", model.location()); + Assertions.assertEquals("pybczmehmtzopb", model.tags().get("phrupidgsybbejhp")); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + VirtualMachineInner model = new VirtualMachineInner().withLocation("uv") + .withTags(mapOf("phrupidgsybbejhp", "pybczmehmtzopb")) + .withProperties(new VirtualMachineProperties()); + model = BinaryData.fromObject(model).toObject(VirtualMachineInner.class); + Assertions.assertEquals("uv", model.location()); + Assertions.assertEquals("pybczmehmtzopb", model.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/multiservice/combined/generated/VirtualMachinePropertiesTests.java b/typespec-tests/src/test/java/azure/resourcemanager/multiservice/combined/generated/VirtualMachinePropertiesTests.java new file mode 100644 index 0000000000..d55bd6b30a --- /dev/null +++ b/typespec-tests/src/test/java/azure/resourcemanager/multiservice/combined/generated/VirtualMachinePropertiesTests.java @@ -0,0 +1,22 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package azure.resourcemanager.multiservice.combined.generated; + +import azure.resourcemanager.multiservice.combined.models.VirtualMachineProperties; +import com.azure.core.util.BinaryData; + +public final class VirtualMachinePropertiesTests { + @org.junit.jupiter.api.Test + public void testDeserialize() throws Exception { + VirtualMachineProperties model + = BinaryData.fromString("{\"provisioningState\":\"Canceled\"}").toObject(VirtualMachineProperties.class); + } + + @org.junit.jupiter.api.Test + public void testSerialize() throws Exception { + VirtualMachineProperties model = new VirtualMachineProperties(); + model = BinaryData.fromObject(model).toObject(VirtualMachineProperties.class); + } +} diff --git a/typespec-tests/src/test/java/service/multiservice/combined/generated/CombinedTestBase.java b/typespec-tests/src/test/java/service/multiservice/combined/generated/CombinedTestBase.java new file mode 100644 index 0000000000..9cfd19eabb --- /dev/null +++ b/typespec-tests/src/test/java/service/multiservice/combined/generated/CombinedTestBase.java @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +// Code generated by Microsoft (R) TypeSpec Code Generator. + +package service.multiservice.combined.generated; + +// The Java test files under 'generated' package are generated for your reference. +// If you wish to modify these files, please copy them out of the 'generated' package, and modify there. +// See https://aka.ms/azsdk/dpg/java/tests for guide on adding a test. + +import com.azure.core.http.policy.HttpLogDetailLevel; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.test.TestMode; +import com.azure.core.test.TestProxyTestBase; +import com.azure.core.util.Configuration; +import service.multiservice.combined.BarClient; +import service.multiservice.combined.CombinedBuilder; +import service.multiservice.combined.FooClient; + +class CombinedTestBase extends TestProxyTestBase { + protected FooClient fooClient; + + protected BarClient barClient; + + @Override + protected void beforeTest() { + CombinedBuilder fooClientbuilder = new CombinedBuilder() + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "http://localhost:3000")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.RECORD) { + fooClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + fooClient = fooClientbuilder.buildFooClient(); + + CombinedBuilder barClientbuilder = new CombinedBuilder() + .endpoint(Configuration.getGlobalConfiguration().get("ENDPOINT", "http://localhost:3000")) + .httpClient(getHttpClientOrUsePlayback(getHttpClients().findFirst().orElse(null))) + .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BASIC)); + if (getTestMode() == TestMode.RECORD) { + barClientbuilder.addPolicy(interceptorManager.getRecordPolicy()); + } + barClient = barClientbuilder.buildBarClient(); + + } +}