-
Notifications
You must be signed in to change notification settings - Fork 71
Add multi-service tests for older API versions and shared models #3713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
7a29e54
Initial plan
Copilot 9baf608
Add multi-service test scenarios with older versions and shared models
Copilot 6a52ce4
Fix endpoint paths to avoid duplicates and validate all scenarios
Copilot bf1276f
Apply code formatting to mockapi files
Copilot 70c2543
Address review comments: fix client syntax, add version-specific prop…
Copilot 66217cc
Add changeset for multi-service test scenarios
Copilot d88be72
Update add-multi-service-tests-2026-01-05-08-56-40.md
tadelesh ef686ff
Merge branch 'main' into copilot/add-more-tests-multiple-services
tadelesh 7194a7b
Add namespace to shared models and remove unused imports
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
.chronus/changes/add-multi-service-tests-2026-01-05-08-56-40.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| --- | ||
| changeKind: feature | ||
| packages: | ||
| - "@azure-tools/azure-http-specs" | ||
| --- | ||
|
|
||
| Add multi-service test scenarios for older API versions and shared models. |
20 changes: 20 additions & 0 deletions
20
...ges/azure-http-specs/specs/azure/resource-manager/multi-service-older-versions/client.tsp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import "./service1.tsp"; | ||
| import "./service2.tsp"; | ||
| import "@azure-tools/typespec-client-generator-core"; | ||
|
|
||
| using Versioning; | ||
| using Azure.Core; | ||
| using Azure.ResourceManager; | ||
| using Azure.ClientGenerator.Core; | ||
|
|
||
| @client({ | ||
| service: [ | ||
| Azure.ResourceManager.MultiServiceOlderVersions.Compute, | ||
| Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk | ||
| ], | ||
| }) | ||
| @useDependency( | ||
| Azure.ResourceManager.MultiServiceOlderVersions.Compute.Versions.v2024_11_01, | ||
| Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk.Versions.v2024_03_02 | ||
| ) | ||
| namespace Azure.ResourceManager.MultiServiceOlderVersions.Combined; | ||
118 changes: 118 additions & 0 deletions
118
...ges/azure-http-specs/specs/azure/resource-manager/multi-service-older-versions/mockapi.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api"; | ||
|
|
||
| export const Scenarios: Record<string, ScenarioMockApi> = {}; | ||
|
|
||
| // Mock data for Compute (VirtualMachine) | ||
| const SUBSCRIPTION_ID = "00000000-0000-0000-0000-000000000000"; | ||
| const RESOURCE_GROUP = "test-rg"; | ||
| const LOCATION = "eastus"; | ||
|
|
||
| const virtualMachine = { | ||
| id: `/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP}/providers/Microsoft.Compute/virtualMachinesOld/vm-old1`, | ||
| name: "vm-old1", | ||
| type: "Microsoft.Compute/virtualMachinesOld", | ||
| location: LOCATION, | ||
| properties: { | ||
| provisioningState: "Succeeded", | ||
| size: "Standard_D2s_v3", | ||
| }, | ||
| }; | ||
|
|
||
| // Mock data for ComputeDisk (Disk) | ||
| const disk = { | ||
| id: `/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP}/providers/Microsoft.Compute/disksOld/disk-old1`, | ||
| name: "disk-old1", | ||
| type: "Microsoft.Compute/disksOld", | ||
| location: LOCATION, | ||
| properties: { | ||
| provisioningState: "Succeeded", | ||
| diskSizeGB: 128, | ||
| }, | ||
| }; | ||
|
|
||
| // Scenario: Get Virtual Machine | ||
| Scenarios.Azure_ResourceManager_MultiServiceOlderVersions_Compute_VirtualMachines_get = | ||
| passOnSuccess([ | ||
| { | ||
| uri: `/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP}/providers/Microsoft.Compute/virtualMachinesOld/vm-old1`, | ||
| method: "get", | ||
| request: { | ||
| query: { | ||
| "api-version": "2024-11-01", | ||
| }, | ||
| }, | ||
| response: { | ||
| status: 200, | ||
| body: json(virtualMachine), | ||
| }, | ||
| kind: "MockApiDefinition", | ||
| }, | ||
| ]); | ||
|
|
||
| // Scenario: Create or Update Virtual Machine | ||
| Scenarios.Azure_ResourceManager_MultiServiceOlderVersions_Compute_VirtualMachines_createOrUpdate = | ||
| passOnSuccess([ | ||
| { | ||
| uri: `/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP}/providers/Microsoft.Compute/virtualMachinesOld/vm-old1`, | ||
| method: "put", | ||
| request: { | ||
| query: { | ||
| "api-version": "2024-11-01", | ||
| }, | ||
| body: json({ | ||
| location: LOCATION, | ||
| properties: { | ||
| size: "Standard_D2s_v3", | ||
| }, | ||
| }), | ||
| }, | ||
| response: { | ||
| status: 200, | ||
| body: json(virtualMachine), | ||
| }, | ||
| kind: "MockApiDefinition", | ||
| }, | ||
| ]); | ||
|
|
||
| // Scenario: Get Disk | ||
| Scenarios.Azure_ResourceManager_MultiServiceOlderVersions_ComputeDisk_Disks_get = passOnSuccess([ | ||
| { | ||
| uri: `/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP}/providers/Microsoft.Compute/disksOld/disk-old1`, | ||
| method: "get", | ||
| request: { | ||
| query: { | ||
| "api-version": "2024-03-02", | ||
| }, | ||
| }, | ||
| response: { | ||
| status: 200, | ||
| body: json(disk), | ||
| }, | ||
| kind: "MockApiDefinition", | ||
| }, | ||
| ]); | ||
|
|
||
| // Scenario: Create or Update Disk | ||
| Scenarios.Azure_ResourceManager_MultiServiceOlderVersions_ComputeDisk_Disks_createOrUpdate = | ||
| passOnSuccess([ | ||
| { | ||
| uri: `/subscriptions/${SUBSCRIPTION_ID}/resourceGroups/${RESOURCE_GROUP}/providers/Microsoft.Compute/disksOld/disk-old1`, | ||
| method: "put", | ||
| request: { | ||
| query: { | ||
| "api-version": "2024-03-02", | ||
| }, | ||
| body: json({ | ||
| location: LOCATION, | ||
| properties: { | ||
| diskSizeGB: 128, | ||
| }, | ||
| }), | ||
| }, | ||
| response: { | ||
| status: 200, | ||
| body: json(disk), | ||
| }, | ||
| kind: "MockApiDefinition", | ||
| }, | ||
| ]); |
120 changes: 120 additions & 0 deletions
120
...s/azure-http-specs/specs/azure/resource-manager/multi-service-older-versions/service1.tsp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| import "@typespec/versioning"; | ||
| import "@azure-tools/typespec-azure-resource-manager"; | ||
| import "@typespec/spector"; | ||
|
|
||
| using TypeSpec.Versioning; | ||
| using Spector; | ||
|
|
||
| /** | ||
| * Compute Client | ||
| */ | ||
| @armProviderNamespace("Microsoft.Compute") | ||
| @service(#{ title: "Azure Compute resource management API." }) | ||
| @versioned(Versions) | ||
| namespace Azure.ResourceManager.MultiServiceOlderVersions.Compute; | ||
|
|
||
| /** | ||
| * The available API versions. | ||
| */ | ||
| enum Versions { | ||
| /** | ||
| * The 2024-11-01 API version. | ||
| */ | ||
| @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v3) | ||
| v2024_11_01: "2024-11-01", | ||
|
|
||
| /** | ||
| * The 2025-04-01 API version. | ||
| */ | ||
| @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v3) | ||
| v2025_04_01: "2025-04-01", | ||
| } | ||
|
|
||
| /** | ||
| * Describes a Virtual Machine. | ||
| */ | ||
| model VirtualMachine is Azure.ResourceManager.TrackedResource<VirtualMachineProperties> { | ||
| ...ResourceNameParameter< | ||
| Resource = VirtualMachine, | ||
| KeyName = "vmName", | ||
| SegmentName = "virtualMachinesOld", | ||
| NamePattern = "" | ||
| >; | ||
| } | ||
|
|
||
| model VirtualMachineProperties { | ||
| @visibility(Lifecycle.Read) | ||
| provisioningState?: ResourceProvisioningState; | ||
tadelesh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Size of the virtual machine. Only available in version 2024-11-01. | ||
| */ | ||
| @added(Versions.v2024_11_01) | ||
| @removed(Versions.v2025_04_01) | ||
| size?: string; | ||
| } | ||
|
|
||
| @armResourceOperations | ||
| interface VirtualMachines { | ||
| /** | ||
| * Retrieves information about the model view or the instance view of a virtual machine. | ||
| */ | ||
| @scenario | ||
| @scenarioDoc(""" | ||
| Test that a client can expose operations from multiple services using older API versions. This operation should be called like this: `client.virtualMachines.get(...)`. | ||
|
|
||
| GET a Virtual Machine. | ||
| Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.Compute/virtualMachinesOld/vm-old1 | ||
| Expected query parameter: api-version=2024-11-01 | ||
|
|
||
| Expected response body: | ||
| ```json | ||
| { | ||
| "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.Compute/virtualMachinesOld/vm-old1", | ||
| "name": "vm-old1", | ||
| "type": "Microsoft.Compute/virtualMachinesOld", | ||
| "location": "eastus", | ||
| "properties": { | ||
| "provisioningState": "Succeeded", | ||
| "size": "Standard_D2s_v3" | ||
| } | ||
| } | ||
| ``` | ||
| """) | ||
| get is ArmResourceRead<VirtualMachine>; | ||
|
|
||
| /** | ||
| * The operation to create or update a virtual machine. Please note some properties can be set only during virtual machine creation. | ||
| */ | ||
| @scenario | ||
| @scenarioDoc(""" | ||
| Test that a client can expose operations from multiple services using older API versions. This operation should be called like this: `client.virtualMachines.createOrUpdate(...)`. | ||
|
|
||
| PUT (create or update) a Virtual Machine. | ||
| Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.Compute/virtualMachinesOld/vm-old1 | ||
| Expected query parameter: api-version=2024-11-01 | ||
| Expected request body: | ||
| ```json | ||
| { | ||
| "location": "eastus", | ||
| "properties": { | ||
| "size": "Standard_D2s_v3" | ||
| } | ||
| } | ||
| ``` | ||
| Expected response body: | ||
| ```json | ||
| { | ||
| "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.Compute/virtualMachinesOld/vm-old1", | ||
| "name": "vm-old1", | ||
| "type": "Microsoft.Compute/virtualMachinesOld", | ||
| "location": "eastus", | ||
| "properties": { | ||
| "provisioningState": "Succeeded", | ||
| "size": "Standard_D2s_v3" | ||
| } | ||
| } | ||
| ``` | ||
| """) | ||
| createOrUpdate is ArmResourceCreateOrUpdateAsync<VirtualMachine>; | ||
| } | ||
123 changes: 123 additions & 0 deletions
123
...s/azure-http-specs/specs/azure/resource-manager/multi-service-older-versions/service2.tsp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| import "@typespec/versioning"; | ||
| import "@azure-tools/typespec-azure-resource-manager"; | ||
| import "@typespec/spector"; | ||
|
|
||
| using TypeSpec.Versioning; | ||
| using Spector; | ||
|
|
||
| /** | ||
| * Compute Disk Client | ||
| */ | ||
| @armProviderNamespace("Microsoft.Compute") | ||
| @service(#{ title: "Azure Compute Disk resource management API." }) | ||
| @versioned(Versions) | ||
| namespace Azure.ResourceManager.MultiServiceOlderVersions.ComputeDisk; | ||
|
|
||
| /** | ||
| * The available API versions. | ||
| */ | ||
| enum Versions { | ||
| /** | ||
| * The 2024-03-02 API version. | ||
| */ | ||
| @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v3) | ||
| v2024_03_02: "2024-03-02", | ||
|
|
||
| /** | ||
| * The 2025-01-02 API version. | ||
| */ | ||
| @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v3) | ||
| v2025_01_02: "2025-01-02", | ||
| } | ||
|
|
||
| /** | ||
| * Disk resource. | ||
| */ | ||
| model Disk is Azure.ResourceManager.TrackedResource<DiskProperties> { | ||
| ...ResourceNameParameter< | ||
| Resource = Disk, | ||
| KeyName = "diskName", | ||
| SegmentName = "disksOld", | ||
| NamePattern = "" | ||
| >; | ||
| } | ||
|
|
||
| /** | ||
| * Disk resource properties. | ||
| */ | ||
| model DiskProperties { | ||
| @visibility(Lifecycle.Read) | ||
| provisioningState?: ResourceProvisioningState; | ||
tadelesh marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /** | ||
| * Size of the disk in GB. Only available in version 2024-03-02. | ||
| */ | ||
| @added(Versions.v2024_03_02) | ||
| @removed(Versions.v2025_01_02) | ||
| diskSizeGB?: int32; | ||
| } | ||
|
|
||
| @armResourceOperations | ||
| interface Disks { | ||
| /** | ||
| * Gets information about a disk. | ||
| */ | ||
| @scenario | ||
| @scenarioDoc(""" | ||
| Test that a client can expose operations from multiple services using older API versions. This operation should be called like this: `client.disks.get(...)`. | ||
|
|
||
| GET a Disk resource. | ||
| Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.Compute/disksOld/disk-old1 | ||
| Expected query parameter: api-version=2024-03-02 | ||
|
|
||
| Expected response body: | ||
| ```json | ||
| { | ||
| "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.Compute/disksOld/disk-old1", | ||
| "name": "disk-old1", | ||
| "type": "Microsoft.Compute/disksOld", | ||
| "location": "eastus", | ||
| "properties": { | ||
| "provisioningState": "Succeeded", | ||
| "diskSizeGB": 128 | ||
| } | ||
| } | ||
| ``` | ||
| """) | ||
| get is ArmResourceRead<Disk>; | ||
|
|
||
| /** | ||
| * Creates or updates a disk. | ||
| */ | ||
| @scenario | ||
| @scenarioDoc(""" | ||
| Test that a client can expose operations from multiple services using older API versions. This operation should be called like this: `client.disks.createOrUpdate(...)`. | ||
|
|
||
| PUT (create or update) a Disk resource. | ||
| Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.Compute/disksOld/disk-old1 | ||
| Expected query parameter: api-version=2024-03-02 | ||
| Expected request body: | ||
| ```json | ||
| { | ||
| "location": "eastus", | ||
| "properties": { | ||
| "diskSizeGB": 128 | ||
| } | ||
| } | ||
| ``` | ||
| Expected response body: | ||
| ```json | ||
| { | ||
| "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Microsoft.Compute/disksOld/disk-old1", | ||
| "name": "disk-old1", | ||
| "type": "Microsoft.Compute/disksOld", | ||
| "location": "eastus", | ||
| "properties": { | ||
| "provisioningState": "Succeeded", | ||
| "diskSizeGB": 128 | ||
| } | ||
| } | ||
| ``` | ||
| """) | ||
| createOrUpdate is ArmResourceCreateOrUpdateAsync<Disk>; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.