From 165f4c05a8ef3291e9b6a6dac0fc9ca27e3435bf Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Fri, 29 Nov 2024 16:20:32 +0800 Subject: [PATCH 1/6] azure-http-specs, add ARM listing available operations case --- packages/azure-http-specs/spec-summary.md | 28 +++++++++++++ .../available-operations.tsp | 39 +++++++++++++++++++ .../operation-templates/main.tsp | 29 ++++++++++++++ .../operation-templates/mockapi.ts | 34 ++++++++++++++++ 4 files changed, 130 insertions(+) create mode 100644 packages/azure-http-specs/specs/azure/resource-manager/operation-templates/available-operations.tsp create mode 100644 packages/azure-http-specs/specs/azure/resource-manager/operation-templates/main.tsp create mode 100644 packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts diff --git a/packages/azure-http-specs/spec-summary.md b/packages/azure-http-specs/spec-summary.md index 200e433552..1306fbac8a 100644 --- a/packages/azure-http-specs/spec-summary.md +++ b/packages/azure-http-specs/spec-summary.md @@ -836,6 +836,34 @@ Expected response body: } ``` +### Azure_ResourceManager_OperationTemplates_ListAvailableOperations + +- Endpoint: `get https://management.azure.com` + + Resource GET operation. + Expected path: /providers/Azure.ResourceManager.Models.Resources/operations + Expected query parameter: api-version=2023-12-01-preview + Expected response body: + + ```json + { + "value": [ + { + "name": "Microsoft.Compute/virtualMachines/write", + "isDataAction": false, + "display": { + "provider": "Microsoft Compute", + "resource": "Virtual Machines", + "operation": "Create or Update Virtual Machine.", + "description": "Add or modify virtual machines." + }, + "origin": "user,system", + "actionType": "Internal" + } + ] + } + ``` + ### Azure_ResourceManager_Resources_Nested_createOrReplace - Endpoint: `put https://management.azure.com` diff --git a/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/available-operations.tsp b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/available-operations.tsp new file mode 100644 index 0000000000..f61018af35 --- /dev/null +++ b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/available-operations.tsp @@ -0,0 +1,39 @@ +import "@typespec/http"; +import "@typespec/rest"; +import "@azure-tools/typespec-azure-core"; +import "@azure-tools/typespec-azure-resource-manager"; +import "@typespec/spector"; + +using TypeSpec.Http; +using TypeSpec.Rest; +using Azure.Core; +using Azure.ResourceManager; +using TypeSpec.OpenAPI; +using Spector; + +namespace Azure.ResourceManager.OperationTemplates; + +@scenario("ListAvailableOperations") +@scenarioDoc(""" + Resource GET operation. + Expected path: /providers/Azure.ResourceManager.Models.Resources/operations + Expected query parameter: api-version=2023-12-01-preview + Expected response body: + ```json + { + "value": [{ + "name": "Microsoft.Compute/virtualMachines/write", + "isDataAction": false, + "display": { + "provider": "Microsoft Compute", + "resource": "Virtual Machines", + "operation": "Create or Update Virtual Machine.", + "description": "Add or modify virtual machines.", + }, + "origin": "user,system", + "actionType": "Internal", + }] + } + ``` + """) +interface Operations extends Azure.ResourceManager.Operations {} diff --git a/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/main.tsp b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/main.tsp new file mode 100644 index 0000000000..d4b403b855 --- /dev/null +++ b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/main.tsp @@ -0,0 +1,29 @@ +import "@typespec/http"; +import "@typespec/rest"; +import "@typespec/versioning"; +import "@azure-tools/typespec-azure-core"; +import "@azure-tools/typespec-azure-resource-manager"; +import "@azure-tools/typespec-client-generator-core"; +import "./available-operations.tsp"; + +using TypeSpec.Http; +using TypeSpec.Rest; +using TypeSpec.Versioning; +using Azure.Core; +using Azure.ResourceManager; +using TypeSpec.OpenAPI; + +@armProviderNamespace +@service +@versioned(Versions) +@doc("Arm Resource Provider management API.") +namespace Azure.ResourceManager.OperationTemplates; + +@doc("Azure API versions.") +enum Versions { + @armCommonTypesVersion(CommonTypes.Versions.v5) + @useDependency(Azure.Core.Versions.v1_0_Preview_2) + @useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1) + @doc("Preview API version 2023-12-01-preview.") + v2023_12_01_preview: "2023-12-01-preview", +} diff --git a/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts new file mode 100644 index 0000000000..1084123662 --- /dev/null +++ b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts @@ -0,0 +1,34 @@ +import { json, passOnSuccess, ScenarioMockApi } from "@typespec/spec-api"; + +export const Scenarios: Record = {}; + +const validAvailableOperations = { + name: "Microsoft.Compute/virtualMachines/write", + isDataAction: false, + display: { + provider: "Microsoft Compute", + resource: "Virtual Machines", + operation: "Create or Update Virtual Machine.", + description: "Add or modify virtual machines.", + }, + origin: "user,system", + actionType: "Internal", +}; + +// operation list +Scenarios.Azure_ResourceManager_OperationTemplates_ListAvailableOperations = passOnSuccess({ + uri: "/providers/Azure.ResourceManager.OperationTemplates/operations", + method: "get", + request: { + params: { + "api-version": "2023-12-01-preview", + }, + }, + response: { + status: 200, + body: json({ + value: [validAvailableOperations], + }), + }, + kind: "MockApiDefinition", +}); From 1f71d1b35a1bfe6ceee1894285dd46f9aca25e07 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Fri, 29 Nov 2024 16:24:40 +0800 Subject: [PATCH 2/6] changelog --- ...arm_listing_available_operations-2024-10-29-16-23-15.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/specs_arm_listing_available_operations-2024-10-29-16-23-15.md diff --git a/.chronus/changes/specs_arm_listing_available_operations-2024-10-29-16-23-15.md b/.chronus/changes/specs_arm_listing_available_operations-2024-10-29-16-23-15.md new file mode 100644 index 0000000000..e575d1085c --- /dev/null +++ b/.chronus/changes/specs_arm_listing_available_operations-2024-10-29-16-23-15.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@azure-tools/azure-http-specs" +--- + +Added listing available operations case for ARM tests. \ No newline at end of file From cb5d1b76b23876283108e01e5408fab9c6d1ecd1 Mon Sep 17 00:00:00 2001 From: "Hong Li(MSFT)" <74638143+v-hongli1@users.noreply.github.com> Date: Mon, 23 Dec 2024 09:46:34 +0000 Subject: [PATCH 3/6] fix format --- packages/azure-http-specs/spec-summary.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/azure-http-specs/spec-summary.md b/packages/azure-http-specs/spec-summary.md index ec5e01824e..044f6e1f5c 100644 --- a/packages/azure-http-specs/spec-summary.md +++ b/packages/azure-http-specs/spec-summary.md @@ -915,7 +915,7 @@ Expected response body: } } ``` - + ### Azure_ResourceManager_OperationTemplates_ListAvailableOperations - Endpoint: `get https://management.azure.com` @@ -924,6 +924,7 @@ Resource GET operation. Expected path: /providers/Azure.ResourceManager.Models.Resources/operations Expected query parameter: api-version=2023-12-01-preview Expected response body: + ```json { "value": [ From 627a90e082e6e2488ebd5459716755936fefbd92 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Tue, 24 Dec 2024 14:41:38 +0800 Subject: [PATCH 4/6] fix comments --- packages/azure-http-specs/spec-summary.md | 2 +- .../operation-templates/available-operations.tsp | 2 +- .../azure/resource-manager/operation-templates/mockapi.ts | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/azure-http-specs/spec-summary.md b/packages/azure-http-specs/spec-summary.md index 044f6e1f5c..ea0035974f 100644 --- a/packages/azure-http-specs/spec-summary.md +++ b/packages/azure-http-specs/spec-summary.md @@ -921,7 +921,7 @@ Expected response body: - Endpoint: `get https://management.azure.com` Resource GET operation. -Expected path: /providers/Azure.ResourceManager.Models.Resources/operations +Expected path: /providers/Azure.ResourceManager.OperationTemplates/operations Expected query parameter: api-version=2023-12-01-preview Expected response body: diff --git a/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/available-operations.tsp b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/available-operations.tsp index f61018af35..a31e0d1c24 100644 --- a/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/available-operations.tsp +++ b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/available-operations.tsp @@ -16,7 +16,7 @@ namespace Azure.ResourceManager.OperationTemplates; @scenario("ListAvailableOperations") @scenarioDoc(""" Resource GET operation. - Expected path: /providers/Azure.ResourceManager.Models.Resources/operations + Expected path: /providers/Azure.ResourceManager.OperationTemplates/operations Expected query parameter: api-version=2023-12-01-preview Expected response body: ```json diff --git a/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts index bd9eacc1f8..345b826bd6 100644 --- a/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts +++ b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts @@ -29,7 +29,7 @@ const validOrder = { lastModifiedByType: "User", }, }; -const validAvailableOperations = { +const validOperation = { name: "Microsoft.Compute/virtualMachines/write", isDataAction: false, display: { @@ -57,7 +57,7 @@ Scenarios.Azure_ResourceManager_OperationTemplates_ListAvailableOperations = pas response: { status: 200, body: json({ - value: [validAvailableOperations], + value: [validOperation], }), }, kind: "MockApiDefinition", From dda8e69ae418a5934466a5095639f1ef74adc6d7 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Wed, 25 Dec 2024 13:47:10 +0800 Subject: [PATCH 5/6] fix format --- .../resource-manager/operation-templates/mockapi.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts index 8199332f5f..e0c9d785cf 100644 --- a/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts +++ b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts @@ -40,7 +40,7 @@ const validOperation = { }, origin: "user,system", actionType: "Internal", -} +}; const checkNameAvailabilityResponse = { nameAvailable: false, reason: "AlreadyExists", @@ -69,8 +69,8 @@ Scenarios.Azure_ResourceManager_OperationTemplates_ListAvailableOperations = pas }); // Check Global Name Availability -Scenarios.Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkGlobal = - passOnSuccess({ +Scenarios.Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkGlobal = passOnSuccess( + { uri: "/subscriptions/:subscriptionId/providers/Azure.ResourceManager.OperationTemplates/checkNameAvailability", method: "post", request: { @@ -88,7 +88,8 @@ Scenarios.Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkGl body: json(checkNameAvailabilityResponse), }, kind: "MockApiDefinition", - }); + } +); // Check Local Name Availability Scenarios.Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkLocal = passOnSuccess( From 1143f4cbd7bbb51cf1396b1506894278b0586e52 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Wed, 25 Dec 2024 14:10:36 +0800 Subject: [PATCH 6/6] fix format --- .../azure/resource-manager/operation-templates/mockapi.ts | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts index e0c9d785cf..3dc7add6c4 100644 --- a/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts +++ b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/mockapi.ts @@ -69,8 +69,8 @@ Scenarios.Azure_ResourceManager_OperationTemplates_ListAvailableOperations = pas }); // Check Global Name Availability -Scenarios.Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkGlobal = passOnSuccess( - { +Scenarios.Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkGlobal = + passOnSuccess({ uri: "/subscriptions/:subscriptionId/providers/Azure.ResourceManager.OperationTemplates/checkNameAvailability", method: "post", request: { @@ -88,8 +88,7 @@ Scenarios.Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkGl body: json(checkNameAvailabilityResponse), }, kind: "MockApiDefinition", - } -); + }); // Check Local Name Availability Scenarios.Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkLocal = passOnSuccess(