source: node_modules/@swagger-api/apidom-ns-json-schema-draft-4/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.4 KB
Line 
1import { invokeArgs } from 'ramda-adjunct';
2import { visit, dereference, refract as baseRefract, dispatchRefractorPlugins } from '@swagger-api/apidom-core';
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', 'JSONSchema', '$visitor'],
8 plugins = [],
9 specificationObj = specification
10} = {}) => {
11 const element = baseRefract(value);
12 const resolvedSpec = dereference(specificationObj);
13
14 /**
15 * This is where generic ApiDOM becomes semantic (namespace applied).
16 * We don't allow consumers to hook into this translation.
17 * Though we allow consumers to define their onw plugins on already transformed ApiDOM.
18 */
19 const rootVisitor = invokeArgs(specPath, [], resolvedSpec);
20 // @ts-ignore
21 visit(element, rootVisitor, {
22 state: {
23 specObj: resolvedSpec
24 }
25 });
26
27 /**
28 * Running plugins visitors means extra single traversal === performance hit.
29 */
30 return dispatchRefractorPlugins(rootVisitor.element, plugins, {
31 toolboxCreator: createToolbox,
32 visitorOptions: {
33 keyMap,
34 nodeTypeGetter: getNodeType
35 }
36 });
37};
38export const createRefractor = specPath => (value, options = {}) => refract(value, {
39 specPath,
40 ...options
41});
42export default refract;
Note: See TracBrowser for help on using the repository browser.