Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions tools/spectral/ipa/rulesets/functions/utils/collectionUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import { EXCEPTION_EXTENSION } from './exceptions.js';
/**
* Collects a violation entry and returns formatted error data.
*
* @param {Array<string>} path - The JSON path for the object where the rule violation occurred.
* @param {Array<string>} jsonPath - The JSON path array for the object where the rule violation occurred. Example: ["paths","./pets","get"]
* @param {string} ruleName - The name of the rule that was violated.
* @param {string|Array<Object>} errorData - The error information. Can be either a string message or an array of error objects.
* @returns {Array<Object>} An array of error objects. Each object has a 'message' property.
* @throws {Error} Throws an error if errorData is neither a string nor an array.
*
*/
export function collectAndReturnViolation(path, ruleName, errorData) {
collector.add(EntryType.VIOLATION, path, ruleName);
export function collectAndReturnViolation(jsonPath, ruleName, errorData) {
collector.add(EntryType.VIOLATION, jsonPath, ruleName);

if (typeof errorData === 'string') {
return [{ message: errorData }];
Expand All @@ -26,23 +26,23 @@ export function collectAndReturnViolation(path, ruleName, errorData) {
/**
* Collects an adoption entry.
*
* @param {Array<string>} path - The JSON path for the object where the rule adoption occurred.
* @param {Array<string>} jsonPath - The JSON path array for the object where the rule violation occurred. Example: ["paths","./pets","get"]
* @param {string} ruleName - The name of the rule that was adopted.
*/
export function collectAdoption(path, ruleName) {
collector.add(EntryType.ADOPTION, path, ruleName);
export function collectAdoption(jsonPath, ruleName) {
collector.add(EntryType.ADOPTION, jsonPath, ruleName);
}

/**
* Collects an exception entry.
*
* @param object the object to evaluate
* @param {Array<string>} path - The JSON path for the object where the rule exception occurred.
* @param {Array<string>} jsonPath - The JSON path array for the object where the rule violation occurred. Example: ["paths","./pets","get"]
* @param {string} ruleName - The name of the rule that the exception is defined for.
*/
export function collectException(object, ruleName, path) {
export function collectException(object, ruleName, jsonPath) {
let exceptionReason = object[EXCEPTION_EXTENSION][ruleName];
if (exceptionReason) {
collector.add(EntryType.EXCEPTION, path, ruleName, exceptionReason);
collector.add(EntryType.EXCEPTION, jsonPath, ruleName, exceptionReason);
}
}
Loading