UNPKG

@redocly/cli

Version:

[@Redocly](https://redocly.com) CLI is your all-in-one API documentation utility. It builds, manages, improves, and quality-checks your API descriptions, all of which comes in handy for various phases of the API Lifecycle. Create your own rulesets to make

53 lines 2.3 kB
import { dequal } from '@redocly/openapi-core'; import { green } from 'colorette'; import { COMPONENTS } from '../../split/types.js'; import { duplicateTagDescriptionWarning } from './duplicate-tag-description-warning.js'; import { filterConflicts } from './filter-conflicts.js'; import { prefixTagSuggestion } from './prefix-tag-suggestion.js'; import { showConflicts } from './show-conflicts.js'; function doesComponentsDiffer(curr, next) { return !dequal(Object.values(curr)[0], Object.values(next)[0]); } function validateComponentsDifference(files) { let isDiffer = false; for (let i = 0, len = files.length; i < len; i++) { const next = files[i + 1]; if (next && doesComponentsDiffer(files[i], next)) { isDiffer = true; } } return isDiffer; } let potentialConflictsTotal = 0; export function iteratePotentialConflicts({ potentialConflicts, withoutXTagGroups, }) { for (const group of Object.keys(potentialConflicts)) { for (const [key, value] of Object.entries(potentialConflicts[group])) { const conflicts = filterConflicts(value); if (conflicts.length) { if (group === COMPONENTS) { for (const [_, conflict] of Object.entries(conflicts)) { if (validateComponentsDifference(conflict[1])) { conflict[1] = conflict[1].map((c) => Object.keys(c)[0]); showConflicts(green(group) + ' => ' + key, [conflict]); potentialConflictsTotal += 1; } } } else { if (withoutXTagGroups && group === 'tags') { duplicateTagDescriptionWarning(conflicts); } else { potentialConflictsTotal += conflicts.length; showConflicts(green(group) + ' => ' + key, conflicts); } } if (group === 'tags' && !withoutXTagGroups) { prefixTagSuggestion(conflicts.length); } } } } return potentialConflictsTotal; } //# sourceMappingURL=iterate-potential-conflicts.js.map