diff --git a/.changeset/short-owls-think.md b/.changeset/short-owls-think.md new file mode 100644 index 000000000..f139926fc --- /dev/null +++ b/.changeset/short-owls-think.md @@ -0,0 +1,5 @@ +--- +"@azure-tools/cadl-ranch-specs": minor +--- + +Added tests for ARM's tracked resource and nested resource. diff --git a/packages/cadl-ranch-specs/cadl-ranch-summary.md b/packages/cadl-ranch-specs/cadl-ranch-summary.md index 5577fa644..1825504de 100644 --- a/packages/cadl-ranch-specs/cadl-ranch-summary.md +++ b/packages/cadl-ranch-specs/cadl-ranch-summary.md @@ -71,6 +71,343 @@ Expects header 'x-ms-api-key': 'valid-key' Expects header 'authorization': 'Bearer https://security.microsoft.com/.default' +### Azure_Arm_Models_Resources_NestedProxyResources_createOrReplace + +- Endpoint: `put https://management.azure.com` + +Resource PUT operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested +Expected query parameter: api-version=2023-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.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested", + "name": "nested", + "type": "nested", + "properties":{ + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } +} +``` + +### Azure_Arm_Models_Resources_NestedProxyResources_delete + +- Endpoint: `delete https://management.azure.com` + +Resource DELETE operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested +Expected query parameter: api-version=2023-12-01-preview +Expected response status code: 204 + +### Azure_Arm_Models_Resources_NestedProxyResources_get + +- Endpoint: `get https://management.azure.com` + +Resource GET operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested +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.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested", + "name": "nested", + "type": "nested", + "properties":{ + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } +} +``` + +### Azure_Arm_Models_Resources_NestedProxyResources_listByTopLevelTrackedResource + +- Endpoint: `get https://management.azure.com` + +Resource LIST by parent resource operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested +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.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested", + "name": "nested", + "type": "nested", + "properties":{ + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + }] +} +``` + +### Azure_Arm_Models_Resources_NestedProxyResources_update + +- Endpoint: `patch https://management.azure.com` + +Resource PATCH operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested +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.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested", + "name": "nested", + "type": "nested", + "properties":{ + "description": "valid2", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } +} +``` + +### Azure_Arm_Models_Resources_TopLevelTrackedResources_createOrReplace + +- Endpoint: `put https://management.azure.com` + +Resource PUT operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top +Expected query parameter: api-version=2023-12-01-preview +Expected request body: + +```json +{ + "location": "eastus", + "properties": { + "description": "valid" + } +} +``` + +Expected response body: + +```json +{ + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top", + "name": "top", + "type": "topLevel", + "location": "eastus", + "properties": { + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } +} +``` + +### Azure_Arm_Models_Resources_TopLevelTrackedResources_delete + +- Endpoint: `delete https://management.azure.com` + +Resource DELETE operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top +Expected query parameter: api-version=2023-12-01-preview + +```` +Expected response status code: 204 + +### Azure_Arm_Models_Resources_TopLevelTrackedResources_get + +- Endpoint: `get https://management.azure.com` + +Resource GET operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top +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.Arm.Models.Resources/topLevelTrackedResources/top", + "name": "top", + "type": "topLevel", + "location": "eastus", + "properties":{ + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } +} +```` + +### Azure_Arm_Models_Resources_TopLevelTrackedResources_listByResourceGroup + +- 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.Arm.Models.Resources/topLevelTrackedResources +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.Arm.Models.Resources/topLevelTrackedResources/top", + "name": "top", + "type": "topLevel", + "location": "eastus", + "properties":{ + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + }] +} +``` + +### Azure_Arm_Models_Resources_TopLevelTrackedResources_listBySubscription + +- Endpoint: `get https://management.azure.com` + +Resource LIST by subscription operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources +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.Arm.Models.Resources/topLevelTrackedResources/top", + "name": "top", + "type": "topLevel", + "location": "eastus", + "properties":{ + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + }] +} +``` + +### Azure_Arm_Models_Resources_TopLevelTrackedResources_update + +- Endpoint: `patch https://management.azure.com` + +Resource PATCH operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top +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.Arm.Models.Resources/topLevelTrackedResources/top", + "name": "top", + "type": "topLevel", + "location": "eastus", + "properties":{ + "description": "valid2", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } +} +``` + ### Azure_ClientGenerator_Core_Access_InternalOperation - Endpoints: diff --git a/packages/cadl-ranch-specs/http/azure/arm/models/resources/main.tsp b/packages/cadl-ranch-specs/http/azure/arm/models/resources/main.tsp new file mode 100644 index 000000000..01149d1a8 --- /dev/null +++ b/packages/cadl-ranch-specs/http/azure/arm/models/resources/main.tsp @@ -0,0 +1,39 @@ +import "@azure-tools/cadl-ranch-expect"; +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 "./toplevel.tsp"; +import "./nested.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.Arm.Models.Resources; + +@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", +} + +union ProvisioningState { + ResourceProvisioningState, + Provisioning: "Provisioning", + Updating: "Updating", + Deleting: "Deleting", + Accepted: "Accepted", +} diff --git a/packages/cadl-ranch-specs/http/azure/arm/models/resources/mockapi.ts b/packages/cadl-ranch-specs/http/azure/arm/models/resources/mockapi.ts new file mode 100644 index 000000000..448229b7c --- /dev/null +++ b/packages/cadl-ranch-specs/http/azure/arm/models/resources/mockapi.ts @@ -0,0 +1,308 @@ +import { passOnSuccess, mockapi, json, ValidationError } from "@azure-tools/cadl-ranch-api"; +import { ScenarioMockApi } from "@azure-tools/cadl-ranch-api"; + +export const Scenarios: Record = {}; + +const SUBSCRIPTION_ID_EXPECTED = "00000000-0000-0000-0000-000000000000"; +const RESOURCE_GROUP_EXPECTED = "test-rg"; +const validTopLevelResource = { + id: `/subscriptions/${SUBSCRIPTION_ID_EXPECTED}/resourceGroups/${RESOURCE_GROUP_EXPECTED}/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top`, + name: "top", + type: "topLevel", + location: "eastus", + properties: { + provisioningState: "Succeeded", + description: "valid", + }, + systemData: { + createdBy: "AzureSDK", + createdByType: "User", + createdAt: new Date(), + lastModifiedBy: "AzureSDK", + lastModifiedAt: new Date(), + lastModifiedByType: "User", + }, +}; + +const validNestedResource = { + id: `/subscriptions/${SUBSCRIPTION_ID_EXPECTED}/resourceGroups/${RESOURCE_GROUP_EXPECTED}/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested`, + name: "nested", + type: "nested", + properties: { + provisioningState: "Succeeded", + description: "valid", + }, + systemData: { + createdBy: "AzureSDK", + createdByType: "User", + createdAt: new Date(), + lastModifiedBy: "AzureSDK", + lastModifiedAt: new Date(), + lastModifiedByType: "User", + }, +}; + +// top level tracked resource +Scenarios.Azure_Arm_Models_Resources_TopLevelTrackedResources_get = passOnSuccess([ + mockapi.get( + "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/:topLevelResourceName", + (req) => { + req.expect.containsQueryParam("api-version", "2023-12-01-preview"); + if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { + throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); + } + if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { + throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); + } + if (req.params.topLevelResourceName.toLowerCase() !== "top") { + throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); + } + return { + status: 200, + body: json(validTopLevelResource), + }; + }, + ), +]); + +Scenarios.Azure_Arm_Models_Resources_TopLevelTrackedResources_createOrReplace = passOnSuccess([ + mockapi.put( + "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/:topLevelResourceName", + (req) => { + req.expect.containsQueryParam("api-version", "2023-12-01-preview"); + if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { + throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); + } + if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { + throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); + } + if (req.params.topLevelResourceName.toLowerCase() !== "top") { + throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); + } + req.expect.bodyEquals({ + location: "eastus", + properties: { + description: "valid", + }, + }); + return { + status: 200, + body: json(validTopLevelResource), + }; + }, + ), +]); + +Scenarios.Azure_Arm_Models_Resources_TopLevelTrackedResources_update = passOnSuccess([ + mockapi.patch( + "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/:topLevelResourceName", + (req) => { + req.expect.containsQueryParam("api-version", "2023-12-01-preview"); + if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { + throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); + } + if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { + throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); + } + if (req.params.topLevelResourceName.toLowerCase() !== "top") { + throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); + } + req.expect.bodyEquals({ + properties: { + description: "valid2", + }, + }); + const resource = { + ...validTopLevelResource, + }; + resource.properties.description = "valid2"; + return { + status: 200, + body: json(resource), + }; + }, + ), +]); + +Scenarios.Azure_Arm_Models_Resources_TopLevelTrackedResources_delete = passOnSuccess([ + mockapi.delete( + "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/:topLevelResourceName", + (req) => { + req.expect.containsQueryParam("api-version", "2023-12-01-preview"); + if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { + throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); + } + if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { + throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); + } + if (req.params.topLevelResourceName.toLowerCase() !== "top") { + throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); + } + return { + status: 204, + }; + }, + ), +]); + +Scenarios.Azure_Arm_Models_Resources_TopLevelTrackedResources_listByResourceGroup = passOnSuccess([ + mockapi.get( + "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.Arm.Models.Resources/topLevelTrackedResources", + (req) => { + req.expect.containsQueryParam("api-version", "2023-12-01-preview"); + if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { + throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); + } + if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { + throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); + } + return { + status: 200, + body: json({ + value: [validTopLevelResource], + }), + }; + }, + ), +]); + +Scenarios.Azure_Arm_Models_Resources_TopLevelTrackedResources_listBySubscription = passOnSuccess([ + mockapi.get("/subscriptions/:subscriptionId/providers/Azure.Arm.Models.Resources/topLevelTrackedResources", (req) => { + req.expect.containsQueryParam("api-version", "2023-12-01-preview"); + if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { + throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); + } + return { + status: 200, + body: json({ + value: [validTopLevelResource], + }), + }; + }), +]); + +// nested proxy resource +Scenarios.Azure_Arm_Models_Resources_NestedProxyResources_get = passOnSuccess([ + mockapi.get( + "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/:topLevelResourceName/nestedProxyResources/:nestedResourceName", + (req) => { + req.expect.containsQueryParam("api-version", "2023-12-01-preview"); + if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { + throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); + } + if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { + throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); + } + if (req.params.topLevelResourceName.toLowerCase() !== "top") { + throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); + } + if (req.params.nestedResourceName.toLowerCase() !== "nested") { + throw new ValidationError("Unexpected nested resource name", "nested", req.params.nestedResourceName); + } + return { + status: 200, + body: json(validNestedResource), + }; + }, + ), +]); + +Scenarios.Azure_Arm_Models_Resources_NestedProxyResources_createOrReplace = passOnSuccess([ + mockapi.put( + "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/:topLevelResourceName/nestedProxyResources/:nestedResourceName", + (req) => { + req.expect.containsQueryParam("api-version", "2023-12-01-preview"); + if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { + throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); + } + if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { + throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); + } + if (req.params.topLevelResourceName.toLowerCase() !== "top") { + throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); + } + if (req.params.nestedResourceName.toLowerCase() !== "nested") { + throw new ValidationError("Unexpected nested resource name", "nested", req.params.nestedResourceName); + } + req.expect.bodyEquals({ + properties: { + description: "valid", + }, + }); + return { + status: 200, + body: json(validNestedResource), + }; + }, + ), +]); + +Scenarios.Azure_Arm_Models_Resources_NestedProxyResources_update = passOnSuccess([ + mockapi.patch( + "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/:topLevelResourceName/nestedProxyResources/:nestedResourceName", + (req) => { + req.expect.containsQueryParam("api-version", "2023-12-01-preview"); + if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { + throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); + } + if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { + throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); + } + if (req.params.topLevelResourceName.toLowerCase() !== "top") { + throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); + } + if (req.params.nestedResourceName.toLowerCase() !== "nested") { + throw new ValidationError("Unexpected nested resource name", "nested", req.params.nestedResourceName); + } + req.expect.bodyEquals({ + properties: { + description: "valid2", + }, + }); + const resource = { + ...validNestedResource, + }; + resource.properties.description = "valid2"; + return { + status: 200, + body: json(resource), + }; + }, + ), +]); + +Scenarios.Azure_Arm_Models_Resources_NestedProxyResources_delete = passOnSuccess([ + mockapi.delete( + "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/:topLevelResourceName/nestedProxyResources/:nestedResourceName", + (req) => { + req.expect.containsQueryParam("api-version", "2023-12-01-preview"); + return { + status: 204, + }; + }, + ), +]); + +Scenarios.Azure_Arm_Models_Resources_NestedProxyResources_listByTopLevelTrackedResource = passOnSuccess([ + mockapi.get( + "/subscriptions/:subscriptionId/resourceGroups/:resourceGroup/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/:topLevelResourceName/nestedProxyResources", + (req) => { + req.expect.containsQueryParam("api-version", "2023-12-01-preview"); + if (req.params.subscriptionId !== SUBSCRIPTION_ID_EXPECTED) { + throw new ValidationError("Unexpected subscriptionId", SUBSCRIPTION_ID_EXPECTED, req.params.subscriptionId); + } + if (req.params.resourceGroup.toLowerCase() !== RESOURCE_GROUP_EXPECTED) { + throw new ValidationError("Unexpected resourceGroup", RESOURCE_GROUP_EXPECTED, req.params.resourceGroup); + } + if (req.params.topLevelResourceName.toLowerCase() !== "top") { + throw new ValidationError("Unexpected top level resource name", "top", req.params.topLevelResourceName); + } + return { + status: 200, + body: json({ + value: [validNestedResource], + }), + }; + }, + ), +]); diff --git a/packages/cadl-ranch-specs/http/azure/arm/models/resources/nested.tsp b/packages/cadl-ranch-specs/http/azure/arm/models/resources/nested.tsp new file mode 100644 index 000000000..528bc8eae --- /dev/null +++ b/packages/cadl-ranch-specs/http/azure/arm/models/resources/nested.tsp @@ -0,0 +1,178 @@ +import "@typespec/http"; +import "@typespec/rest"; +import "@azure-tools/typespec-azure-core"; +import "@azure-tools/typespec-azure-resource-manager"; + +using TypeSpec.Http; +using TypeSpec.Rest; +using Azure.Core; +using Azure.ResourceManager; +using TypeSpec.OpenAPI; + +namespace Azure.Arm.Models.Resources; + +@doc("Nested child of Top Level Tracked Resource.") +@parentResource(TopLevelTrackedResource) +model NestedProxyResource is ProxyResource { + @key("nextedProxyResourceName") + @doc("Name of the nested resource.") + @visibility("read") + @path + @segment("nestedProxyResources") + @pattern("^[A-Za-z0-9]([A-Za-z0-9-_.]{0,62}[A-Za-z0-9])?$") + name: string; +} + +@doc("Nested Proxy Resource Properties.") +model NestedProxyResourceProperties { + @visibility("read") + @doc("Provisioning State of the nested child Resource") + provisioningState?: ProvisioningState; + + @doc("Nested resource description.") + description?: string; +} + +@armResourceOperations +interface NestedProxyResources { + @scenario + @scenarioDoc(""" + Resource GET operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested + 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.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested", + "name": "nested", + "type": "nested", + "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.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested + Expected query parameter: api-version=2023-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.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested", + "name": "nested", + "type": "nested", + "properties":{ + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + } + ``` + """) + createOrReplace is ArmResourceCreateOrReplaceAsync; + + @scenario + @scenarioDoc(""" + Resource PATCH operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested + 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.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested", + "name": "nested", + "type": "nested", + "properties":{ + "description": "valid2", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + } + ``` + """) + update is ArmResourcePatchAsync; + + @scenario + @scenarioDoc(""" + Resource DELETE operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested + Expected query parameter: api-version=2023-12-01-preview + Expected response status code: 204 + """) + delete is ArmResourceDeleteWithoutOkAsync; + + @scenario + @scenarioDoc(""" + Resource LIST by parent resource operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested + 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.Arm.Models.Resources/topLevelTrackedResources/top/nestedProxyResources/nested", + "name": "nested", + "type": "nested", + "properties":{ + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + }] + } + ``` + """) + listByParent is ArmResourceListByParent; +} diff --git a/packages/cadl-ranch-specs/http/azure/arm/models/resources/toplevel.tsp b/packages/cadl-ranch-specs/http/azure/arm/models/resources/toplevel.tsp new file mode 100644 index 000000000..043da7681 --- /dev/null +++ b/packages/cadl-ranch-specs/http/azure/arm/models/resources/toplevel.tsp @@ -0,0 +1,214 @@ +import "@typespec/http"; +import "@typespec/rest"; +import "@azure-tools/typespec-azure-core"; +import "@azure-tools/typespec-azure-resource-manager"; + +using TypeSpec.Http; +using TypeSpec.Rest; +using Azure.Core; +using Azure.ResourceManager; +using TypeSpec.OpenAPI; + +namespace Azure.Arm.Models.Resources; + +@resource("topLevelTrackedResources") +model TopLevelTrackedResource is TrackedResource { + @key("topLevelTrackedResourceName") + @path + @segment("topLevelTrackedResources") + @doc("arm resource name for path") + @pattern("^[A-Za-z0-9]([A-Za-z0-9-_.]{0,62}[A-Za-z0-9])?$") + name: string; +} + +@doc("Top Level Arm Resource Properties.") +model TopLevelTrackedResourceProperties { + @visibility("read") + @doc("The status of the last operation.") + provisioningState?: ProvisioningState; + + @doc("The description of the resource.") + description?: string; +} + +@armResourceOperations +interface TopLevelTrackedResources { + @scenario + @scenarioDoc(""" + Resource GET operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top + 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.Arm.Models.Resources/topLevelTrackedResources/top", + "name": "top", + "type": "topLevel", + "location": "eastus", + "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.Arm.Models.Resources/topLevelTrackedResources/top + Expected query parameter: api-version=2023-12-01-preview + Expected request body: + ```json + { + "location": "eastus", + "properties": { + "description": "valid" + } + } + ``` + Expected response body: + ```json + { + "id": "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top", + "name": "top", + "type": "topLevel", + "location": "eastus", + "properties": { + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + } + ``` + """) + createOrReplace is ArmResourceCreateOrReplaceAsync; + + @scenario + @scenarioDoc(""" + Resource PATCH operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top + 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.Arm.Models.Resources/topLevelTrackedResources/top", + "name": "top", + "type": "topLevel", + "location": "eastus", + "properties":{ + "description": "valid2", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + } + ``` + """) + update is ArmResourcePatchAsync; + + @scenario + @scenarioDoc(""" + Resource DELETE operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources/top + Expected query parameter: api-version=2023-12-01-preview + ``` + Expected response status code: 204 + """) + delete is ArmResourceDeleteWithoutOkAsync; + + @scenario + @scenarioDoc(""" + Resource LIST by resource group operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources + 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.Arm.Models.Resources/topLevelTrackedResources/top", + "name": "top", + "type": "topLevel", + "location": "eastus", + "properties":{ + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + }] + } + ``` + """) + listByResourceGroup is ArmResourceListByParent; + + @scenario + @scenarioDoc(""" + Resource LIST by subscription operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/test-rg/providers/Azure.Arm.Models.Resources/topLevelTrackedResources + 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.Arm.Models.Resources/topLevelTrackedResources/top", + "name": "top", + "type": "topLevel", + "location": "eastus", + "properties":{ + "description": "valid", + "provisioningState": "Succeeded" + }, + "systemData": { + "createdBy": "AzureSDK", + "createdByType": "User", + "createdAt": , + "lastModifiedBy": "AzureSDK", + "lastModifiedAt": , + "lastModifiedByType": "User", + } + }] + } + ``` + """) + listBySubscription is ArmListBySubscription; +}