diff --git a/.chronus/changes/specs_arm_CheckNameAvailability_operations-2024-10-29-17-11-41.md b/.chronus/changes/specs_arm_CheckNameAvailability_operations-2024-10-29-17-11-41.md new file mode 100644 index 0000000000..7c96ca18ab --- /dev/null +++ b/.chronus/changes/specs_arm_CheckNameAvailability_operations-2024-10-29-17-11-41.md @@ -0,0 +1,7 @@ +--- +changeKind: feature +packages: + - "@azure-tools/azure-http-specs" +--- + +Added CheckNameAvailability operations case for ARM tests. \ No newline at end of file diff --git a/packages/azure-http-specs/spec-summary.md b/packages/azure-http-specs/spec-summary.md index 4e3523f47c..0a1b2441be 100644 --- a/packages/azure-http-specs/spec-summary.md +++ b/packages/azure-http-specs/spec-summary.md @@ -916,6 +916,58 @@ Expected response body: } ``` +### Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkGlobal + +- Endpoint: `post https://management.azure.com` + + Resource POST operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/providers/Azure.ResourceManager.OperationTemplates/checkNameAvailability + Expected query parameter: api-version=2023-12-01-preview + Expected request body: + + ```json + { + "name": "checkName", + "type": "Microsoft.Web/site" + } + ``` + + Expected response body: + + ```json + { + "nameAvailable": false, + "reason": "AlreadyExists", + "message": "Hostname 'checkName' already exists. Please select a different name." + } + ``` + +### Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkLocal + +- Endpoint: `post https://management.azure.com` + +Resource POST operation. +Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/providers/Azure.ResourceManager.OperationTemplates/locations/westus/checkNameAvailability +Expected query parameter: api-version=2023-12-01-preview +Expected request body: + +```json +{ + "name": "checkName", + "type": "Microsoft.Web/site" +} +``` + +Expected response body: + +```json +{ + "nameAvailable": false, + "reason": "AlreadyExists", + "message": "Hostname 'checkName' already exists. Please select a different name." +} +``` + ### Azure_ResourceManager_OperationTemplates_Lro_createOrReplace - Endpoint: `put https://management.azure.com` diff --git a/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/checkname-availability.tsp b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/checkname-availability.tsp new file mode 100644 index 0000000000..6069bf171b --- /dev/null +++ b/packages/azure-http-specs/specs/azure/resource-manager/operation-templates/checkname-availability.tsp @@ -0,0 +1,62 @@ +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; + +interface CheckNameAvailability { + @scenario + @scenarioDoc(""" + Resource POST operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/providers/Azure.ResourceManager.OperationTemplates/checkNameAvailability + Expected query parameter: api-version=2023-12-01-preview + Expected request body: + ```json + { + "name": "checkName", + "type": "Microsoft.Web/site" + } + ``` + Expected response body: + ```json + { + "nameAvailable": false, + "reason": "AlreadyExists", + "message": "Hostname 'checkName' already exists. Please select a different name." + } + ``` + """) + checkGlobal is checkGlobalNameAvailability; + + @scenario + @scenarioDoc(""" + Resource POST operation. + Expected path: /subscriptions/00000000-0000-0000-0000-000000000000/providers/Azure.ResourceManager.OperationTemplates/locations/westus/checkNameAvailability + Expected query parameter: api-version=2023-12-01-preview + Expected request body: + ```json + { + "name": "checkName", + "type": "Microsoft.Web/site", + } + ``` + Expected response body: + ```json + { + "nameAvailable": false, + "reason": "AlreadyExists", + "message": "Hostname 'checkName' already exists. Please select a different name." + } + ``` + """) + checkLocal is checkLocalNameAvailability; +} 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 index c5073e69d1..c786aaf4a6 100644 --- 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 @@ -4,6 +4,7 @@ import "@typespec/versioning"; import "@azure-tools/typespec-azure-core"; import "@azure-tools/typespec-azure-resource-manager"; import "@azure-tools/typespec-client-generator-core"; +import "./checkname-availability.tsp"; import "./lro.tsp"; using TypeSpec.Http; 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 a442f08578..26fcb4293f 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,10 +29,61 @@ const validOrder = { lastModifiedByType: "User", }, }; +const checkNameAvailabilityResponse = { + nameAvailable: false, + reason: "AlreadyExists", + message: "Hostname 'checkName' already exists. Please select a different name.", +}; let createOrReplacePollCount = 0; let postPollCount = 0; let deletePollCount = 0; +// Check Global Name Availability +Scenarios.Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkGlobal = + passOnSuccess({ + uri: "/subscriptions/:subscriptionId/providers/Azure.ResourceManager.OperationTemplates/checkNameAvailability", + method: "post", + request: { + params: { + subscriptionId: SUBSCRIPTION_ID_EXPECTED, + "api-version": "2023-12-01-preview", + }, + body: { + name: "checkName", + type: "Microsoft.Web/site", + }, + }, + response: { + status: 200, + body: json(checkNameAvailabilityResponse), + }, + kind: "MockApiDefinition", + }); + +// Check Local Name Availability +Scenarios.Azure_ResourceManager_OperationTemplates_CheckNameAvailability_checkLocal = passOnSuccess( + { + uri: "/subscriptions/:subscriptionId/providers/Azure.ResourceManager.OperationTemplates/locations/:location/checkNameAvailability", + method: "post", + request: { + params: { + subscriptionId: SUBSCRIPTION_ID_EXPECTED, + location: "westus", + "api-version": "2023-12-01-preview", + }, + body: { + name: "checkName", + type: "Microsoft.Web/site", + }, + }, + response: { + status: 200, + body: json(checkNameAvailabilityResponse), + }, + kind: "MockApiDefinition", + }, +); + // lro resource Scenarios.Azure_ResourceManager_OperationTemplates_Lro_createOrReplace = passOnSuccess([ {