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