Skip to content

Conversation

@yelizhenden-mdb
Copy link
Collaborator

@yelizhenden-mdb yelizhenden-mdb commented Mar 26, 2025

Proposed changes

Jira ticket: CLOUDP-304954 and CLOUDP-304956

  xgen-IPA-110-collections-request-includeCount-not-required:
    description: |
      If the request supports an includeCount query parameter, it must not be required.

      ##### Implementation details
      Rule checks for the following conditions:
        - Only applies to List methods (GET on resource collection paths)
        - Checks if includeCount query parameter exists
        - If it exists, verifies the includeCount parameter is not required
    message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-110-collections-request-includeCount-not-required'
    severity: warn
    given: '$.paths[*].get'
    then:
      function: 'IPA110CollectionsRequestIncludeCountNotRequired'
  xgen-IPA-110-collections-response-define-links-array:
    description: |
      The response for collections should define a links array field, providing links to next and previous pages.

      ##### Implementation details
      Rule checks for the following conditions:
        - Only applies to List methods (GET operations that return collections of resources)
        - Verifies the response schema includes a links field of type array
    message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-110-collections-response-define-links-array'
    severity: warn
    given: '$.paths[*].get.responses.200.content'
    then:
      field: '@key'
      function: 'IPA110CollectionsResponseDefineLinksArray'

No violations found for xgen-IPA-110-collections-request-includeCount-not-required
11 violations found for xgen-IPA-110-collections-response-define-links-array (similar to ones that does not have results array in the response)

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 March 26, 2025 17:00
@yelizhenden-mdb yelizhenden-mdb requested a review from a team as a code owner March 26, 2025 17:00
Copy link
Member

@wtrocki wtrocki left a comment

Choose a reason for hiding this comment

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

LGTM. Glad to see those

Comment on lines 28 to 37
const parameters = input.parameters;
if (!parameters) {
return;
}

const includeCountParam = parameters.find((p) => p.name === 'includeCount' && p.in === 'query');

if (!includeCountParam) {
return;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

are we allowed to use moderm js?

Suggested change
const parameters = input.parameters;
if (!parameters) {
return;
}
const includeCountParam = parameters.find((p) => p.name === 'includeCount' && p.in === 'query');
if (!includeCountParam) {
return;
}
const includeCountParam = input?.parameters?.find((p) => p.name === 'includeCount' && p.in === 'query');
if (!includeCountParam) {
return;
}

Copy link
Member

@wtrocki wtrocki Mar 27, 2025

Choose a reason for hiding this comment

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

Yes. We run above >18. ? operator was introduced 6 years ago to Node 14.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Addressed 👍

return;
}

if (includeCountParam.required === true) {
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
if (includeCountParam.required === true) {
if (!!includeCountParam.required) {

Copy link
Member

Choose a reason for hiding this comment

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

We use eslint for such style enforcement.
IMHO we can enable this rule https://eslint.org/docs/latest/rules/no-extra-boolean-cast

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Added no-extra-boolean-cast to eslint config with enforceForLogicalOperands: true

It does not allow if(!!includeCountParam.required), because JS already coerces the includeCountParam.required to boolean in if. I replaced it with if(includeCountParam.required)

Comment on lines +17 to +18
!isResourceCollectionIdentifier(resourcePath) ||
(isResourceCollectionIdentifier(resourcePath) && isSingletonResource(getResourcePathItems(resourcePath, oas.paths)))
Copy link
Contributor

@gssbzn gssbzn Mar 27, 2025

Choose a reason for hiding this comment

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

isn't this the same as

!isResourceCollectionIdentifier(resourcePath) || isSingletonResource(getResourcePathItems(resourcePath, oas.paths)
!A || (A && B) = (!A || A) && (!A || B) 
(!A || A) && (!A || B) = true && (!A || B)
true && (!A || B) = !A || B

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, it is :D It is widely used, so I will share another PR to fix this

@yelizhenden-mdb yelizhenden-mdb mentioned this pull request Mar 27, 2025
3 tasks
@yelizhenden-mdb yelizhenden-mdb merged commit c8d48ad into main Mar 27, 2025
8 checks passed
@yelizhenden-mdb yelizhenden-mdb deleted the CLOUDP-304954 branch March 27, 2025 11:48
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