Skip to content

Commit d9f267d

Browse files
authored
merging the relevant checks from DeleteOperationAsyncResponseValidation into delete-response-codes and removing DeleteOperationAsyncResponseValidation (Azure#535)
* merging the relevant checks from DeleteOperationAsyncResponseValidation into delete-response-codes and removing DeleteOperationAsyncResponseValidation. Removing the status code checks from long-running-response-status-code
1 parent 7a2c09c commit d9f267d

15 files changed

+265
-994
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"changes": [
3+
{
4+
"packageName": "@microsoft.azure/openapi-validator-rulesets",
5+
"comment": "merging linter rules DeleteOperationAsyncResponseValidation and delete-response-codes and removing the checks from long-running-response-status-code as they have conflicting implementations",
6+
"type": "patch"
7+
}
8+
],
9+
"packageName": "@microsoft.azure/openapi-validator-rulesets"
10+
}

docs/delete-operation-async-response-validation.md

Lines changed: 0 additions & 65 deletions
This file was deleted.

docs/long-running-response-status-code-data-plane.md

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,14 @@ SDK Error
66

77
## Applies to
88

9-
ARM and Data plane OpenAPI(swagger) specs
10-
11-
## Related ARM Guideline Code
12-
13-
- RPC-Async-V1-01
9+
Data plane OpenAPI(swagger) specs
1410

1511
## Output Message
1612

1713
A '{0}' operation '{1}' with x-ms-long-running-operation extension must have a valid terminal success status code {2}.
1814

1915
## Description
2016

21-
For ARM spec, the allowed response status codes for a long DELETE operation are "200" & "204"; the allowed response status codes for a POST operation are "200", "201" ,"202", & "204"; the allowed response status codes for a PUT/PATCH operation are "200" & "201".
2217
For Data plane spec, the allowed response status codes for a long DELETE operation are "200","202", & "204"; the allowed response status codes for a POST operation are "200", "201" ,"202", & "204"; the allowed response status codes for a PUT/PATCH operation are "200","201", & "202".
2318

2419
## Why the rule is important

docs/long-running-response-status-code.md

Lines changed: 0 additions & 30 deletions
This file was deleted.

docs/rules.md

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -220,12 +220,6 @@ The request body of a delete operation must be empty.
220220

221221
Please refer to [delete-must-not-have-request-body.md](./delete-must-not-have-request-body.md) for details.
222222

223-
### DeleteOperationAsyncResponseValidation
224-
225-
An async DELETE operation response include status code 202 with 'Location' header. Must support status code 200 if operation can be completed synchronously. Must support 204 (resource doesn't exists). Operation must also add "x-ms-long-running-operation and x-ms-long-running-operation-options" to mark that it is a long running operation (in case of 202) and how it is tracked (Location header).
226-
227-
Please refer to [delete-operation-async-response-validation.md](./delete-operation-async-response-validation.md) for details.
228-
229223
### DeleteOperationResponses
230224

231225
Per ARM Specs, all DELETE methods (non-async) must have responses code implementation: 200, 204.
@@ -450,18 +444,10 @@ Please refer to [long-running-operations-with-long-running-extension.md](./long-
450444

451445
### LongRunningResponseStatusCode
452446

453-
For ARM spec, the allowed response status codes for a long DELETE operation are "200" & "204"; the allowed response status codes for a POST operation are "200", "201" ,"202", & "204"; the allowed response status codes for a PUT/PATCH operation are "200" & "201".
454447
For Data plane spec, the allowed response status codes for a long DELETE operation are "200","202", & "204"; the allowed response status codes for a POST operation are "200", "201" ,"202", & "204"; the allowed response status codes for a PUT/PATCH operation are "200","201", & "202".
455448

456449
Please refer to [long-running-response-status-code-data-plane.md](./long-running-response-status-code-data-plane.md) for details.
457450

458-
### LongRunningResponseStatusCode
459-
460-
For ARM spec, the allowed response status codes for a long DELETE operation are "200" & "204"; the allowed response status codes for a POST operation are "200", "201" ,"202", & "204"; the allowed response status codes for a PUT/PATCH operation are "200" & "201".
461-
For Data plane spec, the allowed response status codes for a long DELETE operation are "200","202", & "204"; the allowed response status codes for a POST operation are "200", "201" ,"202", & "204"; the allowed response status codes for a PUT/PATCH operation are "200","201", & "202".
462-
463-
Please refer to [long-running-response-status-code.md](./long-running-response-status-code.md) for details.
464-
465451
### LroErrorContent
466452

467453
Error response content of long running operations must follow the error schema provided in the common types v2 and above.

packages/rulesets/generated/spectral/az-arm.js

Lines changed: 21 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1464,20 +1464,35 @@ const consistentPatchProperties = (patchOp, _opts, ctx) => {
14641464

14651465
const SYNC_DELETE_RESPONSES = ["200", "204", "default"];
14661466
const LR_DELETE_RESPONSES = ["202", "204", "default"];
1467-
const SYNC_ERROR = "Synchronous delete operations must have responses with 200, 204, and default return codes. They also must have no other response codes.";
1468-
const LR_ERROR = "Long-running (LRO) delete operations must have responses with 202, 204, and default return codes. They also must have no other response codes.";
1467+
const SYNC_ERROR = "Synchronous delete operations must have responses with 200, 204 and default return codes. They also must have no other response codes.";
1468+
const LR_ERROR = "Long-running delete operations must have responses with 202, 204 and default return codes. They also must have no other response codes.";
1469+
const EmptyResponse_ERROR = "Delete operation response codes must be non-empty. It must have response codes 200, 204 and default if it is sync or 202, 204 and default if it is long running.";
14691470
const DeleteResponseCodes = (deleteOp, _opts, ctx) => {
14701471
var _a;
14711472
if (deleteOp === null || typeof deleteOp !== "object") {
14721473
return [];
14731474
}
14741475
const path = ctx.path;
14751476
const errors = [];
1476-
if (!(deleteOp === null || deleteOp === void 0 ? void 0 : deleteOp.responses)) {
1477-
return [];
1478-
}
14791477
const responses = Object.keys((_a = deleteOp === null || deleteOp === void 0 ? void 0 : deleteOp.responses) !== null && _a !== void 0 ? _a : {});
1480-
if (deleteOp["x-ms-long-running-operation"] === true) {
1478+
if (responses.length == 0) {
1479+
errors.push({
1480+
message: EmptyResponse_ERROR,
1481+
path: path,
1482+
});
1483+
return errors;
1484+
}
1485+
const isAsyncOperation = deleteOp.responses["202"] ||
1486+
(deleteOp["x-ms-long-running-operation"] && deleteOp["x-ms-long-running-operation"] === true) ||
1487+
deleteOp["x-ms-long-running-operation-options"];
1488+
if (isAsyncOperation) {
1489+
if (!deleteOp["x-ms-long-running-operation"]) {
1490+
errors.push({
1491+
message: "An async DELETE operation must set '\"x-ms-long-running-operation\" : true'.",
1492+
path: path,
1493+
});
1494+
return errors;
1495+
}
14811496
if (responses.length !== LR_DELETE_RESPONSES.length || !LR_DELETE_RESPONSES.every((value) => responses.includes(value))) {
14821497
errors.push({
14831498
message: LR_ERROR,
@@ -1496,45 +1511,6 @@ const DeleteResponseCodes = (deleteOp, _opts, ctx) => {
14961511
return errors;
14971512
};
14981513

1499-
const longRunningResponseStatusCode = (methodOp, _opts, ctx, validResponseCodesList) => {
1500-
var _a, _b, _c, _d;
1501-
if (methodOp === null || typeof methodOp !== "object") {
1502-
return [];
1503-
}
1504-
const path = ctx.path || [];
1505-
const errors = [];
1506-
const method = Object.keys(methodOp)[0];
1507-
if (!["delete", "put", "patch", "post"].includes(method)) {
1508-
return [];
1509-
}
1510-
const operationId = ((_a = methodOp === null || methodOp === void 0 ? void 0 : methodOp[method]) === null || _a === void 0 ? void 0 : _a.operationId) || "";
1511-
if (!((_b = methodOp === null || methodOp === void 0 ? void 0 : methodOp[method]) === null || _b === void 0 ? void 0 : _b["x-ms-long-running-operation"])) {
1512-
return [];
1513-
}
1514-
if ((_c = methodOp === null || methodOp === void 0 ? void 0 : methodOp[method]) === null || _c === void 0 ? void 0 : _c.responses) {
1515-
const responseCodes = Object.keys((_d = methodOp === null || methodOp === void 0 ? void 0 : methodOp[method]) === null || _d === void 0 ? void 0 : _d.responses);
1516-
const validResponseCodes = validResponseCodesList[method];
1517-
const validResponseCodeString = validResponseCodes.join(" or ");
1518-
const withTerminalCode = validResponseCodes.some((code) => responseCodes.includes(code));
1519-
if (!withTerminalCode) {
1520-
errors.push({
1521-
message: `A '${method}' operation '${operationId}' with x-ms-long-running-operation extension must have a valid terminal success status code ${validResponseCodeString}.`,
1522-
path: [...path, method],
1523-
});
1524-
}
1525-
}
1526-
return errors;
1527-
};
1528-
const longRunningResponseStatusCodeArm = (methodOp, _opts, ctx) => {
1529-
const validResponseCodesList = {
1530-
delete: ["200", "204"],
1531-
post: ["200", "201", "202", "204"],
1532-
put: ["200", "201"],
1533-
patch: ["200", "201", "202"],
1534-
};
1535-
return longRunningResponseStatusCode(methodOp, _opts, ctx, validResponseCodesList);
1536-
};
1537-
15381514
const getCollectionOnlyHasValueAndNextLink = (properties, _opts, ctx) => {
15391515
if (!properties || typeof properties !== "object") {
15401516
return [];
@@ -2598,17 +2574,6 @@ const ruleset = {
25982574
},
25992575
},
26002576
},
2601-
LongRunningResponseStatusCode: {
2602-
description: 'A LRO Post operation with return schema must have "x-ms-long-running-operation-options" extension enabled.',
2603-
message: "{{error}}",
2604-
severity: "error",
2605-
resolved: true,
2606-
formats: [oas2],
2607-
given: ["$[paths,'x-ms-paths'].*.*[?(@property === 'x-ms-long-running-operation' && @ === true)]^^"],
2608-
then: {
2609-
function: longRunningResponseStatusCodeArm,
2610-
},
2611-
},
26122577
ProvisioningStateSpecifiedForLROPut: {
26132578
description: 'A LRO PUT operation\'s response schema must have "ProvisioningState" property specified for the 200 and 201 status codes.',
26142579
message: "{{error}}",

packages/rulesets/src/native/legacyRules/DeleteOperationAsyncResponseValidation.ts

Lines changed: 0 additions & 64 deletions
This file was deleted.

packages/rulesets/src/native/rulesets/common.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ require("../legacyRules/NestedResourcesMustHaveListOperation")
2828
require("../legacyRules/TopLevelResourcesListByResourceGroup")
2929
require("../legacyRules/TopLevelResourcesListBySubscription")
3030
require("../legacyRules/CreateOperationAsyncResponseValidation")
31-
require("../legacyRules/DeleteOperationAsyncResponseValidation")
3231
require("../legacyRules/PostOperationAsyncResponseValidation")
3332
require("../legacyRules/Rpaas_ResourceProvisioningState")
3433
require("../legacyRules/PreviewVersionOverOneYear")

0 commit comments

Comments
 (0)