@azure-tools/typespec-azure-resource-manager 0.41.0-dev.3 → 0.41.0-dev.5
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 +1 -0
- package/dist/src/linter.d.ts.map +1 -1
- package/dist/src/linter.js +2 -0
- package/dist/src/linter.js.map +1 -1
- package/dist/src/rules/arm-delete-response-codes.d.ts.map +1 -1
- package/dist/src/rules/arm-delete-response-codes.js +1 -2
- package/dist/src/rules/arm-delete-response-codes.js.map +1 -1
- package/dist/src/rules/arm-post-response-codes.d.ts +8 -0
- package/dist/src/rules/arm-post-response-codes.d.ts.map +1 -0
- package/dist/src/rules/arm-post-response-codes.js +97 -0
- package/dist/src/rules/arm-post-response-codes.js.map +1 -0
- package/dist/src/rules/arm-put-response-codes.d.ts +7 -0
- package/dist/src/rules/arm-put-response-codes.d.ts.map +1 -0
- package/dist/src/rules/arm-put-response-codes.js +46 -0
- package/dist/src/rules/arm-put-response-codes.js.map +1 -0
- package/lib/arm.tsp +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -33,6 +33,7 @@ Available ruleSets:
|
|
|
33
33
|
| [`@azure-tools/typespec-azure-resource-manager/arm-no-record`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/no-record) | Don't use Record types for ARM resources. |
|
|
34
34
|
| `@azure-tools/typespec-azure-resource-manager/arm-common-types-version` | Specify the ARM common-types version using @armCommonTypesVersion. |
|
|
35
35
|
| [`@azure-tools/typespec-azure-resource-manager/arm-delete-operation-response-codes`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/delete-operation-response-codes) | Ensure delete operations have the appropriate status codes. |
|
|
36
|
+
| [`@azure-tools/typespec-azure-resource-manager/arm-put-operation-response-codes`](https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/put-operation-response-codes) | Ensure put operations have the appropriate status codes. |
|
|
36
37
|
| `@azure-tools/typespec-azure-resource-manager/arm-resource-action-no-segment` | `@armResourceAction` should not be used with `@segment`. |
|
|
37
38
|
| `@azure-tools/typespec-azure-resource-manager/arm-resource-duplicate-property` | Warn about duplicate properties in resources. |
|
|
38
39
|
| `@azure-tools/typespec-azure-resource-manager/arm-resource-invalid-envelope-property` | Check for invalid resource envelope properties. |
|
package/dist/src/linter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linter.d.ts","sourceRoot":"","sources":["../../src/linter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"linter.d.ts","sourceRoot":"","sources":["../../src/linter.ts"],"names":[],"mappings":"AA+DA,eAAO,MAAM,OAAO,+CAmBlB,CAAC"}
|
package/dist/src/linter.js
CHANGED
|
@@ -2,6 +2,7 @@ import { defineLinter } from "@typespec/compiler";
|
|
|
2
2
|
import { armCommonTypesVersionRule } from "./rules/arm-common-types-version.js";
|
|
3
3
|
import { armDeleteResponseCodesRule } from "./rules/arm-delete-response-codes.js";
|
|
4
4
|
import { armNoRecordRule } from "./rules/arm-no-record.js";
|
|
5
|
+
import { armPutResponseCodesRule } from "./rules/arm-put-response-codes.js";
|
|
5
6
|
import { armResourceActionNoSegmentRule } from "./rules/arm-resource-action-no-segment.js";
|
|
6
7
|
import { armResourceDuplicatePropertiesRule } from "./rules/arm-resource-duplicate-property.js";
|
|
7
8
|
import { interfacesRule } from "./rules/arm-resource-interfaces.js";
|
|
@@ -29,6 +30,7 @@ const rules = [
|
|
|
29
30
|
armNoRecordRule,
|
|
30
31
|
armCommonTypesVersionRule,
|
|
31
32
|
armDeleteResponseCodesRule,
|
|
33
|
+
armPutResponseCodesRule,
|
|
32
34
|
armResourceActionNoSegmentRule,
|
|
33
35
|
armResourceDuplicatePropertiesRule,
|
|
34
36
|
armResourceEnvelopeProperties,
|
package/dist/src/linter.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"linter.js","sourceRoot":"","sources":["../../src/linter.ts"],"names":[],"mapp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1
|
-
{"version":3,"file":"arm-delete-response-codes.d.ts","sourceRoot":"","sources":["../../../src/rules/arm-delete-response-codes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"arm-delete-response-codes.d.ts","sourceRoot":"","sources":["../../../src/rules/arm-delete-response-codes.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,eAAO,MAAM,0BAA0B;;;EAmCrC,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { createRule } from "@typespec/compiler";
|
|
2
2
|
import { getLroMetadata } from "@azure-tools/typespec-azure-core";
|
|
3
|
-
import { getHttpOperation } from "@typespec/http";
|
|
4
3
|
import { getArmResources } from "../resource.js";
|
|
5
4
|
/**
|
|
6
5
|
* Verify that a delete operation only
|
|
@@ -22,7 +21,7 @@ export const armDeleteResponseCodesRule = createRule({
|
|
|
22
21
|
if (armResource && armResource.operations.lifecycle.delete) {
|
|
23
22
|
const deleteOperation = armResource.operations.lifecycle.delete;
|
|
24
23
|
const isAsync = getLroMetadata(context.program, deleteOperation.operation) !== undefined;
|
|
25
|
-
const
|
|
24
|
+
const httpOp = deleteOperation.httpOperation;
|
|
26
25
|
const statusCodes = new Set([...httpOp.responses.map((r) => r.statusCodes.toString())]);
|
|
27
26
|
const expected = new Set(["204", "*"]);
|
|
28
27
|
expected.add(isAsync ? "202" : "200");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"arm-delete-response-codes.js","sourceRoot":"","sources":["../../../src/rules/arm-delete-response-codes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEvD,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"arm-delete-response-codes.js","sourceRoot":"","sources":["../../../src/rules/arm-delete-response-codes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEvD,O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AC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;oBAEtC,IACE,WAAW,CAAC,IAAI,KAAK,QAAQ,CAAC,IAAI;wBAClC,CAAC,CAAC,GAAG,WAAW,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAC/C,CAAC;wBACD,OAAO,CAAC,gBAAgB,CAAC;4BACvB,MAAM,EAAE,eAAe,CAAC,SAAS;4BACjC,SAAS,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM;yBACtC,CAAC,CAAC;oBACL,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verify that a post operation has the correct response codes.
|
|
3
|
+
*/
|
|
4
|
+
export declare const armPostResponseCodesRule: import("@typespec/compiler").LinterRuleDefinition<"arm-post-operation-response-codes", {
|
|
5
|
+
readonly sync: "Synchronous post operations must have a 200 or 204 response and a default response. They must not have any other responses.";
|
|
6
|
+
readonly async: "Long-running post operations must have 202 and default responses. They must also have a 200 response if the final response has a schema. They must not have any other responses.";
|
|
7
|
+
}>;
|
|
8
|
+
//# sourceMappingURL=arm-post-response-codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arm-post-response-codes.d.ts","sourceRoot":"","sources":["../../../src/rules/arm-post-response-codes.ts"],"names":[],"mappings":"AAOA;;GAEG;AACH,eAAO,MAAM,wBAAwB;;;EAkGnC,CAAC"}
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { createRule } from "@typespec/compiler";
|
|
2
|
+
import { getLroMetadata } from "@azure-tools/typespec-azure-core";
|
|
3
|
+
import { getArmResources } from "../resource.js";
|
|
4
|
+
/**
|
|
5
|
+
* Verify that a post operation has the correct response codes.
|
|
6
|
+
*/
|
|
7
|
+
export const armPostResponseCodesRule = createRule({
|
|
8
|
+
name: "arm-post-operation-response-codes",
|
|
9
|
+
severity: "warning",
|
|
10
|
+
url: "https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/post-operation-response-codes",
|
|
11
|
+
description: "Ensure post operations have the appropriate status codes.",
|
|
12
|
+
messages: {
|
|
13
|
+
sync: `Synchronous post operations must have a 200 or 204 response and a default response. They must not have any other responses.`,
|
|
14
|
+
async: `Long-running post operations must have 202 and default responses. They must also have a 200 response if the final response has a schema. They must not have any other responses.`,
|
|
15
|
+
},
|
|
16
|
+
create(context) {
|
|
17
|
+
function getResponseBody(response) {
|
|
18
|
+
if (response === undefined)
|
|
19
|
+
return undefined;
|
|
20
|
+
if (response.responses.length > 1) {
|
|
21
|
+
throw new Error("Multiple responses are not supported.");
|
|
22
|
+
}
|
|
23
|
+
if (response.responses[0].body !== undefined) {
|
|
24
|
+
return response.responses[0].body;
|
|
25
|
+
}
|
|
26
|
+
return undefined;
|
|
27
|
+
}
|
|
28
|
+
function validateAsyncPost(op) {
|
|
29
|
+
const statusCodes = new Set([
|
|
30
|
+
...op.httpOperation.responses.map((r) => r.statusCodes.toString()),
|
|
31
|
+
]);
|
|
32
|
+
// validate that there are 202 and * status codes, and maybe 200
|
|
33
|
+
const expected = statusCodes.size === 2 ? new Set(["202", "*"]) : new Set(["202", "200", "*"]);
|
|
34
|
+
if (statusCodes.size !== expected.size || ![...statusCodes].every((v) => expected.has(v))) {
|
|
35
|
+
context.reportDiagnostic({
|
|
36
|
+
target: op.operation,
|
|
37
|
+
messageId: "async",
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
// validate that 202 does not have a schema
|
|
41
|
+
const response202 = op.httpOperation.responses.find((r) => r.statusCodes === 202);
|
|
42
|
+
const body202 = getResponseBody(response202);
|
|
43
|
+
if (body202 !== undefined) {
|
|
44
|
+
context.reportDiagnostic({
|
|
45
|
+
target: op.operation.returnType,
|
|
46
|
+
messageId: "async",
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
// validate that a 200 response does have a schema
|
|
50
|
+
const response200 = op.httpOperation.responses.find((r) => r.statusCodes === 200);
|
|
51
|
+
const body200 = getResponseBody(response200);
|
|
52
|
+
if (response200 && body200 === undefined) {
|
|
53
|
+
context.reportDiagnostic({
|
|
54
|
+
target: op.operation.returnType,
|
|
55
|
+
messageId: "async",
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function validateSyncPost(op) {
|
|
60
|
+
const allowed = [new Set(["200", "*"]), new Set(["204", "*"])];
|
|
61
|
+
const statusCodes = new Set([
|
|
62
|
+
...op.httpOperation.responses.map((r) => r.statusCodes.toString()),
|
|
63
|
+
]);
|
|
64
|
+
if (!allowed.some((expected) => statusCodes.size === expected.size && [...statusCodes].every((v) => expected.has(v)))) {
|
|
65
|
+
context.reportDiagnostic({
|
|
66
|
+
target: op.operation,
|
|
67
|
+
messageId: "sync",
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
return {
|
|
72
|
+
root: (program) => {
|
|
73
|
+
const resources = getArmResources(program);
|
|
74
|
+
for (const resource of resources) {
|
|
75
|
+
const operations = [
|
|
76
|
+
resource.operations.lifecycle.createOrUpdate,
|
|
77
|
+
resource.operations.lifecycle.update,
|
|
78
|
+
...Object.values(resource.operations.actions),
|
|
79
|
+
];
|
|
80
|
+
for (const op of operations) {
|
|
81
|
+
if (op === undefined || op.httpOperation.verb !== "post") {
|
|
82
|
+
continue;
|
|
83
|
+
}
|
|
84
|
+
const isAsync = getLroMetadata(context.program, op.operation) !== undefined;
|
|
85
|
+
if (isAsync) {
|
|
86
|
+
validateAsyncPost(op);
|
|
87
|
+
}
|
|
88
|
+
else {
|
|
89
|
+
validateSyncPost(op);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
};
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
//# sourceMappingURL=arm-post-response-codes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arm-post-response-codes.js","sourceRoot":"","sources":["../../../src/rules/arm-post-response-codes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAGlE,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;GAEG;AACH,MAAM,CAAC,MAAM,wBAAwB,GAAG,UAAU,CAAC;IACjD,IAAI,EAAE,mCAAmC;IACzC,QAAQ,EAAE,SAAS;IACnB,GAAG,EAAE,kHAAkH;IACvH,WAAW,EAAE,2DAA2D;IACxE,QAAQ,EAAE;QACR,IAAI,EAAE,6HAA6H;QACnI,KAAK,EAAE,kLAAkL;KAC1L;IACD,MAAM,CAAC,OAAO;QACZ,SAAS,eAAe,CACtB,QAA2C;YAE3C,IAAI,QAAQ,KAAK,SAAS;gBAAE,OAAO,SAAS,CAAC;YAC7C,IAAI,QAAQ,CAAC,SAAS,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;gBAClC,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;YAC3D,CAAC;YACD,IAAI,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,KAAK,SAAS,EAAE,CAAC;gBAC7C,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;YACpC,CAAC;YACD,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,SAAS,iBAAiB,CAAC,EAAwB;YACjD,MAAM,WAAW,GAAG,IAAI,GAAG,CAAC;gBAC1B,GAAG,EAAE,CAAC,aAAa,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC;aACnE,CAAC,CAA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AC,QAAQ,CAAC,UAAU,CAAC,OAAO,CAAC;qBAC9C,CAAC;oBACF,KAAK,MAAM,EAAE,IAAI,UAAU,EAAE,CAAC;wBAC5B,IAAI,EAAE,KAAK,SAAS,IAAI,EAAE,CAAC,aAAa,CAAC,IAAI,KAAK,MAAM,EAAE,CAAC;4BACzD,SAAS;wBACX,CAAC;wBACD,MAAM,OAAO,GAAG,cAAc,CAAC,OAAO,CAAC,OAAO,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,SAAS,CAAC;wBAC5E,IAAI,OAAO,EAAE,CAAC;4BACZ,iBAAiB,CAAC,EAAE,CAAC,CAAC;wBACxB,CAAC;6BAAM,CAAC;4BACN,gBAAgB,CAAC,EAAE,CAAC,CAAC;wBACvB,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Verify that a put operation has the correct response codes.
|
|
3
|
+
*/
|
|
4
|
+
export declare const armPutResponseCodesRule: import("@typespec/compiler").LinterRuleDefinition<"arm-put-operation-response-codes", {
|
|
5
|
+
readonly default: "Put operations must have 200, 201 and default responses. They must not have any other responses.";
|
|
6
|
+
}>;
|
|
7
|
+
//# sourceMappingURL=arm-put-response-codes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arm-put-response-codes.d.ts","sourceRoot":"","sources":["../../../src/rules/arm-put-response-codes.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,eAAO,MAAM,uBAAuB;;EAyClC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { createRule } from "@typespec/compiler";
|
|
2
|
+
import { getArmResources } from "../resource.js";
|
|
3
|
+
/**
|
|
4
|
+
* Verify that a put operation has the correct response codes.
|
|
5
|
+
*/
|
|
6
|
+
export const armPutResponseCodesRule = createRule({
|
|
7
|
+
name: "arm-put-operation-response-codes",
|
|
8
|
+
severity: "warning",
|
|
9
|
+
url: "https://azure.github.io/typespec-azure/docs/libraries/azure-resource-manager/rules/put-operation-response-codes",
|
|
10
|
+
description: "Ensure put operations have the appropriate status codes.",
|
|
11
|
+
messages: {
|
|
12
|
+
default: `Put operations must have 200, 201 and default responses. They must not have any other responses.`,
|
|
13
|
+
},
|
|
14
|
+
create(context) {
|
|
15
|
+
return {
|
|
16
|
+
root: (program) => {
|
|
17
|
+
const resources = getArmResources(program);
|
|
18
|
+
const expected = new Set(["200", "201", "*"]);
|
|
19
|
+
for (const resource of resources) {
|
|
20
|
+
const operations = [
|
|
21
|
+
resource.operations.lifecycle.createOrUpdate,
|
|
22
|
+
resource.operations.lifecycle.update,
|
|
23
|
+
...Object.values(resource.operations.actions),
|
|
24
|
+
];
|
|
25
|
+
for (const op of operations) {
|
|
26
|
+
if (op === undefined) {
|
|
27
|
+
continue;
|
|
28
|
+
}
|
|
29
|
+
if (op.httpOperation.verb === "put") {
|
|
30
|
+
const statusCodes = new Set([
|
|
31
|
+
...op.httpOperation.responses.map((r) => r.statusCodes.toString()),
|
|
32
|
+
]);
|
|
33
|
+
if (statusCodes.size !== expected.size ||
|
|
34
|
+
![...statusCodes].every((v) => expected.has(v))) {
|
|
35
|
+
context.reportDiagnostic({
|
|
36
|
+
target: op.operation,
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
},
|
|
45
|
+
});
|
|
46
|
+
//# sourceMappingURL=arm-put-response-codes.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arm-put-response-codes.js","sourceRoot":"","sources":["../../../src/rules/arm-put-response-codes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAEzD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD;;GAEG;AACH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CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAC/C,CAAC;gCACD,OAAO,CAAC,gBAAgB,CAAC;oCACvB,MAAM,EAAE,EAAE,CAAC,SAAS;iCACrB,CAAC,CAAC;4BACL,CAAC;wBACH,CAAC;oBACH,CAAC;gBACH,CAAC;YACH,CAAC;SACF,CAAC;IACJ,CAAC;CACF,CAAC,CAAC"}
|
package/lib/arm.tsp
CHANGED
|
@@ -34,6 +34,6 @@ namespace Azure.ResourceManager;
|
|
|
34
34
|
@doc("Supported versions of Azure.ResourceManager building blocks.")
|
|
35
35
|
enum Versions {
|
|
36
36
|
@doc("Version 1.0-preview.1")
|
|
37
|
-
@useDependency(Azure.Core.Versions.
|
|
37
|
+
@useDependency(Azure.Core.Versions.v1_0_Preview_2)
|
|
38
38
|
v1_0_Preview_1: "1.0-preview.1",
|
|
39
39
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@azure-tools/typespec-azure-resource-manager",
|
|
3
|
-
"version": "0.41.0-dev.
|
|
3
|
+
"version": "0.41.0-dev.5",
|
|
4
4
|
"author": "Microsoft Corporation",
|
|
5
5
|
"description": "TypeSpec Azure Resource Manager library",
|
|
6
6
|
"homepage": "https://azure.github.io/typespec-azure",
|