[d24f17c] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | exports.__esModule = true;
|
---|
| 4 | exports.dereference = void 0;
|
---|
| 5 | var _ramda = require("ramda");
|
---|
| 6 | var _ramdaAdjunct = require("ramda-adjunct");
|
---|
| 7 | /**
|
---|
| 8 | * This dereference algorithm is used exclusively for dereferencing specification objects.
|
---|
| 9 | * It doesn't handle circular references of external references and works on objects only (not arrays).
|
---|
| 10 | */
|
---|
| 11 | // eslint-disable-next-line import/prefer-default-export
|
---|
| 12 | const dereference = (object, root) => {
|
---|
| 13 | const rootObject = (0, _ramda.defaultTo)(object, root);
|
---|
| 14 | return (0, _ramda.mapObjIndexed)(val => {
|
---|
| 15 | if ((0, _ramdaAdjunct.isPlainObject)(val) && (0, _ramda.has)('$ref', val) && (0, _ramda.propSatisfies)(_ramdaAdjunct.isString, '$ref', val)) {
|
---|
| 16 | const $ref = (0, _ramda.path)(['$ref'], val);
|
---|
| 17 | // @ts-ignore
|
---|
| 18 | const pointer = (0, _ramdaAdjunct.trimCharsStart)('#/', $ref);
|
---|
| 19 | return (0, _ramda.path)(pointer.split('/'), rootObject);
|
---|
| 20 | }
|
---|
| 21 | if ((0, _ramdaAdjunct.isPlainObject)(val)) {
|
---|
| 22 | return dereference(val, rootObject);
|
---|
| 23 | }
|
---|
| 24 | return val;
|
---|
| 25 | }, object);
|
---|
| 26 | };
|
---|
| 27 | exports.dereference = dereference; |
---|