package.es.refractor.index.mjs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apidom-ns-json-schema-draft-7 Show documentation
Show all versions of apidom-ns-json-schema-draft-7 Show documentation
JSON Schema Draft 7 namespace for ApiDOM.
import { invokeArgs } from 'ramda-adjunct';
import { visit, dereference, refract as baseRefract, dispatchRefractorPlugins } from '@swagger-api/apidom-core';
import specification from "./specification.mjs";
import { keyMap, getNodeType } from "../traversal/visitor.mjs";
import createToolbox from "./toolbox.mjs";
const refract = (value, {
specPath = ['visitors', 'document', 'objects', 'JSONSchema', '$visitor'],
plugins = [],
specificationObj = specification
} = {}) => {
const element = baseRefract(value);
const resolvedSpec = dereference(specificationObj);
/**
* This is where generic ApiDOM becomes semantic (namespace applied).
* We don't allow consumers to hook into this translation.
* Though we allow consumers to define their onw plugins on already transformed ApiDOM.
*/
const rootVisitor = invokeArgs(specPath, [], resolvedSpec);
// @ts-ignore
visit(element, rootVisitor, {
state: {
specObj: resolvedSpec
}
});
/**
* Run plugins only when necessary.
* Running plugins visitors means extra single traversal === performance hit.
*/
return dispatchRefractorPlugins(rootVisitor.element, plugins, {
toolboxCreator: createToolbox,
visitorOptions: {
keyMap,
nodeTypeGetter: getNodeType
}
});
};
export const createRefractor = specPath => (value, options = {}) => refract(value, {
specPath,
...options
});
export default refract;