Skip to content

Commit 1696e9e

Browse files
CLOUDP-314000: Clarify IPA-124 maxItems rule description
1 parent fd3193e commit 1696e9e

File tree

3 files changed

+14
-14
lines changed

3 files changed

+14
-14
lines changed

tools/spectral/ipa/rulesets/IPA-124.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,16 +7,16 @@ functions:
77
rules:
88
xgen-IPA-124-array-max-items:
99
description: |
10-
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.
10+
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.
1111
1212
##### Implementation details
1313
Rule checks for the following conditions:
1414
15-
- All schema objects with type 'array' must have a maxItems property
16-
- The maxItems value must be set below the threshold of 100
15+
- All schema objects with type 'array' must have a `maxItems` property
16+
- The `maxItems` value must be lower than or equal to 100
1717
1818
##### Function options
19-
- maxItems: Required integer parameter specifying the maximum allowed array size (default: 100)
19+
- maxAllowedValue: Required integer parameter specifying the maximum allowed value for the `maxItems` property (100)
2020
- ignore: Required array parameter listing property names to be exempted from validation
2121
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-124-array-max-items'
2222
severity: error
@@ -25,7 +25,7 @@ rules:
2525
then:
2626
function: IPA124ArrayMaxItems
2727
functionOptions:
28-
maxItems: 100
28+
maxAllowedValue: 100
2929
ignore:
3030
- links
3131
- results

tools/spectral/ipa/rulesets/README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -852,16 +852,16 @@ Rules are based on [http://go/ipa/IPA-124](http://go/ipa/IPA-124).
852852
#### xgen-IPA-124-array-max-items
853853

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

857857
##### Implementation details
858858
Rule checks for the following conditions:
859859

860-
- All schema objects with type 'array' must have a maxItems property
861-
- The maxItems value must be set below the threshold of 100
860+
- All schema objects with type 'array' must have a `maxItems` property
861+
- The `maxItems` value must be lower than or equal to 100
862862

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

867867

tools/spectral/ipa/rulesets/functions/IPA124ArrayMaxItems.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const RULE_NAME = 'xgen-IPA-124-array-max-items';
1515
* @param {object} options - Rule configuration options
1616
* @param {object} context - The context object containing the path and documentInventory
1717
*/
18-
export default (input, { maxItems, ignore = [] }, { path }) => {
18+
export default (input, { maxAllowedValue, ignore = [] }, { path }) => {
1919
// Check for exception at the schema level
2020
if (hasException(input, RULE_NAME)) {
2121
collectException(input, RULE_NAME, path);
@@ -36,15 +36,15 @@ export default (input, { maxItems, ignore = [] }, { path }) => {
3636
return;
3737
}
3838

39-
const errors = checkViolationsAndReturnErrors(input, path, maxItems);
39+
const errors = checkViolationsAndReturnErrors(input, path, maxAllowedValue);
4040
if (errors.length > 0) {
4141
return collectAndReturnViolation(path, RULE_NAME, errors);
4242
}
4343

4444
collectAdoption(path, RULE_NAME);
4545
};
4646

47-
function checkViolationsAndReturnErrors(input, path, maxItems) {
47+
function checkViolationsAndReturnErrors(input, path, maxAllowedValue) {
4848
try {
4949
// Check if maxItems is defined
5050
if (input.maxItems === undefined) {
@@ -56,10 +56,10 @@ function checkViolationsAndReturnErrors(input, path, maxItems) {
5656
];
5757
}
5858
// Check if maxItems is larger than the recommended value
59-
else if (input.maxItems > maxItems) {
59+
else if (input.maxItems > maxAllowedValue) {
6060
return [
6161
{
62-
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.`,
62+
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.`,
6363
path,
6464
},
6565
];

0 commit comments

Comments
 (0)