[d24f17c] | 1 | "use strict";
|
---|
| 2 |
|
---|
| 3 | var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
|
---|
| 4 | exports.__esModule = true;
|
---|
| 5 | exports.resolveSchema$refField = exports.resolveSchema$idField = exports.refractToSchemaElement = exports.maybeRefractToSchemaElement = void 0;
|
---|
| 6 | var _ramda = require("ramda");
|
---|
| 7 | var _apidomCore = require("@swagger-api/apidom-core");
|
---|
| 8 | var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-1");
|
---|
| 9 | var url = _interopRequireWildcard(require("../../../util/url.cjs"));
|
---|
| 10 | const resolveSchema$refField = (retrievalURI, schemaElement) => {
|
---|
| 11 | if (typeof schemaElement.$ref === 'undefined') {
|
---|
| 12 | return undefined;
|
---|
| 13 | }
|
---|
| 14 | const hash = url.getHash((0, _apidomCore.toValue)(schemaElement.$ref));
|
---|
| 15 | const inherited$id = (0, _apidomCore.toValue)(schemaElement.meta.get('inherited$id'));
|
---|
| 16 | const $refBaseURI = (0, _ramda.reduce)((acc, uri) => {
|
---|
| 17 | return url.resolve(acc, url.sanitize(url.stripHash(uri)));
|
---|
| 18 | }, retrievalURI, [...inherited$id, (0, _apidomCore.toValue)(schemaElement.$ref)]);
|
---|
| 19 | return `${$refBaseURI}${hash === '#' ? '' : hash}`;
|
---|
| 20 | };
|
---|
| 21 | exports.resolveSchema$refField = resolveSchema$refField;
|
---|
| 22 | const resolveSchema$idField = (retrievalURI, schemaElement) => {
|
---|
| 23 | if (typeof schemaElement.$id === 'undefined') {
|
---|
| 24 | return undefined;
|
---|
| 25 | }
|
---|
| 26 | const inherited$id = (0, _apidomCore.toValue)(schemaElement.meta.get('inherited$id'));
|
---|
| 27 | return (0, _ramda.reduce)((acc, $id) => {
|
---|
| 28 | return url.resolve(acc, url.sanitize(url.stripHash($id)));
|
---|
| 29 | }, retrievalURI, [...inherited$id, (0, _apidomCore.toValue)(schemaElement.$id)]);
|
---|
| 30 | };
|
---|
| 31 |
|
---|
| 32 | /**
|
---|
| 33 | * Cached version of SchemaElement.refract.
|
---|
| 34 | */
|
---|
| 35 | exports.resolveSchema$idField = resolveSchema$idField;
|
---|
| 36 | const refractToSchemaElement = element => {
|
---|
| 37 | if (refractToSchemaElement.cache.has(element)) {
|
---|
| 38 | return refractToSchemaElement.cache.get(element);
|
---|
| 39 | }
|
---|
| 40 | const refracted = _apidomNsOpenapi.SchemaElement.refract(element);
|
---|
| 41 | refractToSchemaElement.cache.set(element, refracted);
|
---|
| 42 | return refracted;
|
---|
| 43 | };
|
---|
| 44 | exports.refractToSchemaElement = refractToSchemaElement;
|
---|
| 45 | refractToSchemaElement.cache = new WeakMap();
|
---|
| 46 | const maybeRefractToSchemaElement = element => {
|
---|
| 47 | /**
|
---|
| 48 | * Conditional version of refractToSchemaElement, that acts as an identity
|
---|
| 49 | * function for all non-primitive Element instances.
|
---|
| 50 | */
|
---|
| 51 | if ((0, _apidomCore.isPrimitiveElement)(element)) {
|
---|
| 52 | return refractToSchemaElement(element);
|
---|
| 53 | }
|
---|
| 54 | return element;
|
---|
| 55 | };
|
---|
| 56 | exports.maybeRefractToSchemaElement = maybeRefractToSchemaElement; |
---|