@azure-tools/typespec-azure-resource-manager 0.71.0-dev.10 → 0.71.0-dev.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -45,6 +45,8 @@ Available ruleSets:
45
45
  | [`@azure-tools/typespec-azure-resource-manager/arm-resource-key-invalid-chars`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/arm-resource-key-invalid-chars) | Arm resource key must contain only alphanumeric characters. |
46
46
  | [`@azure-tools/typespec-azure-resource-manager/arm-resource-name-pattern`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/arm-resource-name-pattern) | The resource name parameter should be defined with a 'pattern' restriction. |
47
47
  | [`@azure-tools/typespec-azure-resource-manager/arm-resource-operation-response`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/arm-resource-operation-response) | [RPC 008]: PUT, GET, PATCH & LIST must return the same resource schema. |
48
+ | [`@azure-tools/typespec-azure-resource-manager/use-api-version`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/use-api-version) | Validate ARM Resource operations include the api-version parameter referencing Azure.ResourceManager.CommonTypes.ApiVersionParameter. |
49
+ | [`@azure-tools/typespec-azure-resource-manager/use-operation-decorator`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/use-operation-decorator) | Validate ARM Resource operations use the correct decorator for the HTTP verb. |
48
50
  | [`@azure-tools/typespec-azure-resource-manager/arm-resource-path-segment-invalid-chars`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/arm-resource-path-segment-invalid-chars) | Arm resource name must contain only alphanumeric characters. |
49
51
  | [`@azure-tools/typespec-azure-resource-manager/arm-resource-provisioning-state`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/arm-resource-provisioning-state) | Check for properly configured provisioningState property. |
50
52
  | [`@azure-tools/typespec-azure-resource-manager/version-progression`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/version-progression) | Validate that ARM service versions all use unique dates and are declared in strictly increasing chronological order. |
@@ -52,7 +54,7 @@ Available ruleSets:
52
54
  | [`@azure-tools/typespec-azure-resource-manager/arm-custom-resource-usage-discourage`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/arm-custom-resource-usage-discourage) | Verify the usage of @customAzureResource decorator. |
53
55
  | [`@azure-tools/typespec-azure-resource-manager/arm-feature-file-usage-discourage`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/arm-feature-file-usage-discourage) | Verify the usage of @featureFiles decorator. |
54
56
  | [`@azure-tools/typespec-azure-resource-manager/beyond-nesting-levels`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/beyond-nesting-levels) | Tracked Resources must use 3 or fewer levels of nesting. |
55
- | [`@azure-tools/typespec-azure-resource-manager/arm-resource-operation`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/arm-resource-operation) | Validate ARM Resource operations. |
57
+ | [`@azure-tools/typespec-azure-resource-manager/use-interface`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/use-interface) | Validate ARM Resource operations are defined inside an interface declaration. |
56
58
  | [`@azure-tools/typespec-azure-resource-manager/no-resource-delete-operation`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/no-resource-delete-operation) | Check for resources that must have a delete operation. |
57
59
  | [`@azure-tools/typespec-azure-resource-manager/empty-updateable-properties`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/empty-updateable-properties) | Should have updateable properties. |
58
60
  | [`@azure-tools/typespec-azure-resource-manager/arm-resource-interface-requires-decorator`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/arm-resource-interface-requires-decorator) | Each resource interface must have an @armResourceOperations decorator. |
@@ -1 +1 @@
1
- {"version":3,"file":"linter.d.ts","sourceRoot":"","sources":["../../src/linter.ts"],"names":[],"mappings":"AAyFA,eAAO,MAAM,OAAO,+CAElB,CAAC"}
1
+ {"version":3,"file":"linter.d.ts","sourceRoot":"","sources":["../../src/linter.ts"],"names":[],"mappings":"AA6FA,eAAO,MAAM,OAAO,+CAElB,CAAC"}
@@ -23,7 +23,6 @@ import { patchOperationsRule } from "./rules/arm-resource-patch.js";
23
23
  import { armResourcePathInvalidCharsRule } from "./rules/arm-resource-path-invalid-chars.js";
24
24
  import { armResourceProvisioningStateRule } from "./rules/arm-resource-provisioning-state-rule.js";
25
25
  import { beyondNestingRule } from "./rules/beyond-nesting-levels.js";
26
- import { coreOperationsRule } from "./rules/core-operations.js";
27
26
  import { envelopePropertiesRules } from "./rules/envelope-properties.js";
28
27
  import { improperSubscriptionListOperationRule } from "./rules/improper-subscription-list-operation.js";
29
28
  import { lroLocationHeaderRule } from "./rules/lro-location-header.js";
@@ -39,6 +38,9 @@ import { resourceNameRule } from "./rules/resource-name.js";
39
38
  import { retryAfterRule } from "./rules/retry-after.js";
40
39
  import { secretProprule } from "./rules/secret-prop.js";
41
40
  import { unsupportedTypeRule } from "./rules/unsupported-type.js";
41
+ import { useApiVersionRule } from "./rules/use-api-version.js";
42
+ import { useInterfaceRule } from "./rules/use-interface.js";
43
+ import { useOperationDecoratorRule } from "./rules/use-operation-decorator.js";
42
44
  import { useRelationshipRequiredPropertiesRule } from "./rules/use-relationship-required-properties.js";
43
45
  import { versionProgressionRule } from "./rules/version-progression.js";
44
46
  const rules = [
@@ -59,6 +61,8 @@ const rules = [
59
61
  armResourceKeyInvalidCharsRule,
60
62
  armResourceNamePatternRule,
61
63
  armResourceOperationsRule,
64
+ useApiVersionRule,
65
+ useOperationDecoratorRule,
62
66
  armResourcePathInvalidCharsRule,
63
67
  armResourceProvisioningStateRule,
64
68
  versionProgressionRule,
@@ -66,7 +70,7 @@ const rules = [
66
70
  armCustomResourceUsageDiscourage,
67
71
  armFeatureFileUsageDiscourage,
68
72
  beyondNestingRule,
69
- coreOperationsRule,
73
+ useInterfaceRule,
70
74
  deleteOperationMissingRule,
71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AAc;IACd,mBAAmB;IACnB,cAAc;IACd,YAAY;IACZ,8BAA8B;CAC/B,CAAC;AAEF,MAAM,CAAC,MAAM,OAAO,GAAG,YAAY,CAAC;IAClC,KAAK;CACN,CAAC,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const useApiVersionRule: import("@typespec/compiler").LinterRuleDefinition<"use-api-version", {
2
+ readonly default: "All Resource operations must use an api-version parameter. Please include Azure.ResourceManager.ApiVersionParameter in the operation parameter list using the spread (...ApiVersionParameter) operator, or using one of the common resource parameter models.";
3
+ }, Record<string, never>>;
4
+ //# sourceMappingURL=use-api-version.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-api-version.d.ts","sourceRoot":"","sources":["../../../src/rules/use-api-version.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,iBAAiB;;yBA4B5B,CAAC"}
@@ -0,0 +1,45 @@
1
+ import { createRule, isTemplateInstance } from "@typespec/compiler";
2
+ import { getNamespaceName, getSourceModel, isTemplatedInterfaceOperation } from "./utils.js";
3
+ export const useApiVersionRule = createRule({
4
+ name: "use-api-version",
5
+ severity: "warning",
6
+ description: "Validate ARM Resource operations include the api-version parameter referencing Azure.ResourceManager.CommonTypes.ApiVersionParameter.",
7
+ url: "https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/use-api-version",
8
+ messages: {
9
+ default: "All Resource operations must use an api-version parameter. Please include Azure.ResourceManager.ApiVersionParameter in the operation parameter list using the spread (...ApiVersionParameter) operator, or using one of the common resource parameter models.",
10
+ },
11
+ create(context) {
12
+ return {
13
+ operation: (operation) => {
14
+ if (!isTemplateInstance(operation) && !isTemplatedInterfaceOperation(operation)) {
15
+ const parameters = operation.parameters;
16
+ if (parameters === undefined ||
17
+ parameters === null ||
18
+ !hasApiParameter(context.program, parameters)) {
19
+ context.reportDiagnostic({
20
+ target: operation,
21
+ });
22
+ }
23
+ }
24
+ },
25
+ };
26
+ },
27
+ });
28
+ function isApiParameter(program, property) {
29
+ if (property.type.kind !== "Scalar")
30
+ return false;
31
+ if (!property.sourceProperty)
32
+ return false;
33
+ const sourceModel = getSourceModel(property.sourceProperty);
34
+ if (sourceModel === undefined)
35
+ return false;
36
+ return (sourceModel.name === "ApiVersionParameter" &&
37
+ getNamespaceName(program, sourceModel) === "Azure.ResourceManager.CommonTypes");
38
+ }
39
+ function hasApiParameter(program, model) {
40
+ if (model.properties === undefined || model.properties.size === 0)
41
+ return false;
42
+ const apiVersionParams = [...model.properties.values()].filter((i) => isApiParameter(program, i));
43
+ return apiVersionParams !== null && apiVersionParams.length === 1;
44
+ }
45
+ //# sourceMappingURL=use-api-version.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-api-version.js","sourceRoot":"","sources":["../../../src/rules/use-api-version.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,6BAA6B,EAAE,MAAM,YAAY,CAAC;AAE7F,MAAM,CAAC,MAAM,iBAAiB,GAAG,UAAU,CAAC;IAC1C,IAAI,EAAE,iBAAiB;IACvB,QAAQ,EAAE,SAAS;IACnB,WAAW,EACT,uIAAuI;IACzI,GAAG,EAAE,oGAAoG;IACzG,QAAQ,EAAE;QACR,OAAO,EACL,+PAA+P;KAClQ;IACD,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,SAAS,EAAE,CAAC,SAAoB,EAAE,EAAE;gBAClC,IAAI,CAAC,kBAAkB,CAAC,SAAS,CAAC,IAAI,CAAC,6BAA6B,CAAC,SAAS,CAAC,EAAE,CAAC;oBAChF,MAAM,UAAU,GAAU,SAAS,CAAC,UAAU,CAAC;oBAC/C,IACE,UAAU,KAAK,SAAS;wBACxB,UAAU,KAAK,IAAI;wBACnB,CAAC,eAAe,CAAC,OAAO,CAAC,OAAO,EAAE,UAAU,CAAC,EAC7C,CAAC;wBACD,OAAO,CAAC,gBAAgB,CAAC;4BACvB,MAAM,EAAE,SAAS;yBAClB,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC;AAEH,SAAS,cAAc,CAAC,OAAgB,EAAE,QAAuB;IAC/D,IAAI,QAAQ,CAAC,IAAI,CAAC,IAAI,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAClD,IAAI,CAAC,QAAQ,CAAC,cAAc;QAAE,OAAO,KAAK,CAAC;IAC3C,MAAM,WAAW,GAAsB,cAAc,CAAC,QAAQ,CAAC,cAAc,CAAC,CAAC;IAC/E,IAAI,WAAW,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAC5C,OAAO,CACL,WAAW,CAAC,IAAI,KAAK,qBAAqB;QAC1C,gBAAgB,CAAC,OAAO,EAAE,WAAW,CAAC,KAAK,mCAAmC,CAC/E,CAAC;AACJ,CAAC;AAED,SAAS,eAAe,CAAC,OAAgB,EAAE,KAAY;IACrD,IAAI,KAAK,CAAC,UAAU,KAAK,SAAS,IAAI,KAAK,CAAC,UAAU,CAAC,IAAI,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAChF,MAAM,gBAAgB,GAAoB,CAAC,GAAG,KAAK,CAAC,UAAU,CAAC,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CACpF,cAAc,CAAC,OAAO,EAAE,CAAC,CAAC,CAC3B,CAAC;IACF,OAAO,gBAAgB,KAAK,IAAI,IAAI,gBAAgB,CAAC,MAAM,KAAK,CAAC,CAAC;AACpE,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare const useInterfaceRule: import("@typespec/compiler").LinterRuleDefinition<"use-interface", {
2
+ readonly default: "All operations must be inside an interface declaration.";
3
+ }, Record<string, never>>;
4
+ //# sourceMappingURL=use-interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-interface.d.ts","sourceRoot":"","sources":["../../../src/rules/use-interface.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,gBAAgB;;yBA4B3B,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { createRule, isTemplateInstance } from "@typespec/compiler";
2
+ import { SyntaxKind } from "@typespec/compiler/ast";
3
+ import { isSourceOperationResourceManagerInternal, isTemplatedInterfaceOperation, } from "./utils.js";
4
+ export const useInterfaceRule = createRule({
5
+ name: "use-interface",
6
+ severity: "warning",
7
+ description: "Validate ARM Resource operations are defined inside an interface declaration.",
8
+ url: "https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/use-interface",
9
+ messages: {
10
+ default: "All operations must be inside an interface declaration.",
11
+ },
12
+ create(context) {
13
+ return {
14
+ operation: (operation) => {
15
+ if (!isSourceOperationResourceManagerInternal(operation) &&
16
+ !isTemplateInstance(operation)) {
17
+ if (!isTemplatedInterfaceOperation(operation) &&
18
+ (!operation.node?.parent ||
19
+ operation.node.parent.kind !== SyntaxKind.InterfaceStatement)) {
20
+ context.reportDiagnostic({
21
+ target: operation,
22
+ });
23
+ }
24
+ }
25
+ },
26
+ };
27
+ },
28
+ });
29
+ //# sourceMappingURL=use-interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-interface.js","sourceRoot":"","sources":["../../../src/rules/use-interface.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EACL,wCAAwC,EACxC,6BAA6B,GAC9B,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,gBAAgB,GAAG,UAAU,CAAC;IACzC,IAAI,EAAE,eAAe;IACrB,QAAQ,EAAE,SAAS;IACnB,WAAW,EAAE,+EAA+E;IAC5F,GAAG,EAAE,kGAAkG;IACvG,QAAQ,EAAE;QACR,OAAO,EAAE,yDAAyD;KACnE;IACD,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,SAAS,EAAE,CAAC,SAAoB,EAAE,EAAE;gBAClC,IACE,CAAC,wCAAwC,CAAC,SAAS,CAAC;oBACpD,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAC9B,CAAC;oBACD,IACE,CAAC,6BAA6B,CAAC,SAAS,CAAC;wBACzC,CAAC,CAAC,SAAS,CAAC,IAAI,EAAE,MAAM;4BACtB,SAAS,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,KAAK,UAAU,CAAC,kBAAkB,CAAC,EAC/D,CAAC;wBACD,OAAO,CAAC,gBAAgB,CAAC;4BACvB,MAAM,EAAE,SAAS;yBAClB,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export declare const useOperationDecoratorRule: import("@typespec/compiler").LinterRuleDefinition<"use-operation-decorator", {
2
+ readonly default: import("@typespec/compiler").CallableMessage<["verb", "decorator"]>;
3
+ readonly invalidOperationType: import("@typespec/compiler").CallableMessage<["verb", "decorator", "operationType"]>;
4
+ }, Record<string, never>>;
5
+ //# sourceMappingURL=use-operation-decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-operation-decorator.d.ts","sourceRoot":"","sources":["../../../src/rules/use-operation-decorator.ts"],"names":[],"mappings":"AAeA,eAAO,MAAM,yBAAyB;;;yBA0DpC,CAAC"}
@@ -0,0 +1,133 @@
1
+ import { createRule, isTemplateInstance, paramMessage } from "@typespec/compiler";
2
+ import { getOperationVerb } from "@typespec/http";
3
+ import { getSegment } from "@typespec/rest";
4
+ import { isSourceOperationResourceManagerInternal, isTemplatedInterfaceOperation, } from "./utils.js";
5
+ export const useOperationDecoratorRule = createRule({
6
+ name: "use-operation-decorator",
7
+ severity: "warning",
8
+ description: "Validate ARM Resource operations use the correct decorator for the HTTP verb.",
9
+ url: "https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/use-operation-decorator",
10
+ messages: {
11
+ default: paramMessage `Resource ${"verb"} operation must be decorated with ${"decorator"}.`,
12
+ invalidOperationType: paramMessage `Resource ${"verb"} operation decorator ${"decorator"} must use operationType ${"operationType"}.`,
13
+ },
14
+ create(context) {
15
+ return {
16
+ operation: (operation) => {
17
+ if (!isSourceOperationResourceManagerInternal(operation) &&
18
+ !isTemplateInstance(operation)) {
19
+ const verb = getOperationVerb(context.program, operation);
20
+ if (verb && isTemplatedInterfaceOperation(operation) === false) {
21
+ const requiredDecorators = resourceOperationDecorators[verb];
22
+ if (requiredDecorators?.length > 0) {
23
+ const decorator = operation.decorators.find((d) => requiredDecorators.indexOf(d.decorator.name) >= 0);
24
+ if (!decorator && !isArmProviderOperation(context.program, operation)) {
25
+ context.reportDiagnostic({
26
+ messageId: "default",
27
+ target: operation,
28
+ format: {
29
+ verb: verb.toUpperCase(),
30
+ decorator: requiredDecorators.map((d) => `@${d.substring(1)}`).join(" or "),
31
+ },
32
+ });
33
+ }
34
+ else if (decorator) {
35
+ const allowedOperationTypes = operationTypesByVerb[verb];
36
+ const operationType = getGenericDecoratorOperationType(decorator);
37
+ if (allowedOperationTypes !== undefined &&
38
+ operationType !== undefined &&
39
+ !allowedOperationTypes.includes(operationType)) {
40
+ context.reportDiagnostic({
41
+ messageId: "invalidOperationType",
42
+ target: operation,
43
+ format: {
44
+ verb: verb.toUpperCase(),
45
+ decorator: `@${decorator.decorator.name.substring(1)}`,
46
+ operationType: allowedOperationTypes.map((x) => `"${x}"`).join(" or "),
47
+ },
48
+ });
49
+ }
50
+ }
51
+ }
52
+ }
53
+ }
54
+ },
55
+ };
56
+ },
57
+ });
58
+ // These private ARM decorators cover all operation types and serve as valid alternatives
59
+ // to the public per-verb decorators (e.g. in extension resource, legacy, and built-in operations).
60
+ const genericArmResourceDecorators = [
61
+ "$extensionResourceOperation",
62
+ "$legacyResourceOperation",
63
+ "$builtInResourceOperation",
64
+ "$legacyExtensionResourceOperation",
65
+ ];
66
+ // operationType argument position per decorator signature:
67
+ // - extensionResourceOperation(targetResourceType, extensionResourceType, operationType, ...)
68
+ // - legacyResourceOperation(resourceType, operationType, ...)
69
+ // - builtInResourceOperation(parentResourceType, builtInResourceType, operationType, ...)
70
+ // - legacyExtensionResourceOperation(resourceType, operationType, ...)
71
+ const operationTypeArgIndexByDecorator = {
72
+ $extensionResourceOperation: 2,
73
+ $legacyResourceOperation: 1,
74
+ $builtInResourceOperation: 2,
75
+ $legacyExtensionResourceOperation: 1,
76
+ };
77
+ const resourceOperationDecorators = {
78
+ put: ["$armResourceCreateOrUpdate", ...genericArmResourceDecorators],
79
+ get: ["$armResourceRead", "$armResourceList", ...genericArmResourceDecorators],
80
+ patch: ["$armResourceUpdate", ...genericArmResourceDecorators],
81
+ delete: ["$armResourceDelete", ...genericArmResourceDecorators],
82
+ post: ["$armResourceAction", "$armResourceCollectionAction", ...genericArmResourceDecorators],
83
+ head: [],
84
+ };
85
+ // ARM operationType conventions:
86
+ // - PUT => createOrUpdate
87
+ // - GET => read or list
88
+ // - PATCH => update
89
+ // - DELETE => delete
90
+ // - POST => action
91
+ // This map is used only for generic private decorators that encode operation type as an argument.
92
+ const operationTypesByVerb = {
93
+ put: ["createOrUpdate"],
94
+ get: ["read", "list"],
95
+ patch: ["update"],
96
+ delete: ["delete"],
97
+ post: ["action"],
98
+ };
99
+ function isGenericArmResourceDecorator(name) {
100
+ return genericArmResourceDecorators.includes(name);
101
+ }
102
+ function getGenericDecoratorOperationType(decorator) {
103
+ const decoratorName = decorator.decorator.name;
104
+ if (!isGenericArmResourceDecorator(decoratorName)) {
105
+ return undefined;
106
+ }
107
+ const operationTypeArg = decorator.args[operationTypeArgIndexByDecorator[decoratorName]];
108
+ return getDecoratorArgumentStringValue(operationTypeArg);
109
+ }
110
+ function getDecoratorArgumentStringValue(arg) {
111
+ return typeof arg?.jsValue === "string" ? arg.jsValue : undefined;
112
+ }
113
+ function isStaticSegment(segment) {
114
+ return segment === undefined || segment === "locations";
115
+ }
116
+ function isArmProviderOperation(program, operation) {
117
+ let isProviderAction = false;
118
+ for (const [index, [, property]] of [...operation.parameters.properties].entries()) {
119
+ const segment = getSegment(program, property);
120
+ if (segment === "providers") {
121
+ isProviderAction = true;
122
+ }
123
+ else if (isProviderAction && !isStaticSegment(segment)) {
124
+ return false;
125
+ }
126
+ const isLastSegment = index === operation.parameters.properties.size - 1;
127
+ if (isLastSegment && !segment) {
128
+ return true;
129
+ }
130
+ }
131
+ return false;
132
+ }
133
+ //# sourceMappingURL=use-operation-decorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-operation-decorator.js","sourceRoot":"","sources":["../../../src/rules/use-operation-decorator.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAE,kBAAkB,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElF,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACL,wCAAwC,EACxC,6BAA6B,GAC9B,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,yBAAyB,GAAG,UAAU,CAAC;IAClD,IAAI,EAAE,yBAAyB;IAC/B,QAAQ,EAAE,SAAS;IACnB,WAAW,EAAE,+EAA+E;IAC5F,GAAG,EAAE,4GAA4G;IACjH,QAAQ,EAAE;QACR,OAAO,EAAE,YAAY,CAAA,YAAY,MAAM,qCAAqC,WAAW,GAAG;QAC1F,oBAAoB,EAAE,YAAY,CAAA,YAAY,MAAM,wBAAwB,WAAW,2BAA2B,eAAe,GAAG;KACrI;IACD,MAAM,CAAC,OAAO;QACZ,OAAO;YACL,SAAS,EAAE,CAAC,SAAoB,EAAE,EAAE;gBAClC,IACE,CAAC,wCAAwC,CAAC,SAAS,CAAC;oBACpD,CAAC,kBAAkB,CAAC,SAAS,CAAC,EAC9B,CAAC;oBACD,MAAM,IAAI,GAAG,gBAAgB,CAAC,OAAO,CAAC,OAAO,EAAE,SAAS,CAAC,C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AE9C,IAAI,OAAO,KAAK,WAAW,EAAE,CAAC;YAC5B,gBAAgB,GAAG,IAAI,CAAC;QAC1B,CAAC;aAAM,IAAI,gBAAgB,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,CAAC;YACzD,OAAO,KAAK,CAAC;QACf,CAAC;QAED,MAAM,aAAa,GAAG,KAAK,KAAK,SAAS,CAAC,UAAU,CAAC,UAAU,CAAC,IAAI,GAAG,CAAC,CAAC;QACzE,IAAI,aAAa,IAAI,CAAC,OAAO,EAAE,CAAC;YAC9B,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@azure-tools/typespec-azure-resource-manager",
3
- "version": "0.71.0-dev.10",
3
+ "version": "0.71.0-dev.11",
4
4
  "author": "Microsoft Corporation",
5
5
  "description": "TypeSpec Azure Resource Manager library",
6
6
  "homepage": "https://azure.github.io/typespec-azure",
@@ -47,15 +47,15 @@
47
47
  "pluralize": "^8.0.0"
48
48
  },
49
49
  "peerDependencies": {
50
- "@azure-tools/typespec-azure-core": "^0.70.0 || >= 0.71.0-dev.3",
50
+ "@azure-tools/typespec-azure-core": "^0.70.0 || >= 0.71.0-dev.4",
51
51
  "@typespec/compiler": "^1.14.0",
52
52
  "@typespec/http": "^1.14.0",
53
53
  "@typespec/rest": "^0.84.0",
54
- "@typespec/versioning": "^0.84.0",
55
- "@typespec/openapi": "^1.14.0"
54
+ "@typespec/openapi": "^1.14.0",
55
+ "@typespec/versioning": "^0.84.0"
56
56
  },
57
57
  "devDependencies": {
58
- "@azure-tools/typespec-azure-core": "^0.70.0 || >= 0.71.0-dev.3",
58
+ "@azure-tools/typespec-azure-core": "^0.70.0 || >= 0.71.0-dev.4",
59
59
  "@types/node": "^26.0.0",
60
60
  "@types/pluralize": "^0.0.33",
61
61
  "@vitest/coverage-v8": "^4.1.3",
@@ -63,12 +63,12 @@
63
63
  "rimraf": "^6.1.3",
64
64
  "typescript": "~6.0.2",
65
65
  "vitest": "^4.1.3",
66
- "@typespec/rest": "^0.84.0",
67
- "@typespec/versioning": "^0.84.0",
68
66
  "@typespec/compiler": "^1.14.0",
69
67
  "@typespec/library-linter": "^0.84.0",
70
- "@typespec/tspd": "^0.76.0",
71
68
  "@typespec/http": "^1.14.0",
69
+ "@typespec/versioning": "^0.84.0",
70
+ "@typespec/rest": "^0.84.0",
71
+ "@typespec/tspd": "^0.76.0",
72
72
  "@typespec/openapi": "^1.14.0"
73
73
  },
74
74
  "scripts": {
@@ -1,6 +0,0 @@
1
- export declare const coreOperationsRule: import("@typespec/compiler").LinterRuleDefinition<"arm-resource-operation", {
2
- readonly default: "All Resource operations must use an api-version parameter. Please include Azure.ResourceManager.ApiVersionParameter in the operation parameter list using the spread (...ApiVersionParameter) operator, or using one of the common resource parameter models.";
3
- readonly opOutsideInterface: "All operations must be inside an interface declaration.";
4
- readonly opMissingDecorator: import("@typespec/compiler").CallableMessage<["verb", "decorator"]>;
5
- }, Record<string, never>>;
6
- //# sourceMappingURL=core-operations.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"core-operations.d.ts","sourceRoot":"","sources":["../../../src/rules/core-operations.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,kBAAkB;;;;yBA8D7B,CAAC"}
@@ -1,105 +0,0 @@
1
- import { createRule, fileRef, isTemplateInstance, paramMessage, } from "@typespec/compiler";
2
- import { SyntaxKind } from "@typespec/compiler/ast";
3
- import { getOperationVerb } from "@typespec/http";
4
- import { getSegment } from "@typespec/rest";
5
- import { getNamespaceName, getSourceModel, isSourceOperationResourceManagerInternal, isTemplatedInterfaceOperation, } from "./utils.js";
6
- export const coreOperationsRule = createRule({
7
- name: "arm-resource-operation",
8
- docs: fileRef.fromPackageRoot("src/rules/arm-resource-operation.md"),
9
- severity: "warning",
10
- description: "Validate ARM Resource operations.",
11
- url: "https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/arm-resource-operation",
12
- messages: {
13
- default: "All Resource operations must use an api-version parameter. Please include Azure.ResourceManager.ApiVersionParameter in the operation parameter list using the spread (...ApiVersionParameter) operator, or using one of the common resource parameter models.",
14
- opOutsideInterface: "All operations must be inside an interface declaration.",
15
- opMissingDecorator: paramMessage `Resource ${"verb"} operation must be decorated with ${"decorator"}.`,
16
- },
17
- create(context) {
18
- return {
19
- operation: (operation) => {
20
- if (!isSourceOperationResourceManagerInternal(operation) &&
21
- !isTemplateInstance(operation)) {
22
- const verb = getOperationVerb(context.program, operation);
23
- if (!isTemplatedInterfaceOperation(operation) &&
24
- (!operation.node?.parent ||
25
- operation.node.parent.kind !== SyntaxKind.InterfaceStatement)) {
26
- context.reportDiagnostic({
27
- messageId: "opOutsideInterface",
28
- target: operation,
29
- });
30
- }
31
- const parameters = operation.parameters;
32
- if (parameters === undefined ||
33
- parameters === null ||
34
- !hasApiParameter(context.program, parameters)) {
35
- context.reportDiagnostic({
36
- target: operation,
37
- });
38
- }
39
- if (verb) {
40
- const requiredDecorators = resourceOperationDecorators[verb];
41
- if (requiredDecorators?.length > 0) {
42
- const decorator = operation.decorators.find((d) => requiredDecorators.indexOf(d.decorator.name) >= 0);
43
- if (!decorator && !isArmProviderOperation(context.program, operation)) {
44
- context.reportDiagnostic({
45
- messageId: "opMissingDecorator",
46
- target: operation,
47
- format: {
48
- verb: verb.toUpperCase(),
49
- decorator: requiredDecorators.map((d) => `@${d.substring(1)}`).join(" or "),
50
- },
51
- });
52
- }
53
- }
54
- }
55
- }
56
- },
57
- };
58
- },
59
- });
60
- const resourceOperationDecorators = {
61
- put: ["$armResourceCreateOrUpdate"],
62
- get: ["$armResourceRead", "$armResourceList"],
63
- patch: ["$armResourceUpdate"],
64
- delete: ["$armResourceDelete"],
65
- post: ["$armResourceAction", "$armResourceCollectionAction"],
66
- head: [],
67
- };
68
- function isApiParameter(program, property) {
69
- if (property.type.kind !== "Scalar")
70
- return false;
71
- if (!property.sourceProperty)
72
- return false;
73
- const sourceModel = getSourceModel(property.sourceProperty);
74
- if (sourceModel === undefined)
75
- return false;
76
- return (sourceModel.name === "ApiVersionParameter" &&
77
- getNamespaceName(program, sourceModel) === "Azure.ResourceManager.CommonTypes");
78
- }
79
- function hasApiParameter(program, model) {
80
- if (model.properties === undefined || model.properties.size === 0)
81
- return false;
82
- const apiVersionParams = [...model.properties.values()].filter((i) => isApiParameter(program, i));
83
- return apiVersionParams !== null && apiVersionParams.length === 1;
84
- }
85
- function isStaticSegment(segment, property) {
86
- return segment === undefined || segment === "locations";
87
- }
88
- function isArmProviderOperation(program, operation) {
89
- let isProviderAction = false;
90
- for (const [index, [, property]] of [...operation.parameters.properties].entries()) {
91
- const segment = getSegment(program, property);
92
- if (segment === "providers") {
93
- isProviderAction = true;
94
- }
95
- else if (isProviderAction && !isStaticSegment(segment, property)) {
96
- return false;
97
- }
98
- const isLastSegment = index === operation.parameters.properties.size - 1;
99
- if (isLastSegment && !segment) {
100
- return true;
101
- }
102
- }
103
- return false;
104
- }
105
- //# sourceMappingURL=core-operations.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"core-operations.js","sourceRoot":"","sources":["../../../src/rules/core-operations.ts"],"names":[],"mappings":"AAAA,OAAO,EAKL,UAAU,EACV,OAAO,EACP,kBAAkB,EAClB,YAAY,GACb,MAAM,oBAAoB,CAAC;AAC5B,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAiB,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC5C,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,wCAAwC,EACxC,6BAA6B,GAC9B,MAAM,YAAY,CAAC;AAEpB,MAAM,CAAC,MAAM,kBAAkB,GAAG,UAAU,CAAC;IAC3C,IAAI,EAAE,wBAAwB;IAC9B,IAAI,EAAE,OAAO,CAAC,eAAe,CAAC,qCAAqC,C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