Skip to content

Commit 3a62aa1

Browse files
docs and prettiers fix
1 parent 11a1288 commit 3a62aa1

File tree

6 files changed

+104
-89
lines changed

6 files changed

+104
-89
lines changed

tools/spectral/ipa/__tests__/IPA124ArrayMaxItems.test.js

Lines changed: 75 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ testRule('xgen-IPA-124-array-max-items', [
1414
type: 'array',
1515
maxItems: 100,
1616
items: {
17-
type: 'string'
18-
}
19-
}
20-
}
21-
}
22-
}
23-
}
17+
type: 'string',
18+
},
19+
},
20+
},
21+
},
22+
},
23+
},
2424
},
25-
errors: []
25+
errors: [],
2626
},
2727
{
2828
name: 'invalid array missing maxItems',
@@ -35,22 +35,22 @@ testRule('xgen-IPA-124-array-max-items', [
3535
items: {
3636
type: 'array',
3737
items: {
38-
type: 'string'
39-
}
40-
}
41-
}
42-
}
43-
}
44-
}
38+
type: 'string',
39+
},
40+
},
41+
},
42+
},
43+
},
44+
},
4545
},
4646
errors: [
4747
{
4848
code: 'xgen-IPA-124-array-max-items',
4949
message: 'Array must have maxItems property defined.',
5050
path: ['components', 'schemas', 'InvalidSchema', 'properties', 'items'],
51-
severity: DiagnosticSeverity.Warning
52-
}
53-
]
51+
severity: DiagnosticSeverity.Warning,
52+
},
53+
],
5454
},
5555
{
5656
name: 'invalid array with incorrect maxItems value',
@@ -64,22 +64,22 @@ testRule('xgen-IPA-124-array-max-items', [
6464
type: 'array',
6565
maxItems: 50,
6666
items: {
67-
type: 'string'
68-
}
69-
}
70-
}
71-
}
72-
}
73-
}
67+
type: 'string',
68+
},
69+
},
70+
},
71+
},
72+
},
73+
},
7474
},
7575
errors: [
7676
{
7777
code: 'xgen-IPA-124-array-max-items',
7878
message: 'Array maxItems must be set to 100, found: 50.',
7979
path: ['components', 'schemas', 'InvalidSchema', 'properties', 'items'],
80-
severity: DiagnosticSeverity.Warning
81-
}
82-
]
80+
severity: DiagnosticSeverity.Warning,
81+
},
82+
],
8383
},
8484
{
8585
name: 'array with exception should be skipped',
@@ -92,18 +92,18 @@ testRule('xgen-IPA-124-array-max-items', [
9292
items: {
9393
type: 'array',
9494
items: {
95-
type: 'string'
95+
type: 'string',
9696
},
9797
'x-xgen-IPA-exception': {
98-
'xgen-IPA-124-array-max-items': 'Reason'
99-
}
100-
}
101-
}
102-
}
103-
}
104-
}
98+
'xgen-IPA-124-array-max-items': 'Reason',
99+
},
100+
},
101+
},
102+
},
103+
},
104+
},
105105
},
106-
errors: []
106+
errors: [],
107107
},
108108
{
109109
name: 'nested arrays should all be checked',
@@ -117,26 +117,26 @@ testRule('xgen-IPA-124-array-max-items', [
117117
type: 'array',
118118
maxItems: 100,
119119
items: {
120-
type: 'array',
120+
type: 'array',
121121
maxItems: 50,
122122
items: {
123-
type: 'string'
124-
}
125-
}
126-
}
127-
}
128-
}
129-
}
130-
}
123+
type: 'string',
124+
},
125+
},
126+
},
127+
},
128+
},
129+
},
130+
},
131131
},
132132
errors: [
133133
{
134134
code: 'xgen-IPA-124-array-max-items',
135135
message: 'Array maxItems must be set to 100, found: 50.',
136136
path: ['components', 'schemas', 'NestedArrays', 'properties', 'outerArray', 'items'],
137-
severity: DiagnosticSeverity.Warning
138-
}
139-
]
137+
severity: DiagnosticSeverity.Warning,
138+
},
139+
],
140140
},
141141
{
142142
name: 'arrays in request/response bodies should be checked',
@@ -153,25 +153,35 @@ testRule('xgen-IPA-124-array-max-items', [
153153
items: {
154154
type: 'array',
155155
items: {
156-
type: 'string'
157-
}
158-
}
159-
}
160-
}
161-
}
162-
}
163-
}
164-
}
165-
}
166-
}
156+
type: 'string',
157+
},
158+
},
159+
},
160+
},
161+
},
162+
},
163+
},
164+
},
165+
},
166+
},
167167
},
168168
errors: [
169169
{
170170
code: 'xgen-IPA-124-array-max-items',
171171
message: 'Array must have maxItems property defined.',
172-
path: ['paths', '/api/resources', 'post', 'requestBody', 'content', 'application/json', 'schema', 'properties', 'items'],
173-
severity: DiagnosticSeverity.Warning
174-
}
175-
]
176-
}
172+
path: [
173+
'paths',
174+
'/api/resources',
175+
'post',
176+
'requestBody',
177+
'content',
178+
'application/json',
179+
'schema',
180+
'properties',
181+
'items',
182+
],
183+
severity: DiagnosticSeverity.Warning,
184+
},
185+
],
186+
},
177187
]);

tools/spectral/ipa/ipa-spectral.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,3 @@ overrides:
5757
- '**#/paths/~1rest~1unauth~1version' # external reference, to be covered by CLOUDP-309694
5858
rules:
5959
xgen-IPA-114-error-responses-refer-to-api-error: 'off'
60-

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ rules:
3232
- Validates that each enum array has 20 or fewer values
3333
- Reusable enum schemas will be ignored
3434
- Skips validation if the schema has an exception defined for this rule
35+
- This validation threshold can be adjusted by changing the functionOptions.maxEnumValues parameter
3536
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-123-allowable-enum-values-should-not-exceed-20'
3637
severity: warn
3738
resolved: false

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,18 @@ rules:
88
xgen-IPA-124-array-max-items:
99
description: |
1010
Array fields must have a maxItems property defined with a value of 100.
11-
11+
1212
##### Implementation details
1313
Rule checks for the following conditions:
14-
14+
1515
- All schema objects with type 'array' must have a maxItems property
1616
- The maxItems value must be set to 100
17-
- Schema objects with `x-xgen-IPA-exception` for this rule are excluded from validation
17+
- This validation threshold can be adjusted by changing the functionOptions.maxItems parameter
1818
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-124-array-max-items'
1919
severity: warn
2020
resolved: false
2121
given: $..[?(@.type=="array")]
2222
then:
2323
function: IPA124ArrayMaxItems
2424
functionOptions:
25-
maxItems: 100
25+
maxItems: 100

tools/spectral/ipa/rulesets/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,7 @@ Rule checks for the following conditions:
841841
- Validates that each enum array has 20 or fewer values
842842
- Reusable enum schemas will be ignored
843843
- Skips validation if the schema has an exception defined for this rule
844+
- This validation threshold can be adjusted by changing the functionOptions.maxEnumValues parameter
844845

845846

846847

@@ -858,7 +859,7 @@ Rule checks for the following conditions:
858859

859860
- All schema objects with type 'array' must have a maxItems property
860861
- The maxItems value must be set to 100
861-
- Schema objects with `x-xgen-IPA-exception` for this rule are excluded from validation
862+
- This validation threshold can be adjusted by changing the functionOptions.maxItems parameter
862863

863864

864865

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

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,39 @@ const RULE_NAME = 'xgen-IPA-124-array-max-items';
1616
* @param {object} context - The context object containing the path and documentInventory
1717
*/
1818
export default (input, { maxItems }, { path }) => {
19-
// Check for exception at the schema level
20-
if (hasException(input, RULE_NAME)) {
21-
collectException(input, RULE_NAME, path);
22-
return;
23-
}
19+
// Check for exception at the schema level
20+
if (hasException(input, RULE_NAME)) {
21+
collectException(input, RULE_NAME, path);
22+
return;
23+
}
2424

25-
const errors = checkViolationsAndReturnErrors(input, path, maxItems);
26-
if (errors.length > 0) {
27-
return collectAndReturnViolation(path, RULE_NAME, errors);
28-
}
25+
const errors = checkViolationsAndReturnErrors(input, path, maxItems);
26+
if (errors.length > 0) {
27+
return collectAndReturnViolation(path, RULE_NAME, errors);
28+
}
2929

30-
collectAdoption(path, RULE_NAME);
30+
collectAdoption(path, RULE_NAME);
3131
};
3232

3333
function checkViolationsAndReturnErrors(input, path, maxItems) {
3434
try {
3535
// Check if maxItems is defined
3636
if (input.maxItems === undefined) {
37-
return [{
38-
message: `Array must have maxItems property defined.`,
39-
path,
40-
}];
37+
return [
38+
{
39+
message: `Array must have maxItems property defined.`,
40+
path,
41+
},
42+
];
4143
}
4244
// Check if maxItems is set to the required value
4345
else if (input.maxItems !== maxItems) {
44-
return [{
45-
message: `Array maxItems must be set to ${maxItems}, found: ${input.maxItems}.`,
46-
path,
47-
}];
46+
return [
47+
{
48+
message: `Array maxItems must be set to ${maxItems}, found: ${input.maxItems}.`,
49+
path,
50+
},
51+
];
4852
}
4953

5054
return [];

0 commit comments

Comments
 (0)