source: node_modules/swagger-client/lib/resolver/strategies/openapi-3-1-apidom/normalize.js

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.2 KB
Line 
1"use strict";
2
3var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
4exports.__esModule = true;
5exports.pojoAdapter = exports.default = void 0;
6var _apidomCore = require("@swagger-api/apidom-core");
7var _apidomNsOpenapi = require("@swagger-api/apidom-ns-openapi-3-1");
8var _opId = _interopRequireDefault(require("../../../helpers/op-id.js"));
9/* eslint-disable camelcase */
10
11const normalize = element => {
12 if (!(0, _apidomCore.isObjectElement)(element)) return element;
13 if (element.hasKey('$$normalized')) return element;
14 const plugins = [(0, _apidomNsOpenapi.refractorPluginNormalizeOperationIds)({
15 operationIdNormalizer: (operationId, path, method) => (0, _opId.default)({
16 operationId
17 }, path, method, {
18 v2OperationIdCompatibilityMode: false
19 })
20 }), (0, _apidomNsOpenapi.refractorPluginNormalizeParameters)(), (0, _apidomNsOpenapi.refractorPluginNormalizeSecurityRequirements)(), (0, _apidomNsOpenapi.refractorPluginNormalizeServers)(), (0, _apidomNsOpenapi.refractorPluginNormalizeParameterExamples)(), (0, _apidomNsOpenapi.refractorPluginNormalizeHeaderExamples)()];
21 const normalized = (0, _apidomCore.dispatchRefractorPlugins)(element, plugins, {
22 toolboxCreator: _apidomNsOpenapi.createToolbox,
23 visitorOptions: {
24 keyMap: _apidomNsOpenapi.keyMap,
25 nodeTypeGetter: _apidomNsOpenapi.getNodeType
26 }
27 });
28 normalized.set('$$normalized', true);
29 return normalized;
30};
31
32/**
33 * This adapter allow to perform normalization on Plain Old JavaScript Objects.
34 * The function adapts the `normalize` function interface and is able to accept
35 * Plain Old JavaScript Objects and returns Plain Old JavaScript Objects.
36 */
37const pojoAdapter = normalizeFn => spec => {
38 if (spec != null && spec.$$normalized) return spec;
39 if (pojoAdapter.cache.has(spec)) return pojoAdapter.cache.get(spec);
40 const openApiElement = _apidomNsOpenapi.OpenApi3_1Element.refract(spec);
41 const normalized = normalizeFn(openApiElement);
42 const value = (0, _apidomCore.toValue)(normalized);
43 pojoAdapter.cache.set(spec, value);
44 return value;
45};
46exports.pojoAdapter = pojoAdapter;
47pojoAdapter.cache = new WeakMap();
48var _default = exports.default = normalize;
49/* eslint-enable camelcase */
Note: See TracBrowser for help on using the repository browser.