Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions tools/spectral/ipa/rulesets/IPA-124.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@ functions:
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.
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.
##### 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
- All schema objects with type 'array' must have a `maxItems` property
- The `maxItems` value must be lower than or equal to 100
##### Function options
- maxItems: Required integer parameter specifying the maximum allowed array size (default: 100)
- maxAllowedValue: Required integer parameter specifying the maximum allowed value for the `maxItems` property (100)
- ignore: Required array parameter listing property names to be exempted from validation
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-124-array-max-items'
severity: error
Expand All @@ -25,7 +25,7 @@ rules:
then:
function: IPA124ArrayMaxItems
functionOptions:
maxItems: 100
maxAllowedValue: 100
ignore:
- links
- results
Expand Down
8 changes: 4 additions & 4 deletions tools/spectral/ipa/rulesets/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -852,16 +852,16 @@ Rules are based on [http://go/ipa/IPA-124](http://go/ipa/IPA-124).
#### xgen-IPA-124-array-max-items

![error](https://img.shields.io/badge/error-red)
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.

##### 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
- All schema objects with type 'array' must have a `maxItems` property
- The `maxItems` value must be lower than or equal to 100

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


Expand Down
10 changes: 5 additions & 5 deletions tools/spectral/ipa/rulesets/functions/IPA124ArrayMaxItems.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const RULE_NAME = 'xgen-IPA-124-array-max-items';
* @param {object} options - Rule configuration options
* @param {object} context - The context object containing the path and documentInventory
*/
export default (input, { maxItems, ignore = [] }, { path }) => {
export default (input, { maxAllowedValue, ignore = [] }, { path }) => {
// Check for exception at the schema level
if (hasException(input, RULE_NAME)) {
collectException(input, RULE_NAME, path);
Expand All @@ -36,15 +36,15 @@ export default (input, { maxItems, ignore = [] }, { path }) => {
return;
}

const errors = checkViolationsAndReturnErrors(input, path, maxItems);
const errors = checkViolationsAndReturnErrors(input, path, maxAllowedValue);
if (errors.length > 0) {
return collectAndReturnViolation(path, RULE_NAME, errors);
}

collectAdoption(path, RULE_NAME);
};

function checkViolationsAndReturnErrors(input, path, maxItems) {
function checkViolationsAndReturnErrors(input, path, maxAllowedValue) {
try {
// Check if maxItems is defined
if (input.maxItems === undefined) {
Expand All @@ -56,10 +56,10 @@ function checkViolationsAndReturnErrors(input, path, maxItems) {
];
}
// Check if maxItems is larger than the recommended value
else if (input.maxItems > maxItems) {
else if (input.maxItems > maxAllowedValue) {
return [
{
message: `The maxItems value for arrays must be set to ${maxItems} or below, found: ${input.maxItems}. If the array field has the chance of being too large, the API should use a sub-resource instead.`,
message: `The maxItems value for arrays must be set to ${maxAllowedValue} or below, found: ${input.maxItems}. If the array field has the chance of being too large, the API should use a sub-resource instead.`,
path,
},
];
Expand Down
Loading