From a67aa940abdbf7165d62d7d59d43f5678de27b88 Mon Sep 17 00:00:00 2001 From: hongli750210 Date: Fri, 29 Nov 2024 14:25:17 +0800 Subject: [PATCH] azure-http-specs, add ARM Location-Based case --- packages/azure-http-specs/spec-summary.md | 150 +++++++++++++++ .../resource-manager/resources/location.tsp | 175 ++++++++++++++++++ .../azure/resource-manager/resources/main.tsp | 1 + .../resource-manager/resources/mockapi.ts | 134 ++++++++++++++ 4 files changed, 460 insertions(+) create mode 100644 packages/azure-http-specs/specs/azure/resource-manager/resources/location.tsp diff --git a/packages/azure-http-specs/spec-summary.md b/packages/azure-http-specs/spec-summary.md index 200e433552..1cbd459f6b 100644 --- a/packages/azure-http-specs/spec-summary.md +++ b/packages/azure-http-specs/spec-summary.md @@ -836,6 +836,156 @@ Expected response body: } ``` +### Azure_ResourceManager_Resources_LocationResources_createOrUpdate + +- Endpoint: `put https://management.azure.com` + +Resource PUT operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource +Expected query parameter: api-version=2022-12-01-preview +Expected request body: + +```json +{ + "properties": { + "description": "valid" + } +} +``` + +Expected response body: + +```json +{ + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource", + "name": "resource", + "type": "Azure.ResourceManager.Resources/locationResources", + "properties": { + "description": "valid", + "provisioningState": "Succeeded", + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } +} +``` + +### Azure_ResourceManager_Resources_LocationResources_delete + +- Endpoint: `delete https://management.azure.com` + +Resource DELETE operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource +Expected query parameter: api-version=2023-12-01-preview + +```` +Expected response status code: 204 + +### Azure_ResourceManager_Resources_LocationResources_get + +- Endpoint: `get https://management.azure.com` + +Resource GET operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource +Expected query parameter: api-version=2023-12-01-preview + +Expected response body: +```json +{ + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource", + "name": "resource", + "type": "Azure.ResourceManager.Resources/locationResources", + "properties":{ + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } +} +```` + +### Azure_ResourceManager_Resources_LocationResources_listByParent + +- Endpoint: `get https://management.azure.com` + +Resource LIST by resource group operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources +Expected query parameter: api-version=2023-12-01-preview + +Expected response body: + +```json +{ + "value": [{ + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource", + "name": "resource", + "type": "Azure.ResourceManager.Resources/locationResources", + "properties":{ + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + }] +} +``` + +### Azure_ResourceManager_Resources_LocationResources_update + +- Endpoint: `patch https://management.azure.com` + +Resource PATCH operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource +Expected query parameter: api-version=2023-12-01-preview +Expected request body: + +```json +{ + "properties": { + "description": "valid2" + } +} +``` + +Expected response body: + +```json +{ + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource", + "name": "resource", + "type": "Azure.ResourceManager.Resources/locationResources", + "properties":{ + "description": "valid2", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } +} +``` + ### Azure_ResourceManager_Resources_Nested_createOrReplace - Endpoint: `put https://management.azure.com` diff --git a/packages/azure-http-specs/specs/azure/resource-manager/resources/location.tsp b/packages/azure-http-specs/specs/azure/resource-manager/resources/location.tsp new file mode 100644 index 0000000000..5c716200d6 --- /dev/null +++ b/packages/azure-http-specs/specs/azure/resource-manager/resources/location.tsp @@ -0,0 +1,175 @@ +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.Resources; + +@resource("locationResources") +@parentResource(ResourceGroupLocationResource) +model LocationResource is ProxyResource { + ...ResourceNameParameter; +} + +/** Location resource properties */ +model LocationResourceProperties { + @doc("The description of the resource.") + description?: string; + + /** The status of the last operation. */ + @visibility("read") + provisioningState?: ProvisioningState; +} + +@armResourceOperations +interface LocationResources { + @scenario + @scenarioDoc(""" + Resource GET operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource + Expected query parameter: api-version=2023-12-01-preview + + Expected response body: + ```json + { + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource", + "name": "resource", + "type": "Azure.ResourceManager.Resources/locationResources", + "properties":{ + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + } + ``` + """) + get is ArmResourceRead; + + @scenario + @scenarioDoc(""" + Resource PUT operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource + Expected query parameter: api-version=2022-12-01-preview + Expected request body: + ```json + { + "properties": { + "description": "valid", + } + } + ``` + Expected response body: + ```json + { + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource", + "name": "resource", + "type": "Azure.ResourceManager.Resources/locationResources", + "properties": { + "description": "valid", + "provisioningState": "Succeeded", + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + } + ``` + """) + createOrUpdate is ArmResourceCreateOrUpdateAsync; + + @scenario + @scenarioDoc(""" + Resource PATCH operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource + Expected query parameter: api-version=2023-12-01-preview + Expected request body: + ```json + { + "properties": { + "description": "valid2", + } + } + ``` + Expected response body: + ```json + { + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource", + "name": "resource", + "type": "Azure.ResourceManager.Resources/locationResources", + "properties":{ + "description": "valid2", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + } + ``` + """) + update is ArmResourcePatchSync; + + @scenario + @scenarioDoc(""" + Resource DELETE operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource + Expected query parameter: api-version=2023-12-01-preview + ``` + Expected response status code: 204 + """) + delete is ArmResourceDeleteSync; + + @scenario + @scenarioDoc(""" + Resource LIST by resource group operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources + Expected query parameter: api-version=2023-12-01-preview + + Expected response body: + ```json + { + "value": [{ + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.ResourceManager.Resources/locations/eastus/locationResources/resource", + "name": "resource", + "type": "Azure.ResourceManager.Resources/locationResources", + "properties":{ + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + }] + } + ``` + """) + listByParent is ArmResourceListByParent; +} diff --git a/packages/azure-http-specs/specs/azure/resource-manager/resources/main.tsp b/packages/azure-http-specs/specs/azure/resource-manager/resources/main.tsp index 6cfddb625c..7f5e5f47d2 100644 --- a/packages/azure-http-specs/specs/azure/resource-manager/resources/main.tsp +++ b/packages/azure-http-specs/specs/azure/resource-manager/resources/main.tsp @@ -7,6 +7,7 @@ import "@azure-tools/typespec-client-generator-core"; import "./toplevel.tsp"; import "./nested.tsp"; import "./singleton.tsp"; +import "./location.tsp"; using TypeSpec.Http; using TypeSpec.Rest; diff --git a/packages/azure-http-specs/specs/azure/resource-manager/resources/mockapi.ts b/packages/azure-http-specs/specs/azure/resource-manager/resources/mockapi.ts index 78e5dd3f64..a11fe7395a 100644 --- a/packages/azure-http-specs/specs/azure/resource-manager/resources/mockapi.ts +++ b/packages/azure-http-specs/specs/azure/resource-manager/resources/mockapi.ts @@ -4,6 +4,7 @@ export const Scenarios: Record = {}; const SUBSCRIPTION_ID_EXPECTED = "00000000-0000-0000-0000-000000000000"; const RESOURCE_GROUP_EXPECTED = "test-rg"; +const LOCATION_EXPECTED = "eastus"; const validTopLevelResource = { id: `/subscriptions/${SUBSCRIPTION_ID_EXPECTED}/resourceGroups/${RESOURCE_GROUP_EXPECTED}/providers/Azure.ResourceManager.Resources/topLevelTrackedResources/top`, name: "top", @@ -60,6 +61,139 @@ const validSingletonResource = { }, }; +const validResourceGroupLocationResource = { + id: `/subscriptions/${SUBSCRIPTION_ID_EXPECTED}/resourceGroups/${RESOURCE_GROUP_EXPECTED}/providers/Azure.ResourceManager.Resources/locations/${LOCATION_EXPECTED}/locationResources/resource`, + name: "resource", + type: "Azure.ResourceManager.Resources/locationResources", + properties: { + description: "valid", + provisioningState: "Succeeded", + }, + systemData: { + createdBy: "AzureSDK", + createdByType: "User", + createdAt: "2024-10-04T00:56:07.442Z", + lastModifiedBy: "AzureSDK", + lastModifiedAt: "2024-10-04T00:56:07.442Z", + lastModifiedByType: "User", + }, +}; + +// location resource +Scenarios.Azure_ResourceManager_Resources_LocationResources_get = passOnSuccess({ + uri: "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.ResourceManager.Resources/locations/:location/locationResources/:locationResourceName", + method: "get", + request: { + params: { + subscriptionId: SUBSCRIPTION_ID_EXPECTED, + resourceGroup: RESOURCE_GROUP_EXPECTED, + location: LOCATION_EXPECTED, + locationResourceName: "resource", + "api-version": "2023-12-01-preview", + }, + }, + response: { + status: 200, + body: json(validResourceGroupLocationResource), + }, + kind: "MockApiDefinition", +}); + +Scenarios.Azure_ResourceManager_Resources_LocationResources_createOrUpdate = passOnSuccess({ + uri: "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.ResourceManager.Resources/locations/:location/locationResources/:locationResourceName", + method: "put", + request: { + params: { + subscriptionId: SUBSCRIPTION_ID_EXPECTED, + resourceGroup: RESOURCE_GROUP_EXPECTED, + location: LOCATION_EXPECTED, + locationResourceName: "resource", + "api-version": "2023-12-01-preview", + }, + body: { + properties: { + description: "valid", + }, + }, + }, + response: { + status: 200, + body: json(validResourceGroupLocationResource), + }, + kind: "MockApiDefinition", +}); + +Scenarios.Azure_ResourceManager_Resources_LocationResources_update = passOnSuccess({ + uri: "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.ResourceManager.Resources/locations/:location/locationResources/:locationResourceName", + method: "patch", + request: { + params: { + subscriptionId: SUBSCRIPTION_ID_EXPECTED, + resourceGroup: RESOURCE_GROUP_EXPECTED, + location: LOCATION_EXPECTED, + locationResourceName: "resource", + "api-version": "2023-12-01-preview", + }, + body: { + properties: { + description: "valid2", + }, + }, + headers: { + "Content-Type": "application/merge-patch+json", + }, + }, + response: { + status: 200, + body: json({ + ...validResourceGroupLocationResource, + properties: { + provisioningState: "Succeeded", + description: "valid2", + }, + }), + }, + kind: "MockApiDefinition", +}); + +Scenarios.Azure_ResourceManager_Resources_LocationResources_delete = passOnSuccess({ + uri: "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.ResourceManager.Resources/locations/:location/locationResources/:locationResourceName", + method: "delete", + request: { + params: { + subscriptionId: SUBSCRIPTION_ID_EXPECTED, + resourceGroup: RESOURCE_GROUP_EXPECTED, + location: LOCATION_EXPECTED, + locationResourceName: "resource", + "api-version": "2023-12-01-preview", + }, + }, + response: { + status: 204, + }, + kind: "MockApiDefinition", +}); + +Scenarios.Azure_ResourceManager_Resources_LocationResources_listByParent = passOnSuccess({ + uri: "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.ResourceManager.Resources/locations/:location/locationResources", + method: "get", + request: { + params: { + subscriptionId: SUBSCRIPTION_ID_EXPECTED, + resourceGroup: RESOURCE_GROUP_EXPECTED, + location: LOCATION_EXPECTED, + "api-version": "2023-12-01-preview", + }, + }, + response: { + status: 200, + body: json({ + value: [validResourceGroupLocationResource], + }), + }, + kind: "MockApiDefinition", +}); + // singleton tracked resource Scenarios.Azure_ResourceManager_Resources_Singleton_getByResourceGroup = passOnSuccess({ uri: "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.ResourceManager.Resources/singletonTrackedResources/default",