Skip to content

Conversation

lovisaberggren
Copy link
Collaborator

@lovisaberggren lovisaberggren commented Dec 9, 2024

Proposed changes

  • IPA 104 resource must have GET rule implementation
  • Rule test with Jest npm run test
  • Run IPA validation with npm run ipa-validation

Example output:

warning  xgen-IPA-104-resource-has-GET  APIs must provide a get method for resources. http://go/ipa/117  paths./api/atlas/v2/orgs/{orgId}/users/{userId}/roles

Jira ticket: CLOUDP-285964

Follow up

  • Run tests and IPA validation on PRs
  • Exceptions

@lovisaberggren lovisaberggren marked this pull request as ready for review December 16, 2024 10:36
@lovisaberggren lovisaberggren requested a review from a team as a code owner December 16, 2024 10:36
},
];
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: What if it is not a singleton and standard resource?(The equivalent of /custom in the tests). Don't we check for get method at all?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

For /custom in the tests, we do check these as well. It's basically a standard resource with extra custom methods, in these cases, we ignore the custom methods (since they can be post or get) and only check the children (/custom/{exampleId} in the tests)

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 we have no resources that fall into neither standard nor singleton (with the checks currently implemented)

import testRule from './__helpers__/testRule';
import { DiagnosticSeverity } from '@stoplight/types';

testRule('xgen-IPA-104-resource-has-GET', [
Copy link
Contributor

Choose a reason for hiding this comment

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

can you add a case with nested resource?
/groups/{groupId}/clusters? and a singleton like /groups/{groupId}/settings?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

Copy link
Contributor

Choose a reason for hiding this comment

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

can we unit test these, and if not can we add some examples to things like isSingletonResource or isStandardResource it's a bit hard to follow the intention of the method and some examples either in text or as actual tests would be of great help in the future if we need to debug or change those functions

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, makes sense, I'll add unit tests for them as well (getResourcePaths, isStandardResource and isSingletonResource as they are probably the tricky ones)

Comment on lines +61 to +64
const customChildMethodPattern = new RegExp(`^${parent}/{[a-zA-Z]+}:+[a-zA-Z]+$`);
const customMethodPattern = new RegExp(`^${parent}:+[a-zA-Z]+$`);
return allPaths.filter(
(p) => parent === p || childPathPattern.test(p) || customMethodPattern.test(p) || customChildMethodPattern.test(p)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The added tests revealed that we were missing a custom case, as it can be either /path/{id}:method or /path:method

Copy link
Contributor

@gssbzn gssbzn left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Collaborator

@yelizhenden-mdb yelizhenden-mdb left a comment

Choose a reason for hiding this comment

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

LGTM, exciting! 🚀

@lovisaberggren lovisaberggren merged commit 89b16b0 into main Dec 16, 2024
12 checks passed
@lovisaberggren lovisaberggren deleted the CLOUDP-285964 branch December 16, 2024 15:10
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