Skip to content

Commit 6c3198e

Browse files
test commit
1 parent 56091ad commit 6c3198e

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

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

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@ const RULE_NAME = 'xgen-IPA-114-error-responses-refer-to-api-error';
1717
* @param {object} _ - Rule options (unused)
1818
* @param {object} context - The context object containing path and document information
1919
*/
20-
export default (input, _, { path, documentInventory }) => {
20+
export default (input, _, { path, documentInventory, referencedDocuments }) => {
2121
const oas = documentInventory.unresolved;
2222
const apiResponseObject = resolveObject(oas, path);
2323
const errorCode = path[path.length - 1];
24+
console.log(referencedDocuments);
2425

2526
// Check for exception at response level
2627
if (hasException(apiResponseObject, RULE_NAME)) {
@@ -44,12 +45,18 @@ function checkViolationsAndReturnErrors(apiResponseObject, oas, path, errorCode)
4445
if (apiResponseObject.content) {
4546
content = apiResponseObject.content;
4647
} else if (apiResponseObject.$ref) {
47-
const schemaName = getSchemaNameFromRef(apiResponseObject.$ref);
48-
const responseSchema = resolveObject(oas, ['components', 'responses', schemaName]);
49-
if (!responseSchema) {
50-
return [{ path, message: `${errorCode} response must define content with a valid reference.` }];
48+
const ref = apiResponseObject.$ref;
49+
if(ref.startsWith('#/components')) {
50+
const schemaName = getSchemaNameFromRef(apiResponseObject.$ref);
51+
const responseSchema = resolveObject(oas, ['components', 'responses', schemaName]);
52+
if (!responseSchema) {
53+
return [{ path, message: `${errorCode} response must define content with a valid reference.` }];
54+
}
55+
content = responseSchema.content;
56+
} else {
57+
console.log(ref);
5158
}
52-
content = responseSchema.content;
59+
5360
} else {
5461
return [{ path, message: `${errorCode} response must define content with ApiError schema reference.` }];
5562
}

0 commit comments

Comments
 (0)