source: node_modules/@swagger-api/apidom-reference/cjs/resolve/strategies/openapi-3-1/util.cjs

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: 2.4 KB
Line 
1"use strict";
2
3var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
4exports.__esModule = true;
5exports.resolveSchema$refField = exports.resolveSchema$idField = exports.refractToSchemaElement = exports.maybeRefractToSchemaElement = void 0;
6var _ramda = require("ramda");
7var _apidomCore = require("@swagger-api/apidom-core");
8var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-1");
9var url = _interopRequireWildcard(require("../../../util/url.cjs"));
10const 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};
21exports.resolveSchema$refField = resolveSchema$refField;
22const 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 */
35exports.resolveSchema$idField = resolveSchema$idField;
36const 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};
44exports.refractToSchemaElement = refractToSchemaElement;
45refractToSchemaElement.cache = new WeakMap();
46const 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};
56exports.maybeRefractToSchemaElement = maybeRefractToSchemaElement;
Note: See TracBrowser for help on using the repository browser.