Skip to content

Commit beaa280

Browse files
CLOUDP-308270: Validation of parent and child paths with exceptions (PoC for root path exception inheritance)
1 parent 737b0d7 commit beaa280

File tree

2 files changed

+74
-3
lines changed

2 files changed

+74
-3
lines changed

openapi/.raw/v2.json

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53063,6 +53063,57 @@
5306353063
"x-xgen-IPA-exception": {
5306453064
"xgen-IPA-102-path-alternate-resource-name-path-param": "API predates IPA validation"
5306553065
}
53066+
},
53067+
"/api/atlas/v2/alertConfigs/matchers/fieldNames/{fieldId}": {
53068+
"get": {
53069+
"description": "Get all field names that the `matchers.fieldName` parameter accepts when you create or update an Alert Configuration. You can successfully call this endpoint with any assigned role.",
53070+
"operationId": "listAlertConfigurationMatchersFieldNames",
53071+
"parameters": [
53072+
{
53073+
"$ref": "#/components/parameters/envelope"
53074+
},
53075+
{
53076+
"$ref": "#/components/parameters/pretty"
53077+
}
53078+
],
53079+
"responses": {
53080+
"200": {
53081+
"content": {
53082+
"application/vnd.atlas.2023-01-01+json": {
53083+
"schema": {
53084+
"items": {
53085+
"$ref": "#/components/schemas/MatcherFieldView"
53086+
},
53087+
"type": "array",
53088+
"x-xgen-IPA-exception": {
53089+
"xgen-IPA-124-array-max-items": "Schema predates IPA validation"
53090+
}
53091+
},
53092+
"x-xgen-version": "2023-01-01"
53093+
}
53094+
},
53095+
"description": "OK"
53096+
},
53097+
"401": {
53098+
"$ref": "#/components/responses/unauthorized"
53099+
},
53100+
"403": {
53101+
"$ref": "#/components/responses/forbidden"
53102+
},
53103+
"404": {
53104+
"$ref": "#/components/responses/notFound"
53105+
},
53106+
"500": {
53107+
"$ref": "#/components/responses/internalServerError"
53108+
}
53109+
},
53110+
"summary": "Return All Alert Configuration Matchers Field Names",
53111+
"tags": [
53112+
"Alert Configurations"
53113+
],
53114+
"x-xgen-docs-url": "https://mongodb.com/docs/atlas/reference/api-resources-spec/v2/#tag/Alert-Configurations/operation/listAlertConfigurationMatchersFieldNames",
53115+
"x-xgen-owner-team": "CAP"
53116+
}
5306653117
},
5306753118
"/api/atlas/v2/clusters": {
5306853119
"get": {

tools/spectral/ipa/rulesets/functions/IPA102EachPathAlternatesBetweenResourceNameAndPathParam.js

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,25 @@ const validatePathStructure = (elements) => {
2828
});
2929
};
3030

31+
const findExceptionInPathHierarchy = (oas, currentPath, ruleName) => {
32+
// Check current path first
33+
if (hasException(oas.paths[currentPath], ruleName)) {
34+
return currentPath;
35+
}
36+
37+
// Check parent paths by removing segments from the end
38+
const pathSegments = currentPath.split('/').filter(segment => segment !== '');
39+
40+
for (let i = pathSegments.length - 1; i > 0; i--) {
41+
const parentPath = '/' + pathSegments.slice(0, i).join('/');
42+
if (oas.paths[parentPath] && hasException(oas.paths[parentPath], ruleName)) {
43+
return parentPath;
44+
}
45+
}
46+
47+
return null;
48+
}
49+
3150
export default (input, _, { path, documentInventory }) => {
3251
const oas = documentInventory.resolved;
3352

@@ -41,8 +60,9 @@ export default (input, _, { path, documentInventory }) => {
4160
return;
4261
}
4362

44-
if (hasException(oas.paths[input], RULE_NAME)) {
45-
collectException(oas.paths[input], RULE_NAME, path);
63+
const exceptionPath = findExceptionInPathHierarchy(oas, input, RULE_NAME);
64+
if (exceptionPath) {
65+
collectException(oas.paths[exceptionPath], RULE_NAME, path);
4666
return;
4767
}
4868

@@ -64,4 +84,4 @@ function checkViolationsAndReturnErrors(suffixWithLeadingSlash, path) {
6484
} catch (e) {
6585
handleInternalError(RULE_NAME, path, e);
6686
}
67-
}
87+
}

0 commit comments

Comments
 (0)