main
Last change
on this file was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago |
Initial commit
|
-
Property mode
set to
100644
|
File size:
903 bytes
|
Rev | Line | |
---|
[d24f17c] | 1 | import { defaultTo, has, mapObjIndexed, path, propSatisfies } from 'ramda';
|
---|
| 2 | import { isPlainObject, isString, trimCharsStart } from 'ramda-adjunct';
|
---|
| 3 |
|
---|
| 4 | /**
|
---|
| 5 | * This dereference algorithm is used exclusively for dereferencing specification objects.
|
---|
| 6 | * It doesn't handle circular references of external references and works on objects only (not arrays).
|
---|
| 7 | */
|
---|
| 8 | // eslint-disable-next-line import/prefer-default-export
|
---|
| 9 | export const dereference = (object, root) => {
|
---|
| 10 | const rootObject = defaultTo(object, root);
|
---|
| 11 | return mapObjIndexed(val => {
|
---|
| 12 | if (isPlainObject(val) && has('$ref', val) && propSatisfies(isString, '$ref', val)) {
|
---|
| 13 | const $ref = path(['$ref'], val);
|
---|
| 14 | // @ts-ignore
|
---|
| 15 | const pointer = trimCharsStart('#/', $ref);
|
---|
| 16 | return path(pointer.split('/'), rootObject);
|
---|
| 17 | }
|
---|
| 18 | if (isPlainObject(val)) {
|
---|
| 19 | return dereference(val, rootObject);
|
---|
| 20 | }
|
---|
| 21 | return val;
|
---|
| 22 | }, object);
|
---|
| 23 | }; |
---|
Note:
See
TracBrowser
for help on using the repository browser.