source: node_modules/@swagger-api/apidom-ns-openapi-3-1/es/refractor/index.mjs@ d24f17c

main
Last change on this file since d24f17c was d24f17c, checked in by Aleksandar Panovski <apano77@…>, 15 months ago

Initial commit

  • Property mode set to 100644
File size: 1.3 KB
Line 
1import { visit, dereference, refract as baseRefract, dispatchRefractorPlugins } from '@swagger-api/apidom-core';
2import { path } from 'ramda';
3import specification from "./specification.mjs";
4import { keyMap, getNodeType } from "../traversal/visitor.mjs";
5import createToolbox from "./toolbox.mjs";
6const refract = (value, {
7 specPath = ['visitors', 'document', 'objects', 'OpenApi', '$visitor'],
8 plugins = []
9} = {}) => {
10 const element = baseRefract(value);
11 const resolvedSpec = dereference(specification);
12
13 /**
14 * This is where generic ApiDOM becomes semantic (namespace applied).
15 * We don't allow consumers to hook into this translation.
16 * Though we allow consumers to define their onw plugins on already transformed ApiDOM.
17 */
18 const RootVisitorClass = path(specPath, resolvedSpec);
19 const rootVisitor = new RootVisitorClass({
20 specObj: resolvedSpec
21 });
22 visit(element, rootVisitor);
23
24 /**
25 * Running plugins visitors means extra single traversal === performance hit.
26 */
27 return dispatchRefractorPlugins(rootVisitor.element, plugins, {
28 toolboxCreator: createToolbox,
29 visitorOptions: {
30 keyMap,
31 nodeTypeGetter: getNodeType
32 }
33 });
34};
35export const createRefractor = specPath => (value, options = {}) => refract(value, {
36 specPath,
37 ...options
38});
39export default refract;
Note: See TracBrowser for help on using the repository browser.