From a4d1737079c5bdee43746e965b3ac6c42086dad6 Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Bustillo Date: Tue, 15 Oct 2024 15:14:39 -0700 Subject: [PATCH 01/12] Fix linting rule to get it trigger when @get is used --- .../rules/arm-resource-invalid-action-verb.ts | 7 ++-- .../test/rules/operation-usage.test.ts | 33 ------------------- 2 files changed, 2 insertions(+), 38 deletions(-) diff --git a/packages/typespec-azure-resource-manager/src/rules/arm-resource-invalid-action-verb.ts b/packages/typespec-azure-resource-manager/src/rules/arm-resource-invalid-action-verb.ts index 206d04fafb..4ab970ea09 100644 --- a/packages/typespec-azure-resource-manager/src/rules/arm-resource-invalid-action-verb.ts +++ b/packages/typespec-azure-resource-manager/src/rules/arm-resource-invalid-action-verb.ts @@ -2,7 +2,7 @@ import { Operation, createRule } from "@typespec/compiler"; import { getOperationVerb } from "@typespec/http"; import { getActionDetails } from "@typespec/rest"; -import { isInternalTypeSpec, isSourceOperationResourceManagerInternal } from "./utils.js"; +import { isInternalTypeSpec } from "./utils.js"; export const invalidActionVerbRule = createRule({ name: "arm-resource-invalid-action-verb", @@ -14,10 +14,7 @@ export const invalidActionVerbRule = createRule({ create(context) { return { operation: (operation: Operation) => { - if ( - !isInternalTypeSpec(context.program, operation) && - !isSourceOperationResourceManagerInternal(operation) - ) { + if (!isInternalTypeSpec(context.program, operation)) { const actionType = getActionDetails(context.program, operation); const verb = getOperationVerb(context.program, operation); if (actionType !== undefined && verb !== "post") { diff --git a/packages/typespec-azure-resource-manager/test/rules/operation-usage.test.ts b/packages/typespec-azure-resource-manager/test/rules/operation-usage.test.ts index 5e6bc70ec9..ae13463466 100644 --- a/packages/typespec-azure-resource-manager/test/rules/operation-usage.test.ts +++ b/packages/typespec-azure-resource-manager/test/rules/operation-usage.test.ts @@ -87,39 +87,6 @@ describe("typespec-azure-resource-manager: detect non-post actions", () => { message: "Actions must be HTTP Post operations.", }); }); - - it("Allows post actions for authorized provider actions", async () => { - await tester - .expect( - ` - @armProviderNamespace - @service({title: "Microsoft.Foo"}) - @versioned(Versions) - namespace Microsoft.Foo; - enum Versions { - @useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1) - @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v5) - "2021-10-01-preview", - } - - interface Operations extends Azure.ResourceManager.Operations {} - - @doc("The VM Size") - model VmSize { - @doc("number of cpus ") - cpus: int32; - } - - @armResourceOperations - interface ProviderOperations { - @get - @armResourceList(VmSize) - getVmsSizes is ArmProviderActionSync; - } - `, - ) - .toBeValid(); - }); }); describe("typespec-azure-resource-manager: generates armResourceAction paths correctly", () => { From 2e9f1cd697de7f2fc3e85a67543f566e9ccc231d Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Bustillo Date: Tue, 15 Oct 2024 15:22:55 -0700 Subject: [PATCH 02/12] Summary of change --- .../fix-linting-rule-post-operation-2024-9-15-15-21-46.md | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .chronus/changes/fix-linting-rule-post-operation-2024-9-15-15-21-46.md diff --git a/.chronus/changes/fix-linting-rule-post-operation-2024-9-15-15-21-46.md b/.chronus/changes/fix-linting-rule-post-operation-2024-9-15-15-21-46.md new file mode 100644 index 0000000000..70c88b3df1 --- /dev/null +++ b/.chronus/changes/fix-linting-rule-post-operation-2024-9-15-15-21-46.md @@ -0,0 +1,7 @@ +--- +changeKind: fix +packages: + - "@azure-tools/typespec-azure-resource-manager" +--- + +Fix linting rule to ensure that the linting rule triggers for @get operations on ArmProviderAction From 13937f1a8c387d09df04d248e42692710515e0d7 Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Bustillo Date: Tue, 15 Oct 2024 17:19:28 -0700 Subject: [PATCH 03/12] Fix test to match rule --- .../operations/operation-provider/main.tsp | 10 +++++----- .../typespec-autorest/2022-11-01-preview/openapi.json | 10 +++++----- 2 files changed, 10 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..455c192458 100644 --- a/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp +++ b/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp @@ -47,33 +47,33 @@ model LogAnalyticsCollection is Page; @armResourceOperations interface ProviderOperations { /** Operation to get virtual machines for subscription (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/getVmSizes) */ - @get + @post getVmSizes is ArmProviderActionAsync< Response = VmSizeCollection, Scope = SubscriptionActionScope >; /** Operation to get virtual machines for tenant (/providers/Microsoft.ContosoProviderHub/getVmSizesTenant) */ - @get + @post getVmSizesTenant is ArmProviderActionAsync< Response = VmSizeCollection, Scope = TenantActionScope >; /** Operation to get virtual machines for subscription for specific location (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/locations/{location}/getVmSizesLocation) */ - @get + @post getVmSizesLocation is ArmProviderActionAsync< Response = VmSizeCollection, Scope = SubscriptionActionScope, Parameters = LocationParameter >; /** Operation to get throttled requests sharing action (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/logAnalytics/apiAccess/getThrottledRequests) */ - @get + @post @action("logAnalytics/apiAccess/getThrottledRequests") getThrottledRequestsSubscription is ArmProviderActionAsync< Response = LogAnalyticsCollection, Scope = SubscriptionActionScope >; /** Operation to get throttled requests sharing action for tenant (/providers/Microsoft.ContosoProviderHub/logAnalytics/apiAccess/getThrottledRequests) */ - @get + @post @action("logAnalytics/apiAccess/getThrottledRequests") getThrottledRequestsTenant is ArmProviderActionAsync< Response = LogAnalyticsCollection, 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..7125a37405 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 @@ -47,7 +47,7 @@ ], "paths": { "/providers/Microsoft.OperationStatusSample/getVmSizesTenant": { - "get": { + "post": { "operationId": "ProviderOperations_GetVmSizesTenant", "tags": [ "ProviderOperations" @@ -78,7 +78,7 @@ } }, "/providers/Microsoft.OperationStatusSample/logAnalytics/apiAccess/getThrottledRequests": { - "get": { + "post": { "operationId": "ProviderOperations_GetThrottledRequestsTenant", "tags": [ "ProviderOperations" @@ -140,7 +140,7 @@ } }, "/subscriptions/{subscriptionId}/providers/Microsoft.OperationStatusSample/getVmSizes": { - "get": { + "post": { "operationId": "ProviderOperations_GetVmSizes", "tags": [ "ProviderOperations" @@ -174,7 +174,7 @@ } }, "/subscriptions/{subscriptionId}/providers/Microsoft.OperationStatusSample/locations/{location}/getVmSizesLocation": { - "get": { + "post": { "operationId": "ProviderOperations_GetVmSizesLocation", "tags": [ "ProviderOperations" @@ -211,7 +211,7 @@ } }, "/subscriptions/{subscriptionId}/providers/Microsoft.OperationStatusSample/logAnalytics/apiAccess/getThrottledRequests": { - "get": { + "post": { "operationId": "ProviderOperations_GetThrottledRequestsSubscription", "tags": [ "ProviderOperations" From 5c66edeb076ee7f581f19e6996762176b0fc3e25 Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Bustillo Date: Wed, 16 Oct 2024 11:53:33 -0700 Subject: [PATCH 04/12] fir after merge main --- .../operations/operation-provider/main.tsp | 5 +++++ .../typespec-autorest/2022-11-01-preview/openapi.json | 10 +++++----- 2 files changed, 10 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 acb6484e3c..fb222f212e 100644 --- a/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp +++ b/packages/samples/specs/resource-manager/operations/operation-provider/main.tsp @@ -47,12 +47,15 @@ model LogAnalyticsCollection is Page; @armResourceOperations interface ProviderOperations { /** Operation to get virtual machines for subscription (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/getVmSizes) */ + #suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-action-verb" "Action can be used for get" @get getVmSizes is ArmProviderActionSync; /** Operation to get virtual machines for tenant (/providers/Microsoft.ContosoProviderHub/getVmSizesTenant) */ + #suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-action-verb" "Action can be used for get" @get getVmSizesTenant is ArmProviderActionSync; /** Operation to get virtual machines for subscription for specific location (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/locations/{location}/getVmSizesLocation) */ + #suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-action-verb" "Action can be used for get" @get getVmSizesLocation is ArmProviderActionSync< Response = VmSizeCollection, @@ -60,6 +63,7 @@ interface ProviderOperations { Parameters = LocationParameter >; /** Operation to get throttled requests sharing action (/subscriptions/{subscriptionId}/providers/Microsoft.ContosoProviderHub/logAnalytics/apiAccess/getThrottledRequests) */ + #suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-action-verb" "Action can be used for get" @get @action("logAnalytics/apiAccess/getThrottledRequests") getThrottledRequestsSubscription is ArmProviderActionSync< @@ -67,6 +71,7 @@ interface ProviderOperations { Scope = SubscriptionActionScope >; /** Operation to get throttled requests sharing action for tenant (/providers/Microsoft.ContosoProviderHub/logAnalytics/apiAccess/getThrottledRequests) */ + #suppress "@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-action-verb" "Action can be used for get" @get @action("logAnalytics/apiAccess/getThrottledRequests") getThrottledRequestsTenant is ArmProviderActionSync< 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 b5f3f243b1..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 @@ -47,7 +47,7 @@ ], "paths": { "/providers/Microsoft.OperationStatusSample/getVmSizesTenant": { - "post": { + "get": { "operationId": "ProviderOperations_GetVmSizesTenant", "tags": [ "ProviderOperations" @@ -78,7 +78,7 @@ } }, "/providers/Microsoft.OperationStatusSample/logAnalytics/apiAccess/getThrottledRequests": { - "post": { + "get": { "operationId": "ProviderOperations_GetThrottledRequestsTenant", "tags": [ "ProviderOperations" @@ -140,7 +140,7 @@ } }, "/subscriptions/{subscriptionId}/providers/Microsoft.OperationStatusSample/getVmSizes": { - "post": { + "get": { "operationId": "ProviderOperations_GetVmSizes", "tags": [ "ProviderOperations" @@ -174,7 +174,7 @@ } }, "/subscriptions/{subscriptionId}/providers/Microsoft.OperationStatusSample/locations/{location}/getVmSizesLocation": { - "post": { + "get": { "operationId": "ProviderOperations_GetVmSizesLocation", "tags": [ "ProviderOperations" @@ -266,7 +266,7 @@ } }, "/subscriptions/{subscriptionId}/providers/Microsoft.OperationStatusSample/logAnalytics/apiAccess/getThrottledRequests": { - "post": { + "get": { "operationId": "ProviderOperations_GetThrottledRequestsSubscription", "tags": [ "ProviderOperations" From 5dc069c06493b08000039e0ce0848219b9de2bf3 Mon Sep 17 00:00:00 2001 From: Alitzel Mendez <6895254+AlitzelMendez@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:59:57 -0700 Subject: [PATCH 05/12] Update .chronus/changes/fix-linting-rule-post-operation-2024-9-15-15-21-46.md Co-authored-by: Timothee Guerin --- .../fix-linting-rule-post-operation-2024-9-15-15-21-46.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.chronus/changes/fix-linting-rule-post-operation-2024-9-15-15-21-46.md b/.chronus/changes/fix-linting-rule-post-operation-2024-9-15-15-21-46.md index 70c88b3df1..4b86b63c6b 100644 --- a/.chronus/changes/fix-linting-rule-post-operation-2024-9-15-15-21-46.md +++ b/.chronus/changes/fix-linting-rule-post-operation-2024-9-15-15-21-46.md @@ -4,4 +4,4 @@ packages: - "@azure-tools/typespec-azure-resource-manager" --- -Fix linting rule to ensure that the linting rule triggers for @get operations on ArmProviderAction +Fix `arm-resource-invalid-action-verb` rule to trigger on `@get` operations on ArmProviderAction From 7bad4221d2ca410d5ed17680c298fc11adaf8cb0 Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Bustillo Date: Wed, 16 Oct 2024 13:41:59 -0700 Subject: [PATCH 06/12] Feedback + Documentation --- .../rules/arm-resource-invalid-action-verb.md | 33 +++++++++++++++++++ .../src/linter.ts | 4 +-- .../rules/arm-resource-invalid-action-verb.ts | 19 +++++------ ... arm-resource-invalid-action-verb.test.ts} | 4 +-- 4 files changed, 45 insertions(+), 15 deletions(-) create mode 100644 docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md rename packages/typespec-azure-resource-manager/test/rules/{operation-usage.test.ts => arm-resource-invalid-action-verb.test.ts} (98%) diff --git a/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md b/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md new file mode 100644 index 0000000000..fc6823e89a --- /dev/null +++ b/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md @@ -0,0 +1,33 @@ +--- +title: arm-resource-invalid-action-verb +--- + +```text title=- Full name- +@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-action-verb +``` + +For ARM http operations, the action verb must be `@post`. Any other action verb is flagged as incorrect. + +#### ❌ Incorrect + +```tsp + @get getAction is ArmProviderActionAsync< + { + name: string; + }, + ArmCombinedLroHeaders, + SubscriptionActionScope + >; +``` + +#### ✅ Correct + +```tsp + postAction is ArmProviderActionAsync< + { + name: string; + }, + ArmCombinedLroHeaders, + SubscriptionActionScope + >; +``` diff --git a/packages/typespec-azure-resource-manager/src/linter.ts b/packages/typespec-azure-resource-manager/src/linter.ts index c0d86c4b1d..fe17cf93ad 100644 --- a/packages/typespec-azure-resource-manager/src/linter.ts +++ b/packages/typespec-azure-resource-manager/src/linter.ts @@ -7,7 +7,7 @@ import { armPutResponseCodesRule } from "./rules/arm-put-response-codes.js"; import { armResourceActionNoSegmentRule } from "./rules/arm-resource-action-no-segment.js"; import { armResourceDuplicatePropertiesRule } from "./rules/arm-resource-duplicate-property.js"; import { interfacesRule } from "./rules/arm-resource-interfaces.js"; -import { invalidActionVerbRule } from "./rules/arm-resource-invalid-action-verb.js"; +import { armResourceInvalidActionVerb } from "./rules/arm-resource-invalid-action-verb.js"; import { armResourceEnvelopeProperties } from "./rules/arm-resource-invalid-envelope-property.js"; import { armResourceInvalidVersionFormatRule } from "./rules/arm-resource-invalid-version-format.js"; import { armResourceKeyInvalidCharsRule } from "./rules/arm-resource-key-invalid-chars.js"; @@ -51,7 +51,7 @@ const rules = [ deleteOperationMissingRule, envelopePropertiesRules, interfacesRule, - invalidActionVerbRule, + armResourceInvalidActionVerb, listBySubscriptionRule, lroLocationHeaderRule, missingXmsIdentifiersRule, diff --git a/packages/typespec-azure-resource-manager/src/rules/arm-resource-invalid-action-verb.ts b/packages/typespec-azure-resource-manager/src/rules/arm-resource-invalid-action-verb.ts index 4ab970ea09..0456fb9878 100644 --- a/packages/typespec-azure-resource-manager/src/rules/arm-resource-invalid-action-verb.ts +++ b/packages/typespec-azure-resource-manager/src/rules/arm-resource-invalid-action-verb.ts @@ -1,27 +1,24 @@ import { Operation, createRule } from "@typespec/compiler"; import { getOperationVerb } from "@typespec/http"; - import { getActionDetails } from "@typespec/rest"; -import { isInternalTypeSpec } from "./utils.js"; -export const invalidActionVerbRule = createRule({ +export const armResourceInvalidActionVerb = createRule({ name: "arm-resource-invalid-action-verb", severity: "warning", description: "Actions must be HTTP Post operations.", + url: "https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb", messages: { default: "Actions must be HTTP Post operations.", }, create(context) { return { operation: (operation: Operation) => { - if (!isInternalTypeSpec(context.program, operation)) { - const actionType = getActionDetails(context.program, operation); - const verb = getOperationVerb(context.program, operation); - if (actionType !== undefined && verb !== "post") { - context.reportDiagnostic({ - target: operation, - }); - } + const actionType = getActionDetails(context.program, operation); + const verb = getOperationVerb(context.program, operation); + if (actionType !== undefined && verb !== "post") { + context.reportDiagnostic({ + target: operation, + }); } }, }; diff --git a/packages/typespec-azure-resource-manager/test/rules/operation-usage.test.ts b/packages/typespec-azure-resource-manager/test/rules/arm-resource-invalid-action-verb.test.ts similarity index 98% rename from packages/typespec-azure-resource-manager/test/rules/operation-usage.test.ts rename to packages/typespec-azure-resource-manager/test/rules/arm-resource-invalid-action-verb.test.ts index ae13463466..e699cd998d 100644 --- a/packages/typespec-azure-resource-manager/test/rules/operation-usage.test.ts +++ b/packages/typespec-azure-resource-manager/test/rules/arm-resource-invalid-action-verb.test.ts @@ -7,7 +7,7 @@ import { import { getHttpOperation } from "@typespec/http"; import { strictEqual } from "assert"; import { beforeEach, describe, it } from "vitest"; -import { invalidActionVerbRule } from "../../src/rules/arm-resource-invalid-action-verb.js"; +import { armResourceInvalidActionVerb } from "../../src/rules/arm-resource-invalid-action-verb.js"; import { listBySubscriptionRule } from "../../src/rules/list-operation.js"; import { createAzureResourceManagerTestRunner } from "../test-host.js"; @@ -19,7 +19,7 @@ describe("typespec-azure-resource-manager: detect non-post actions", () => { runner = await createAzureResourceManagerTestRunner(); tester = createLinterRuleTester( runner, - invalidActionVerbRule, + armResourceInvalidActionVerb, "@azure-tools/typespec-azure-resource-manager", ); }); From 6ab1c7b33fa329d6928f830166556253bc55e2a9 Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Bustillo Date: Wed, 16 Oct 2024 13:51:08 -0700 Subject: [PATCH 07/12] Add test again and rename --- .../src/linter.ts | 4 +-- .../rules/arm-resource-invalid-action-verb.ts | 2 +- .../arm-resource-invalid-action-verb.test.ts | 36 +++++++++++++++++-- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/packages/typespec-azure-resource-manager/src/linter.ts b/packages/typespec-azure-resource-manager/src/linter.ts index fe17cf93ad..09be44f29e 100644 --- a/packages/typespec-azure-resource-manager/src/linter.ts +++ b/packages/typespec-azure-resource-manager/src/linter.ts @@ -7,7 +7,7 @@ import { armPutResponseCodesRule } from "./rules/arm-put-response-codes.js"; import { armResourceActionNoSegmentRule } from "./rules/arm-resource-action-no-segment.js"; import { armResourceDuplicatePropertiesRule } from "./rules/arm-resource-duplicate-property.js"; import { interfacesRule } from "./rules/arm-resource-interfaces.js"; -import { armResourceInvalidActionVerb } from "./rules/arm-resource-invalid-action-verb.js"; +import { armResourceInvalidActionVerbRule } from "./rules/arm-resource-invalid-action-verb.js"; import { armResourceEnvelopeProperties } from "./rules/arm-resource-invalid-envelope-property.js"; import { armResourceInvalidVersionFormatRule } from "./rules/arm-resource-invalid-version-format.js"; import { armResourceKeyInvalidCharsRule } from "./rules/arm-resource-key-invalid-chars.js"; @@ -51,7 +51,7 @@ const rules = [ deleteOperationMissingRule, envelopePropertiesRules, interfacesRule, - armResourceInvalidActionVerb, + armResourceInvalidActionVerbRule, listBySubscriptionRule, lroLocationHeaderRule, missingXmsIdentifiersRule, diff --git a/packages/typespec-azure-resource-manager/src/rules/arm-resource-invalid-action-verb.ts b/packages/typespec-azure-resource-manager/src/rules/arm-resource-invalid-action-verb.ts index 0456fb9878..62040299b9 100644 --- a/packages/typespec-azure-resource-manager/src/rules/arm-resource-invalid-action-verb.ts +++ b/packages/typespec-azure-resource-manager/src/rules/arm-resource-invalid-action-verb.ts @@ -2,7 +2,7 @@ import { Operation, createRule } from "@typespec/compiler"; import { getOperationVerb } from "@typespec/http"; import { getActionDetails } from "@typespec/rest"; -export const armResourceInvalidActionVerb = createRule({ +export const armResourceInvalidActionVerbRule = createRule({ name: "arm-resource-invalid-action-verb", severity: "warning", description: "Actions must be HTTP Post operations.", diff --git a/packages/typespec-azure-resource-manager/test/rules/arm-resource-invalid-action-verb.test.ts b/packages/typespec-azure-resource-manager/test/rules/arm-resource-invalid-action-verb.test.ts index e699cd998d..8706a30c54 100644 --- a/packages/typespec-azure-resource-manager/test/rules/arm-resource-invalid-action-verb.test.ts +++ b/packages/typespec-azure-resource-manager/test/rules/arm-resource-invalid-action-verb.test.ts @@ -7,7 +7,7 @@ import { import { getHttpOperation } from "@typespec/http"; import { strictEqual } from "assert"; import { beforeEach, describe, it } from "vitest"; -import { armResourceInvalidActionVerb } from "../../src/rules/arm-resource-invalid-action-verb.js"; +import { armResourceInvalidActionVerbRule } from "../../src/rules/arm-resource-invalid-action-verb.js"; import { listBySubscriptionRule } from "../../src/rules/list-operation.js"; import { createAzureResourceManagerTestRunner } from "../test-host.js"; @@ -19,7 +19,7 @@ describe("typespec-azure-resource-manager: detect non-post actions", () => { runner = await createAzureResourceManagerTestRunner(); tester = createLinterRuleTester( runner, - armResourceInvalidActionVerb, + armResourceInvalidActionVerbRule, "@azure-tools/typespec-azure-resource-manager", ); }); @@ -87,6 +87,38 @@ describe("typespec-azure-resource-manager: detect non-post actions", () => { message: "Actions must be HTTP Post operations.", }); }); + it("Detects non-post actions for internal operations", async () => { + await tester + .expect( + ` + @armProviderNamespace + @service({title: "Microsoft.Foo"}) + @versioned(Versions) + namespace Microsoft.Foo; + enum Versions { + @useDependency(Azure.ResourceManager.Versions.v1_0_Preview_1) + @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v5) + "2021-10-01-preview", + } + interface Operations extends Azure.ResourceManager.Operations {} + @doc("The VM Size") + model VmSize { + @doc("number of cpus ") + cpus: int32; + } + @armResourceOperations + interface ProviderOperations { + @get + @armResourceList(VmSize) + getVmsSizes is ArmProviderActionSync; + } + `, + ) + .toEmitDiagnostics({ + code: "@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-action-verb", + message: "Actions must be HTTP Post operations.", + }); + }); }); describe("typespec-azure-resource-manager: generates armResourceAction paths correctly", () => { From e92aea2c53ba4bb851914c37977ba956f5a45387 Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Bustillo Date: Wed, 16 Oct 2024 13:53:51 -0700 Subject: [PATCH 08/12] re-add blank space --- .../test/rules/arm-resource-invalid-action-verb.test.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/typespec-azure-resource-manager/test/rules/arm-resource-invalid-action-verb.test.ts b/packages/typespec-azure-resource-manager/test/rules/arm-resource-invalid-action-verb.test.ts index 8706a30c54..d27f6d0de8 100644 --- a/packages/typespec-azure-resource-manager/test/rules/arm-resource-invalid-action-verb.test.ts +++ b/packages/typespec-azure-resource-manager/test/rules/arm-resource-invalid-action-verb.test.ts @@ -100,12 +100,15 @@ describe("typespec-azure-resource-manager: detect non-post actions", () => { @armCommonTypesVersion(Azure.ResourceManager.CommonTypes.Versions.v5) "2021-10-01-preview", } + interface Operations extends Azure.ResourceManager.Operations {} + @doc("The VM Size") model VmSize { @doc("number of cpus ") cpus: int32; } + @armResourceOperations interface ProviderOperations { @get From 420b3f4ea9fc1bc4e7d9d41bd2172446dd03c922 Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Bustillo Date: Wed, 16 Oct 2024 14:40:22 -0700 Subject: [PATCH 09/12] Add documentation --- docs/libraries/azure-resource-manager/reference/linter.md | 2 +- packages/typespec-azure-resource-manager/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/libraries/azure-resource-manager/reference/linter.md b/docs/libraries/azure-resource-manager/reference/linter.md index 7d64cf2dcb..bcdd354402 100644 --- a/docs/libraries/azure-resource-manager/reference/linter.md +++ b/docs/libraries/azure-resource-manager/reference/linter.md @@ -43,7 +43,7 @@ Available ruleSets: | `@azure-tools/typespec-azure-resource-manager/no-resource-delete-operation` | Check for resources that must have a delete operation. | | `@azure-tools/typespec-azure-resource-manager/empty-updateable-properties` | Should have updateable properties. | | `@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator` | Each resource interface must have an @armResourceOperations decorator. | -| `@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-action-verb` | Actions must be HTTP Post operations. | +| [`@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-action-verb`](/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md) | Actions must be HTTP Post operations. | | `@azure-tools/typespec-azure-resource-manager/improper-subscription-list-operation` | Tenant and Extension resources should not define a list by subscription operation. | | [`@azure-tools/typespec-azure-resource-manager/lro-location-header`](/libraries/azure-resource-manager/rules/lro-location-header.md) | A 202 response should include a Location response header. | | [`@azure-tools/typespec-azure-resource-manager/missing-x-ms-identifiers`](/libraries/azure-resource-manager/rules/missing-x-ms-identifiers.md) | Array properties should describe their identifying properties with x-ms-identifiers. Decorate the property with @OpenAPI.extension("x-ms-identifiers", [id-prop]) where "id-prop" is a list of the names of identifying properties in the item type. | diff --git a/packages/typespec-azure-resource-manager/README.md b/packages/typespec-azure-resource-manager/README.md index d4c5548e62..bfaaa9bdff 100644 --- a/packages/typespec-azure-resource-manager/README.md +++ b/packages/typespec-azure-resource-manager/README.md @@ -47,7 +47,7 @@ Available ruleSets: | `@azure-tools/typespec-azure-resource-manager/no-resource-delete-operation` | Check for resources that must have a delete operation. | | `@azure-tools/typespec-azure-resource-manager/empty-updateable-properties` | Should have updateable properties. | | `@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator` | Each resource interface must have an @armResourceOperations decorator. | -| `@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-action-verb` | Actions must be HTTP Post operations. | +| [`@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-action-verb`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb) | Actions must be HTTP Post operations. | | `@azure-tools/typespec-azure-resource-manager/improper-subscription-list-operation` | Tenant and Extension resources should not define a list by subscription operation. | | [`@azure-tools/typespec-azure-resource-manager/lro-location-header`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/lro-location-header) | A 202 response should include a Location response header. | | [`@azure-tools/typespec-azure-resource-manager/missing-x-ms-identifiers`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/missing-x-ms-identifiers) | Array properties should describe their identifying properties with x-ms-identifiers. Decorate the property with @OpenAPI.extension("x-ms-identifiers", [id-prop]) where "id-prop" is a list of the names of identifying properties in the item type. | From c5a6c596cd7c65801fbe984eb820e65015c1079f Mon Sep 17 00:00:00 2001 From: Alitzel Mendez <6895254+AlitzelMendez@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:58:08 -0700 Subject: [PATCH 10/12] Update docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md Co-authored-by: Timothee Guerin --- .../rules/arm-resource-invalid-action-verb.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md b/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md index fc6823e89a..5054f54260 100644 --- a/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md +++ b/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md @@ -11,7 +11,7 @@ For ARM http operations, the action verb must be `@post`. Any other action verb #### ❌ Incorrect ```tsp - @get getAction is ArmProviderActionAsync< + @get op getAction is ArmProviderActionAsync< { name: string; }, From 440d1396ffdf7aadd18eac1ce4eb1e2ee7025057 Mon Sep 17 00:00:00 2001 From: Alitzel Mendez <6895254+AlitzelMendez@users.noreply.github.com> Date: Wed, 16 Oct 2024 14:58:15 -0700 Subject: [PATCH 11/12] Update docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md Co-authored-by: Timothee Guerin --- .../rules/arm-resource-invalid-action-verb.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md b/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md index 5054f54260..ed5d8cb658 100644 --- a/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md +++ b/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md @@ -23,7 +23,7 @@ For ARM http operations, the action verb must be `@post`. Any other action verb #### ✅ Correct ```tsp - postAction is ArmProviderActionAsync< + op postAction is ArmProviderActionAsync< { name: string; }, From db5b6cdb5b9250065077da468138a6d612c65fa8 Mon Sep 17 00:00:00 2001 From: Alitzel Mendez Bustillo Date: Wed, 16 Oct 2024 15:15:54 -0700 Subject: [PATCH 12/12] fix feedback style --- .../rules/arm-resource-invalid-action-verb.md | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md b/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md index ed5d8cb658..5a34644986 100644 --- a/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md +++ b/docs/libraries/azure-resource-manager/rules/arm-resource-invalid-action-verb.md @@ -11,23 +11,23 @@ For ARM http operations, the action verb must be `@post`. Any other action verb #### ❌ Incorrect ```tsp - @get op getAction is ArmProviderActionAsync< - { - name: string; - }, - ArmCombinedLroHeaders, - SubscriptionActionScope - >; +@get op getAction is ArmProviderActionAsync< + { + name: string; + }, + ArmCombinedLroHeaders, + SubscriptionActionScope +>; ``` #### ✅ Correct ```tsp - op postAction is ArmProviderActionAsync< - { - name: string; - }, - ArmCombinedLroHeaders, - SubscriptionActionScope - >; +op postAction is ArmProviderActionAsync< + { + name: string; + }, + ArmCombinedLroHeaders, + SubscriptionActionScope +>; ```