Skip to content

Commit bd8e19a

Browse files
committed
fix: format
1 parent 181c6af commit bd8e19a

9 files changed

+81
-46
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ testRule('xgen-IPA-108-delete-method-return-204-response', [
3838
{
3939
code: 'xgen-IPA-108-delete-method-return-204-response',
4040
message: 'DELETE method should return 204 No Content status code http://go/ipa/108',
41-
path: ['paths', '/resource/{id}'],
41+
path: ['paths', '/resource/{id}', 'delete'],
4242
severity: DiagnosticSeverity.Error,
4343
},
4444
],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ testRule('xgen-IPA-108-delete-include-404-response', [
3737
{
3838
code: 'xgen-IPA-108-delete-include-404-response',
3939
message: 'DELETE method should include 404 status code for not found resources http://go/ipa/108',
40-
path: ['paths', '/resource/{id}'],
40+
path: ['paths', '/resource/{id}', 'delete'],
4141
severity: DiagnosticSeverity.Error,
4242
},
4343
],

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ testRule('xgen-IPA-108-delete-request-no-body', [
2525
delete: {
2626
requestBody: {
2727
content: {
28-
'application/json': {
28+
'application/vnd.atlas.2024-08-05+json': {
2929
schema: { type: 'object' },
3030
},
3131
},
@@ -41,7 +41,7 @@ testRule('xgen-IPA-108-delete-request-no-body', [
4141
{
4242
code: 'xgen-IPA-108-delete-request-no-body',
4343
message: 'DELETE method should not have a request body http://go/ipa/108',
44-
path: ['paths', '/resource/{id}'],
44+
path: ['paths', '/resource/{id}', 'delete'],
4545
severity: DiagnosticSeverity.Error,
4646
},
4747
],

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ testRule('xgen-IPA-108-delete-response-should-be-empty', [
4040
{
4141
code: 'xgen-IPA-108-delete-response-should-be-empty',
4242
message: 'DELETE method should return an empty response http://go/ipa/108',
43-
path: ['paths', '/resource/{id}'],
43+
path: ['paths', '/resource/{id}', 'delete'],
4444
severity: DiagnosticSeverity.Error,
4545
},
4646
],

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@ rules:
66
description: Delete method response must be empty http://go/ipa/108
77
message: '{{error}} http://go/ipa/108'
88
severity: warn
9-
given: $.paths[*].delete
9+
given: $.paths
1010
then:
1111
function: deleteMethodResponseShouldBeVoid
1212

1313
xgen-IPA-108-delete-method-return-204-response:
1414
description: DELETE method must return 204 No Content
1515
message: '{{error}} http://go/ipa/108'
1616
severity: warn
17-
given: $.paths[*].delete
17+
given: $.paths
1818
then:
1919
function: deleteMethod204Response
2020

@@ -30,7 +30,7 @@ rules:
3030
description: DELETE method must include 404 response
3131
message: '{{error}} http://go/ipa/108'
3232
severity: warn
33-
given: $.paths[*].delete
33+
given: $.paths
3434
then:
3535
function: deleteMethod404Response
3636

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js';
22
import { hasException } from './utils/exceptions.js';
33

4-
const RULE_NAME = 'xgen-IPA-108-delete-204-response';
4+
const RULE_NAME = 'xgen-IPA-108-delete-method-return-204-response';
55
const ERROR_MESSAGE = 'DELETE method should return 204 No Content status code';
66

7-
export default (deleteOp, _, { path }) => {
8-
if (hasException(deleteOp, RULE_NAME)) {
9-
return collectException(deleteOp, RULE_NAME, path);
10-
}
7+
export default (paths, _, { path }) => {
8+
const errors = [];
119

12-
const responses = deleteOp.responses || {};
13-
if (!responses['204']) {
14-
return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE);
15-
}
10+
Object.entries(paths).forEach(([pathUrl, pathItem]) => {
11+
const deleteOp = pathItem.delete;
12+
if (!deleteOp) return;
1613

17-
collectAdoption(path, RULE_NAME);
14+
if (hasException(deleteOp, RULE_NAME)) {
15+
errors.push(collectException(deleteOp, RULE_NAME, `${path}.${pathUrl}.delete`));
16+
return;
17+
}
18+
19+
const responses = deleteOp.responses || {};
20+
if (!responses['204']) {
21+
errors.push(collectAndReturnViolation(`${path}.${pathUrl}.delete`, RULE_NAME, ERROR_MESSAGE));
22+
return;
23+
}
24+
25+
collectAdoption(`${path}.${pathUrl}.delete`, RULE_NAME);
26+
});
27+
28+
return errors;
1829
};
Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,29 @@
11
import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js';
22
import { hasException } from './utils/exceptions.js';
33

4-
const RULE_NAME = 'xgen-IPA-108-delete-404-response';
4+
const RULE_NAME = 'xgen-IPA-108-delete-include-404-response';
55
const ERROR_MESSAGE = 'DELETE method should include 404 status code for not found resources';
66

7-
export default (deleteOp, _, { path }) => {
8-
if (hasException(deleteOp, RULE_NAME)) {
9-
return collectException(deleteOp, RULE_NAME, path);
10-
}
7+
export default (paths, _, { path }) => {
8+
const errors = [];
119

12-
const responses = deleteOp.responses || {};
13-
if (!responses['404']) {
14-
return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE);
15-
}
10+
Object.entries(paths).forEach(([pathUrl, pathItem]) => {
11+
const deleteOp = pathItem.delete;
12+
if (!deleteOp) return;
1613

17-
collectAdoption(path, RULE_NAME);
14+
if (hasException(deleteOp, RULE_NAME)) {
15+
errors.push(collectException(deleteOp, RULE_NAME, `${path}.${pathUrl}.delete`));
16+
return;
17+
}
18+
19+
const responses = deleteOp.responses || {};
20+
if (!responses['404']) {
21+
errors.push(collectAndReturnViolation(`${path}.${pathUrl}.delete`, RULE_NAME, ERROR_MESSAGE));
22+
return;
23+
}
24+
25+
collectAdoption(`${path}.${pathUrl}.delete`, RULE_NAME);
26+
});
27+
28+
return errors;
1829
};
Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,25 @@
11
import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js';
22
import { hasException } from './utils/exceptions.js';
33

4-
const RULE_NAME = 'xgen-IPA-108-delete-no-body';
4+
const RULE_NAME = 'xgen-IPA-108-delete-request-no-body';
55
const ERROR_MESSAGE = 'DELETE method should not have a request body';
66

77
export default (deleteOp, _, { path }) => {
8+
if (!deleteOp) return [];
9+
10+
const errors = [];
11+
812
if (hasException(deleteOp, RULE_NAME)) {
9-
return collectException(deleteOp, RULE_NAME, path);
13+
errors.push(collectException(deleteOp, RULE_NAME, path));
14+
return errors;
1015
}
1116

1217
if (deleteOp.requestBody) {
13-
return collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE);
18+
errors.push(collectAndReturnViolation(path, RULE_NAME, ERROR_MESSAGE));
19+
return errors;
1420
}
1521

1622
collectAdoption(path, RULE_NAME);
23+
24+
return errors;
1725
};
Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
11
import { hasException } from './utils/exceptions.js';
22
import { collectAdoption, collectAndReturnViolation, collectException } from './utils/collectionUtils.js';
33

4-
const RULE_NAME = 'xgen-IPA-108-delete-response-should-be-void';
4+
const RULE_NAME = 'xgen-IPA-108-delete-response-should-be-empty';
55
const ERROR_MESSAGES = {
66
NON_EMPTY_RESPONSE: 'DELETE method should return an empty response',
77
};
88

9-
export default (deleteOp, _, { path }) => {
9+
export default (paths, _, { path }) => {
1010
const errors = [];
1111

12-
if (hasException(deleteOp, RULE_NAME)) {
13-
return collectException(deleteOp, RULE_NAME, path);
14-
}
12+
Object.entries(paths).forEach(([pathUrl, pathItem]) => {
13+
const deleteOp = pathItem.delete;
14+
if (!deleteOp) return;
1515

16-
const responses = deleteOp.responses || {};
16+
if (hasException(deleteOp, RULE_NAME)) {
17+
errors.push(...collectException(deleteOp, RULE_NAME, `${path}.${pathUrl}.delete`));
18+
return;
19+
}
20+
21+
const responses = deleteOp.responses || {};
22+
Object.entries(responses).forEach(([status, response]) => {
23+
if (status === '204' && response.content) {
24+
errors.push(
25+
collectAndReturnViolation(`${path}.${pathUrl}.delete`, RULE_NAME, ERROR_MESSAGES.NON_EMPTY_RESPONSE)
26+
);
27+
}
28+
});
1729

18-
Object.entries(responses).forEach(([status, response]) => {
19-
if (status === '204' && response.content) {
20-
errors.push(ERROR_MESSAGES.NON_EMPTY_RESPONSE);
30+
if (errors.length === 0) {
31+
collectAdoption(`${path}.${pathUrl}.delete`, RULE_NAME);
2132
}
2233
});
2334

24-
if (errors.length === 0) {
25-
collectAdoption(path, RULE_NAME);
26-
} else {
27-
return collectAndReturnViolation(path, RULE_NAME, errors);
28-
}
29-
3035
return errors;
3136
};

0 commit comments

Comments
 (0)