Skip to content

Conversation

lovisaberggren
Copy link
Collaborator

@lovisaberggren lovisaberggren commented Dec 18, 2024

Proposed changes

Adds ability to ignore API components with IPA exception extensions to existing IPA rules:

  • xgen-IPA-104-resource-has-GET
  • xgen-IPA-102-path-alternate-resource-name-path-param

Also added a IPA rule validation xgen-IPA-005-exception-extension-format to check the format of any x-xgen-IPA-exception extensions. This rule does not accept exceptions, and should not.

Jira ticket: CLOUDP-288860

Testing

  • Added tests for existing rules to validate that the component is ignored when an x-xgen-IPA-exception extension is present with the corresponding rule name
  • Added tests for the new xgen-IPA-005-exception-extension-format rule to validate that it catches invalid exception extensions
  • Unit test for hasException helper function

Comment on lines +137 to +157
{
name: 'invalid paths with exceptions',
document: {
paths: {
'/api/atlas/v2/unauth/resourceName1/resourceName2': {
'x-xgen-IPA-exception': {
'xgen-IPA-102-path-alternate-resource-name-path-param': {
reason: 'test',
},
},
},
'/api/atlas/v2/resourceName/{pathParam1}/{pathParam2}': {
'x-xgen-IPA-exception': {
'xgen-IPA-102-path-alternate-resource-name-path-param': {
reason: 'test',
},
},
},
},
},
errors: [],
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Expect no errors when component has exception

Comment on lines +128 to +148
{
name: 'invalid method with exception',
document: {
paths: {
'/standard': {
post: {},
get: {},
'x-xgen-IPA-exception': {
'xgen-IPA-104-resource-has-GET': {
reason: 'test',
},
},
},
'/standard/{exampleId}': {
patch: {},
delete: {},
},
},
},
errors: [],
},
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Expect no errors when component has exception

@lovisaberggren lovisaberggren marked this pull request as ready for review December 18, 2024 16:00
@lovisaberggren lovisaberggren requested a review from a team as a code owner December 18, 2024 16:00
* @param ruleName the name of the exempted rule
* @returns {boolean} true if the object has an exception named ruleName, otherwise false
*/
export function hasException(object, ruleName) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: Do we accept if the exception is not in the correct format?
Because the exception format will be evaluated within the scope of another rule, and it will not affect the acceptance of the rule exception. WDYT?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I decided not to check the format here since we have a rule that covers it already, so here we assume the extension has keys with the rule names

function isValidException(ruleName, exception) {
const exceptionObjectKeys = Object.keys(exception);
return (
ruleName.startsWith(RULE_NAME_PREFIX) &&
Copy link
Collaborator

Choose a reason for hiding this comment

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

Q: Should we check if the ruleName is among the rules defined?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I was thinking about it but couldn't figure out how to do it without having to introduce a list of some sorts with the rules names, that would be manually updated any time there are new rules, I'll have a think if we can achieve this in some way

Copy link
Collaborator

@yelizhenden-mdb yelizhenden-mdb Dec 18, 2024

Choose a reason for hiding this comment

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

Yes, I think you would need another helper function which loads ipa-spectral.yaml to a Spectral object and fetch the rule names from there

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think it is fine by now, it can be an improvement for later

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Cool, I can create a ticket for consideration as a nice to have later

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 🚀

@lovisaberggren lovisaberggren merged commit c29cfec into main Dec 18, 2024
13 checks passed
@lovisaberggren lovisaberggren deleted the CLOUDP-288860 branch December 18, 2024 17:02
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.

2 participants