UNPKG

@opendoc/openapi-reference-parser

Version:

Get the dependencies of reference in openapi.

63 lines 1.75 kB
import * as R from 'ramda'; import * as ObjectPath from 'object-path'; export class Reference { static from($ref) { if (typeof $ref === 'string') { if ($ref.startsWith('#')) return new RelativeReference($ref.split('/').slice(1)); return new AbsoluteReference($ref); } return new RelativeReference($ref); } } export class RelativeReference extends Reference { paths; constructor(paths) { super(); this.paths = paths; } async resolve(object) { return R.pathOr(undefined, this.paths, object); } toString() { return `#/${this.paths.join('/')}`; } set(storage, value) { ObjectPath.set(storage, this.paths, value); } get(storage) { return R.path(this.paths, storage); } equals(ref) { if (!(ref instanceof RelativeReference)) return false; return R.equals(this.paths, ref.paths); } } export class AbsoluteReference extends Reference { address; constructor(address) { super(); this.address = address; } async resolve() { throw new Error('Not implemented'); } toString() { return this.address; } // eslint-disable-next-line @typescript-eslint/no-unused-vars set(storage, value) { throw new Error('AbsoluteReference is not supported'); } // eslint-disable-next-line @typescript-eslint/no-unused-vars get(storage) { throw new Error('AbsoluteReference is not supported'); } equals(ref) { if (!(ref instanceof AbsoluteReference)) return false; return this.address === ref.address; } } //# sourceMappingURL=reference.js.map