Skip to content

Conversation

yelizhenden-mdb
Copy link
Collaborator

Proposed changes

If an exception is defined for a parent path identifier, all child paths inherit it—no need to add separate exceptions.
The validation rules for path identifier formats have been updated accordingly.

Jira ticket: CLOUDP-308270

Checklist

  • I have signed the MongoDB CLA
  • I have added tests that prove my fix is effective or that my feature works

Changes to Spectral

  • I have read the README file for Spectral Updates

Further comments

@yelizhenden-mdb yelizhenden-mdb changed the title feat(ipa):child path identifiers inherit parent path exceptions feat(ipa): child path identifiers inherit parent path exceptions Aug 15, 2025
@yelizhenden-mdb yelizhenden-mdb marked this pull request as ready for review August 15, 2025 11:21
@yelizhenden-mdb yelizhenden-mdb requested a review from a team as a code owner August 15, 2025 11:21
@yelizhenden-mdb yelizhenden-mdb changed the title feat(ipa): child path identifiers inherit parent path exceptions fix(ipa): child path identifiers inherit parent path exceptions Aug 15, 2025
Comment on lines 33 to 42
// Check parent paths by removing segments from the end
const pathSegments = currentPath.split('/').filter((segment) => segment !== '');

for (let i = pathSegments.length - 1; i > 0; i--) {
const parentPath = '/' + pathSegments.slice(0, i).join('/');
if (oas.paths[parentPath] && hasException(oas.paths[parentPath], ruleName)) {
return parentPath;
}
}

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this mean that if atlas/api/v2.0/groups/{groupId}/cluster/{clusterName} has an exception also that exception is applied to atlas/api/v2.0/groups/{groupId}/?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it is the opposite, if atlas/api/v2.0/groups/{groupId}/ has an exception for the rule, atlas/api/v2.0/groups/{groupId}/cluster/{clusterName} will inherit it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the clarifications. Why do we want to add this functionality? atlas/api/v2.0/groups/{groupId} and atlas/api/v2.0/groups/{groupId}/cluster/{clusterName} are two separated resources

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Currently, when API producers define new API endpoints using Swagger annotations in Java, they specify only the child path segment to append to a parent path. They are not responsible for, nor can they modify, the parent path itself and exceptions on it.

This way, any new method extending the parent path does not require separate exceptions. API producers won’t need to add exceptions each time, though we will still collect metrics as if the child paths had defined exceptions

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's say that atlas/api/v2.0/groups/{groupId}/ has an exception to xgen-IPA-104-resource-has-GET which means that the GET method is missing. Why should we applied this exception to all the child resources?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only implemented for IPA-102 guidelines, which is covering the path formatting. It does not apply to other principles

Comment on lines 29 to 31
if (hasException(oas.paths[currentPath], ruleName)) {
return currentPath;
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we return a spectral error if the current path has an exception as well as the parent? So we can identify the unnecessary ones?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Added. Could you double-check?

const violations = checkViolations(pathKey, path, ignoredValues);

return evaluateAndCollectAdoptionStatus(violations, RULE_NAME, oas.paths[input], path);
// Check for exceptions in path hierarchy
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update the rule descriptions for these to clarify the exception behaviour?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rule documentation updated 👍

* Evaluates and collects adoptions, exceptions and violations based on the rule, evaluated object and the validation errors.
* If the object is violating the rule, but has an exception, the validation error is ignored
* If the object is adopting the rule, but has an exception, a validation error will be returned
* If the object is adopting the rule, but has an exception, an unnecessary exception error is returned, but the object is counted as adopting the rule
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: Behavior change. IMHO we don't need to collect "unnecessary exceptions" as violations.
Let me know if you have strong opinions

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, makes sense. Thanks!

Copy link
Collaborator

@lovisaberggren lovisaberggren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, I see some test failures - let me know when the errors are resolved and I can re-stamp 👍

@yelizhenden-mdb yelizhenden-mdb merged commit 75f3934 into main Aug 15, 2025
11 checks passed
@yelizhenden-mdb yelizhenden-mdb deleted the CLOUDP-308270 branch August 15, 2025 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants