Skip to content

Commit d82a6fa

Browse files
IPA-114: Errors (fix for exception level) (#637)
1 parent f5ae0e6 commit d82a6fa

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -204,18 +204,19 @@ testRule('xgen-IPA-114-error-responses-refer-to-api-error', [
204204
get: {
205205
responses: {
206206
400: {
207+
'x-xgen-IPA-exception': {
208+
'xgen-IPA-114-error-responses-refer-to-api-error': 'Reason',
209+
},
207210
content: {
208211
'application/json': {
209212
schema: {
210213
type: 'object',
211214
},
212-
'x-xgen-IPA-exception': {
213-
'xgen-IPA-114-error-responses-refer-to-api-error': 'Reason',
214-
},
215215
},
216216
},
217217
},
218218
500: {
219+
description: 'Internal Service Error',
219220
'x-xgen-IPA-exception': {
220221
'xgen-IPA-114-error-responses-refer-to-api-error': 'Reason',
221222
},

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ rules:
1515
This rule checks that all 4xx and 5xx error responses reference the ApiError schema.
1616
message: '{{error}} https://mdb.link/mongodb-atlas-openapi-validation#xgen-IPA-114-error-responses-refer-to-api-error'
1717
severity: warn
18+
resolved: false
1819
given: '$.paths[*][*].responses[?(@property.match(/^[45]\d\d$/))]'
1920
then:
2021
function: 'IPA114ErrorResponsesReferToApiError'

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ function checkViolationsAndReturnErrors(apiResponseObject, oas, path, errorCode)
4646
} else if (apiResponseObject.$ref) {
4747
const schemaName = getSchemaNameFromRef(apiResponseObject.$ref);
4848
const responseSchema = resolveObject(oas, ['components', 'responses', schemaName]);
49+
if (!responseSchema) {
50+
return [{ path, message: `${errorCode} response must define content with a valid reference.` }];
51+
}
4952
content = responseSchema.content;
5053
} else {
5154
return [{ path, message: `${errorCode} response must define content with ApiError schema reference.` }];
@@ -56,13 +59,7 @@ function checkViolationsAndReturnErrors(apiResponseObject, oas, path, errorCode)
5659
continue;
5760
}
5861

59-
if (hasException(mediaTypeObj, RULE_NAME)) {
60-
collectException(mediaTypeObj, RULE_NAME, [...path, 'content', mediaType]);
61-
continue;
62-
}
63-
6462
const contentPath = [...path, 'content', mediaType];
65-
6663
// Check if schema exists
6764
if (!mediaTypeObj.schema) {
6865
errors.push({

0 commit comments

Comments
 (0)