Skip to content

Conversation

@yelizhenden-mdb
Copy link
Collaborator

@yelizhenden-mdb yelizhenden-mdb commented Apr 3, 2025

Proposed changes

Jira ticket: CLOUDP-306579

  xgen-IPA-124-array-max-items:
    description: |
      Array fields must have a maxItems property defined to enforce an upper bound on the number of items (default: 100).

      ##### Implementation details
      Rule checks for the following conditions:

        - All schema objects with type 'array' must have a maxItems property
        - The maxItems value must be set below the threshold of 100

      ##### Function options
              - maxItems: Required integer parameter specifying the maximum allowed array size (default: 100)
              - ignore: Required array parameter listing property names to be exempted from validation

Found 426 violations to fix.
Planned fix: No exceptions, but adding maxItems for the violating array fields

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

- Validates that each enum array has 20 or fewer values
- Reusable enum schemas will be ignored
- Skips validation if the schema has an exception defined for this rule
- This validation threshold can be adjusted by changing the functionOptions.maxEnumValues parameter
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: drive-by fix

@yelizhenden-mdb yelizhenden-mdb marked this pull request as ready for review April 3, 2025 16:19
@yelizhenden-mdb yelizhenden-mdb requested a review from a team as a code owner April 3, 2025 16:19
rules:
xgen-IPA-124-array-max-items:
description: |
Array fields must have a maxItems property defined to enforce an upper bound on the number of items (default: 100).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Array fields must have a maxItems property defined to enforce an upper bound on the number of items (default: 100).
Array fields must have a maxItems property defined to enforce an upper bound on the number of items (recommended max: 100). If repeated data has the chance of being too large, the API should use a sub-resource instead.

[Nit] Include guidance on option instead of very large array

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I changed repeated data with array field to be consistent, and kept the rest. Let me know how it looks 👍


testRule('xgen-IPA-124-array-max-items', [
{
name: 'valid array with maxItems set to 100',
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 also add a case with valid maxItems: <value lower than 100>?

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, let me know how it looks 👍

Comment on lines 121 to 131
properties: {
outerArray: {
type: 'array',
maxItems: 100,
arrayProperty: {
type: 'array',
maxItems: 101,
items: {
type: 'string',
},
},
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 add a case where both the outer and nested array has a too large value?

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, let me know how it looks 👍

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.

TY!

rules:
xgen-IPA-124-array-max-items:
description: |
Array fields must have a maxItems property defined to enforce an upper bound on the number of items (recommended max: 100). If the array field has the chance of being too large, the API should use a sub-resource instead..
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
Array fields must have a maxItems property defined to enforce an upper bound on the number of items (recommended max: 100). If the array field has the chance of being too large, the API should use a sub-resource instead..
Array fields must have a maxItems property defined to enforce an upper bound on the number of items (recommended max: 100). If the array field has the chance of being too large, the API should use a sub-resource instead.

@yelizhenden-mdb yelizhenden-mdb merged commit 8ab779c into main Apr 4, 2025
7 of 8 checks passed
@yelizhenden-mdb yelizhenden-mdb deleted the CLOUDP-306579 branch April 4, 2025 09:47
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