From bc64b16e1eab63429c8d17fc677efb5f2a6beecb Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Bustillo Date: Fri, 11 Oct 2024 12:09:05 -0700 Subject: [PATCH 1/6] [Bug] ArmProviderAsync does not return 202 --- .../operations/operation-provider/main.tsp | 17 +++--- .../2022-11-01-preview/openapi.json | 52 +++++++++++++++++++ .../lib/operations.tsp | 2 +- 3 files changed, 61 insertions(+), 10 deletions(-) diff --git a/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp b/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp index 1e8c49a9c7..b4a21cf99d 100644 --- a/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp +++ b/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp @@ -48,19 +48,18 @@ model LogAnalyticsCollection is Page; interface ProviderOperations { /** Operation to get virtual machines for subscription (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/getVmSizes) */ @get - getVmSizes is ArmProviderActionAsync< - Response = VmSizeCollection, + getVmSizes is ArmProviderActionSync; + /** Operation to post virtual machines for subscription (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/postVmSizes) */ + postVmSizes is ArmProviderActionAsync< + Response = LogAnalyticsCollection, Scope = SubscriptionActionScope >; /** Operation to get virtual machines for tenant (/providers/Microsoft.ContosoProviderHub/getVmSizesTenant) */ @get - getVmSizesTenant is ArmProviderActionAsync< - Response = VmSizeCollection, - Scope = TenantActionScope - >; + getVmSizesTenant is ArmProviderActionSync; /** Operation to get virtual machines for subscription for specific location (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/locations/{location}/getVmSizesLocation) */ @get - getVmSizesLocation is ArmProviderActionAsync< + getVmSizesLocation is ArmProviderActionSync< Response = VmSizeCollection, Scope = SubscriptionActionScope, Parameters = LocationParameter @@ -68,14 +67,14 @@ interface ProviderOperations { /** Operation to get throttled requests sharing action (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/logAnalytics/apiAccess/getThrottledRequests) */ @get @action("logAnalytics/apiAccess/getThrottledRequests") - getThrottledRequestsSubscription is ArmProviderActionAsync< + getThrottledRequestsSubscription is ArmProviderActionSync< Response = LogAnalyticsCollection, Scope = SubscriptionActionScope >; /** Operation to get throttled requests sharing action for tenant (/providers/Microsoft.ContosoProviderHub/logAnalytics/apiAccess/getThrottledRequests) */ @get @action("logAnalytics/apiAccess/getThrottledRequests") - getThrottledRequestsTenant is ArmProviderActionAsync< + getThrottledRequestsTenant is ArmProviderActionSync< Response = LogAnalyticsCollection, Scope = TenantActionScope >; diff --git a/packages/samples/test/output/azure/resource-manager/operations/operation-provider/@azure-tools/typespec-autorest/2022-11-01-preview/openapi.json b/packages/samples/test/output/azure/resource-manager/operations/operation-provider/@azure-tools/typespec-autorest/2022-11-01-preview/openapi.json index 53a68f6347..494845f4e0 100644 --- a/packages/samples/test/output/azure/resource-manager/operations/operation-provider/@azure-tools/typespec-autorest/2022-11-01-preview/openapi.json +++ b/packages/samples/test/output/azure/resource-manager/operations/operation-provider/@azure-tools/typespec-autorest/2022-11-01-preview/openapi.json @@ -243,6 +243,58 @@ "nextLinkName": "nextLink" } } + }, + "/subscriptions/{subscriptionId}/providers/Microsoft.OperationStatusSample/postVmSizes": { + "post": { + "operationId": "ProviderOperations_PostVmSizes", + "tags": [ + "ProviderOperations" + ], + "description": "Operation to post virtual machines for subscription (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/postVmSizes)", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + } + ], + "responses": { + "200": { + "description": "The request has succeeded.", + "schema": { + "$ref": "#/definitions/LogAnalyticsCollection" + } + }, + "202": { + "description": "Resource operation accepted.", + "headers": { + "Location": { + "type": "string", + "description": "The Location header contains the URL where the status of the long running operation can be checked." + }, + "Retry-After": { + "type": "integer", + "format": "int32", + "description": "The Retry-After header can indicate how long the client should wait before polling the operation status." + } + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-long-running-operation-options": { + "final-state-via": "location" + }, + "x-ms-long-running-operation": true, + "x-ms-pageable": { + "nextLinkName": "nextLink" + } + } } }, "definitions": { diff --git a/packages/typespec-azure-resource-manager/lib/operations.tsp b/packages/typespec-azure-resource-manager/lib/operations.tsp index 9deaa0bb0b..53ddba5a11 100644 --- a/packages/typespec-azure-resource-manager/lib/operations.tsp +++ b/packages/typespec-azure-resource-manager/lib/operations.tsp @@ -752,4 +752,4 @@ op ArmProviderActionAsync< /** The request body */ @bodyRoot body: Request, -): Response | ErrorResponse; +): ArmAcceptedLroResponse<"Resource operation accepted.", LroHeaders> | Response | ErrorResponse; From 01362b9d620632aa6ca047733235cc6432bebf9f Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Bustillo Date: Fri, 11 Oct 2024 12:13:05 -0700 Subject: [PATCH 2/6] Summary of changes --- ...ArmProviderAsync-doesnt-return-202-2024-9-11-12-10-7.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/hotfix-ArmProviderAsync-doesnt-return-202-2024-9-11-12-10-7.md diff --git a/.chronus/changes/hotfix-ArmProviderAsync-doesnt-return-202-2024-9-11-12-10-7.md b/.chronus/changes/hotfix-ArmProviderAsync-doesnt-return-202-2024-9-11-12-10-7.md new file mode 100644 index 0000000000..8414b8c0d7 --- /dev/null +++ b/.chronus/changes/hotfix-ArmProviderAsync-doesnt-return-202-2024-9-11-12-10-7.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-azure-resource-manager" +--- + +Fix `ArmProviderActionAsync` to correctly return 202 responses. From 98ede662063412aa6ed64630a107dff74164d94d Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Bustillo Date: Fri, 11 Oct 2024 13:01:50 -0700 Subject: [PATCH 3/6] Missing documentation --- docs/libraries/azure-resource-manager/reference/interfaces.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/libraries/azure-resource-manager/reference/interfaces.md b/docs/libraries/azure-resource-manager/reference/interfaces.md index b0217d5796..f5e706d63a 100644 --- a/docs/libraries/azure-resource-manager/reference/interfaces.md +++ b/docs/libraries/azure-resource-manager/reference/interfaces.md @@ -674,7 +674,7 @@ op Azure.ResourceManager.ArmListBySubscription(apiVersion: string, subscriptionI ### `ArmProviderActionAsync` {#Azure.ResourceManager.ArmProviderActionAsync} ```typespec -op Azure.ResourceManager.ArmProviderActionAsync(apiVersion: string, subscriptionId: Azure.Core.uuid, location: string, resourceGroupName: string, resourceUri: string, provider: "Microsoft.ThisWillBeReplaced", body: Request): Response | Azure.ResourceManager.CommonTypes.ErrorResponse +op Azure.ResourceManager.ArmProviderActionAsync(apiVersion: string, subscriptionId: Azure.Core.uuid, location: string, resourceGroupName: string, resourceUri: string, provider: "Microsoft.ThisWillBeReplaced", body: Request): Azure.ResourceManager.ArmAcceptedLroResponse | Response | Azure.ResourceManager.CommonTypes.ErrorResponse ``` #### Template Parameters From b0a98ea6eabe4971038066a673b02b7929e8b8db Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Bustillo Date: Fri, 11 Oct 2024 14:48:38 -0700 Subject: [PATCH 4/6] Feedback: Adding more examples --- .../operations/operation-provider/main.tsp | 32 +++- .../2022-11-01-preview/openapi.json | 173 ++++++++++++++++++ 2 files changed, 200 insertions(+), 5 deletions(-) diff --git a/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp b/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp index b4a21cf99d..33b7864115 100644 --- a/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp +++ b/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp @@ -44,16 +44,17 @@ model VmSizeCollection is Page; /** LogAnalytics collection of operation status response */ model LogAnalyticsCollection is Page; +/** Retry after header response */ +model RetryAfterHeader is Azure.Core.Foundations.RetryAfterHeader; + +/** ArmCombined header response */ +model ArmCombinedHeader is ArmCombinedLroHeaders; + @armResourceOperations interface ProviderOperations { /** Operation to get virtual machines for subscription (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/getVmSizes) */ @get getVmSizes is ArmProviderActionSync; - /** Operation to post virtual machines for subscription (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/postVmSizes) */ - postVmSizes is ArmProviderActionAsync< - Response = LogAnalyticsCollection, - Scope = SubscriptionActionScope - >; /** Operation to get virtual machines for tenant (/providers/Microsoft.ContosoProviderHub/getVmSizesTenant) */ @get getVmSizesTenant is ArmProviderActionSync; @@ -78,4 +79,25 @@ interface ProviderOperations { Response = LogAnalyticsCollection, Scope = TenantActionScope >; + /** Operation to post virtual machines for subscription (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/postVmSizes) */ + postVmSizes is ArmProviderActionAsync< + Response = LogAnalyticsCollection, + Scope = SubscriptionActionScope + >; + /** Operation to post virtual machines for subscription for specific location (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/locations/{location}/postVmSizesLocation) */ + postVmSizesLocation is ArmProviderActionAsync< + Response = LogAnalyticsCollection, + Scope = SubscriptionActionScope, + Parameters = LocationParameter + >; + /** Operation to post virtual machines for subscription with retry after header (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/postVmSizesRetry) */ + postVmSizesRetry is ArmProviderActionAsync< + Response = RetryAfterHeader, + Scope = SubscriptionActionScope + >; + /** Operation to post virtual machines for subscription with ARM combined header (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/postVmSizesArmCombined) */ + postVmSizesArmCombined is ArmProviderActionAsync< + Response = ArmCombinedHeader, + Scope = SubscriptionActionScope + >; } diff --git a/packages/samples/test/output/azure/resource-manager/operations/operation-provider/@azure-tools/typespec-autorest/2022-11-01-preview/openapi.json b/packages/samples/test/output/azure/resource-manager/operations/operation-provider/@azure-tools/typespec-autorest/2022-11-01-preview/openapi.json index 494845f4e0..7ccce548f4 100644 --- a/packages/samples/test/output/azure/resource-manager/operations/operation-provider/@azure-tools/typespec-autorest/2022-11-01-preview/openapi.json +++ b/packages/samples/test/output/azure/resource-manager/operations/operation-provider/@azure-tools/typespec-autorest/2022-11-01-preview/openapi.json @@ -210,6 +210,61 @@ } } }, + "/subscriptions/{subscriptionId}/providers/Microsoft.OperationStatusSample/locations/{location}/postVmSizesLocation": { + "post": { + "operationId": "ProviderOperations_PostVmSizesLocation", + "tags": [ + "ProviderOperations" + ], + "description": "Operation to post virtual machines for subscription for specific location (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/locations/{location}/postVmSizesLocation)", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/LocationParameter" + } + ], + "responses": { + "200": { + "description": "The request has succeeded.", + "schema": { + "$ref": "#/definitions/LogAnalyticsCollection" + } + }, + "202": { + "description": "Resource operation accepted.", + "headers": { + "Location": { + "type": "string", + "description": "The Location header contains the URL where the status of the long running operation can be checked." + }, + "Retry-After": { + "type": "integer", + "format": "int32", + "description": "The Retry-After header can indicate how long the client should wait before polling the operation status." + } + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-long-running-operation-options": { + "final-state-via": "location" + }, + "x-ms-long-running-operation": true, + "x-ms-pageable": { + "nextLinkName": "nextLink" + } + } + }, "/subscriptions/{subscriptionId}/providers/Microsoft.OperationStatusSample/logAnalytics/apiAccess/getThrottledRequests": { "get": { "operationId": "ProviderOperations_GetThrottledRequestsSubscription", @@ -295,9 +350,123 @@ "nextLinkName": "nextLink" } } + }, + "/subscriptions/{subscriptionId}/providers/Microsoft.OperationStatusSample/postVmSizesArmCombined": { + "post": { + "operationId": "ProviderOperations_PostVmSizesArmCombined", + "tags": [ + "ProviderOperations" + ], + "description": "Operation to post virtual machines for subscription with ARM combined header (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/postVmSizesArmCombined)", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + } + ], + "responses": { + "200": { + "description": "The request has succeeded.", + "headers": { + "Azure-AsyncOperation": { + "type": "string", + "format": "uri", + "description": "A link to the status monitor" + }, + "Location": { + "type": "string", + "description": "The Location header contains the URL where the status of the long running operation can be checked." + } + } + }, + "202": { + "description": "Resource operation accepted.", + "headers": { + "Location": { + "type": "string", + "description": "The Location header contains the URL where the status of the long running operation can be checked." + }, + "Retry-After": { + "type": "integer", + "format": "int32", + "description": "The Retry-After header can indicate how long the client should wait before polling the operation status." + } + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-long-running-operation-options": { + "final-state-via": "location" + }, + "x-ms-long-running-operation": true + } + }, + "/subscriptions/{subscriptionId}/providers/Microsoft.OperationStatusSample/postVmSizesRetry": { + "post": { + "operationId": "ProviderOperations_PostVmSizesRetry", + "tags": [ + "ProviderOperations" + ], + "description": "Operation to post virtual machines for subscription with retry after header (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/postVmSizesRetry)", + "parameters": [ + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/ApiVersionParameter" + }, + { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/parameters/SubscriptionIdParameter" + } + ], + "responses": { + "200": { + "description": "The request has succeeded.", + "headers": { + "Retry-After": { + "type": "integer", + "format": "int32", + "description": "The Retry-After header can indicate how long the client should wait before polling the operation status." + } + } + }, + "202": { + "description": "Resource operation accepted.", + "headers": { + "Location": { + "type": "string", + "description": "The Location header contains the URL where the status of the long running operation can be checked." + }, + "Retry-After": { + "type": "integer", + "format": "int32", + "description": "The Retry-After header can indicate how long the client should wait before polling the operation status." + } + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "../../../../../../../../../specs/resource-manager/common-types/v5/types.json#/definitions/ErrorResponse" + } + } + }, + "x-ms-long-running-operation-options": { + "final-state-via": "location" + }, + "x-ms-long-running-operation": true + } } }, "definitions": { + "ArmCombinedHeader": { + "type": "object", + "description": "ArmCombined header response" + }, "LogAnalyticsCollection": { "type": "object", "description": "LogAnalytics collection of operation status response", @@ -333,6 +502,10 @@ "output" ] }, + "RetryAfterHeader": { + "type": "object", + "description": "Retry after header response" + }, "VmSize": { "type": "object", "description": "Represents a virtual machine size", From 10926a45d059da7f188880ab6bc0bc92582e76e2 Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Bustillo Date: Mon, 14 Oct 2024 10:00:29 -0700 Subject: [PATCH 5/6] Adreess feedback, no rename --- .../operations/operation-provider/main.tsp | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp b/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp index 33b7864115..acb6484e3c 100644 --- a/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp +++ b/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp @@ -44,12 +44,6 @@ model VmSizeCollection is Page; /** LogAnalytics collection of operation status response */ model LogAnalyticsCollection is Page; -/** Retry after header response */ -model RetryAfterHeader is Azure.Core.Foundations.RetryAfterHeader; - -/** ArmCombined header response */ -model ArmCombinedHeader is ArmCombinedLroHeaders; - @armResourceOperations interface ProviderOperations { /** Operation to get virtual machines for subscription (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/getVmSizes) */ @@ -92,12 +86,12 @@ interface ProviderOperations { >; /** Operation to post virtual machines for subscription with retry after header (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/postVmSizesRetry) */ postVmSizesRetry is ArmProviderActionAsync< - Response = RetryAfterHeader, + Response = Azure.Core.Foundations.RetryAfterHeader, Scope = SubscriptionActionScope >; /** Operation to post virtual machines for subscription with ARM combined header (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/postVmSizesArmCombined) */ postVmSizesArmCombined is ArmProviderActionAsync< - Response = ArmCombinedHeader, + Response = ArmCombinedLroHeaders, Scope = SubscriptionActionScope >; } From 6d218cab0173b9d1dc656b90d11d4e9bb3a64c41 Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Bustillo Date: Mon, 14 Oct 2024 10:03:10 -0700 Subject: [PATCH 6/6] Adreess feedback, no rename --- .../2022-11-01-preview/openapi.json | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/samples/test/output/azure/resource-manager/operations/operation-provider/@azure-tools/typespec-autorest/2022-11-01-preview/openapi.json b/packages/samples/test/output/azure/resource-manager/operations/operation-provider/@azure-tools/typespec-autorest/2022-11-01-preview/openapi.json index 7ccce548f4..94f6986fc6 100644 --- a/packages/samples/test/output/azure/resource-manager/operations/operation-provider/@azure-tools/typespec-autorest/2022-11-01-preview/openapi.json +++ b/packages/samples/test/output/azure/resource-manager/operations/operation-provider/@azure-tools/typespec-autorest/2022-11-01-preview/openapi.json @@ -463,9 +463,13 @@ } }, "definitions": { - "ArmCombinedHeader": { + "Azure.Core.Foundations.RetryAfterHeader": { "type": "object", - "description": "ArmCombined header response" + "description": "The retry-after envelope." + }, + "Azure.ResourceManager.ArmCombinedLroHeaders, void, TypeSpec.Rest.ResourceLocation, string>": { + "type": "object", + "description": "Provide Both Azure-AsyncOperation and Location headers" }, "LogAnalyticsCollection": { "type": "object", @@ -502,10 +506,6 @@ "output" ] }, - "RetryAfterHeader": { - "type": "object", - "description": "Retry after header response" - }, "VmSize": { "type": "object", "description": "Represents a virtual machine size",