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

28 lines 1.29 kB
import { isRef, isPlainObject } from '@redocly/openapi-core'; import * as path from 'node:path'; import { crawl, startsWithComponents } from '../../split/index.js'; export function replace$Refs(obj, componentsPrefix) { crawl(obj, (node) => { if (isRef(node) && startsWithComponents(node.$ref)) { const name = path.basename(node.$ref); node.$ref = node.$ref.replace(name, componentsPrefix + '_' + name); } else if (isPlainObject(node.discriminator) && isPlainObject(node.discriminator.mapping)) { const { mapping } = node.discriminator; for (const name of Object.keys(mapping)) { const mappingPointer = mapping[name]; if (typeof mappingPointer === 'string' && startsWithComponents(mappingPointer)) { mapping[name] = mappingPointer .split('/') .map((name, i, arr) => { return arr.length - 1 === i && !name.startsWith(componentsPrefix + '_') ? componentsPrefix + '_' + name : name; }) .join('/'); } } } }); } //# sourceMappingURL=replace-$-refs.js.map