Skip to content

Conversation

yelizhenden-mdb
Copy link
Collaborator

@yelizhenden-mdb yelizhenden-mdb commented Dec 17, 2024

Proposed changes

Jira ticket: CLOUDP-271988

Implements a rule under IPA-102, which checks if the paths are alternating between resource name and path param.
Assumptions:

  1. All the paths are starting with api/atlas/v2 or /api/atlas/v2/unauth prefixes
  2. api/atlas/v2 or /api/atlas/v2/unauth by themselves are valid paths
  3. pathParam is in the format of {[a-z][a-zA-Z0-9]*} or {[a-z][a-zA-Z0-9]*}:[a-z][a-zA-Z0-9]* if custom methods attached
  4. All the paths remaining after prefixes start with resourceName and alternates with pathParam
  5. This rule does not check the validity of pathParam or resourceName for the cases such as camelCase or plurality

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 marked this pull request as ready for review December 17, 2024 14:49
@yelizhenden-mdb yelizhenden-mdb requested a review from a team as a code owner December 17, 2024 14:49
description: "APIs must provide a get method for resources. http://go/ipa/104"
message: "{{error}} http://go/ipa/117"
description: 'APIs must provide a get method for resources. http://go/ipa/104'
message: '{{error}} http://go/ipa/104'
Copy link
Collaborator

Choose a reason for hiding this comment

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

❤️

const validatePathStructure = (elements) => {
return elements.every((element, index) => {
const isEvenIndex = index % 2 === 0;
return isEvenIndex ? !isPathParam(element) : isPathParam(element);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return isEvenIndex ? !isPathParam(element) : isPathParam(element);
return isEvenIndex && !isPathParam(element);

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

When the index is odd, it will return false this way. Am I missing anything?

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.

Thanks!

@yelizhenden-mdb yelizhenden-mdb merged commit 1c2fa35 into main Dec 17, 2024
13 checks passed
@yelizhenden-mdb yelizhenden-mdb deleted the CLOUDP-271988 branch December 17, 2024 16:51
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