package.es.adapter.mjs Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of apidom-parser-adapter-api-design-systems-json Show documentation
Show all versions of apidom-parser-adapter-api-design-systems-json Show documentation
Parser adapter for parsing JSON documents into API Design Systems namespace.
import { propOr, omit } from 'ramda';
import { isNotUndefined } from 'ramda-adjunct';
import { createNamespace } from '@swagger-api/apidom-core';
import { parse as parseJSON, detect as detectJSON } from '@swagger-api/apidom-parser-adapter-json';
import apiDesignSystemsNamespace, { MainElement } from '@swagger-api/apidom-ns-api-design-systems';
export { default as mediaTypes } from "./media-types.mjs";
export const detectionRegExp = /"version"\s*:\s*"(?2021-05-07)"/;
export const detect = async source => detectionRegExp.test(source) && (await detectJSON(source));
export const parse = async (source, options = {}) => {
const refractorOpts = propOr({}, 'refractorOpts', options);
const parserOpts = omit(['refractorOpts'], options);
const parseResultElement = await parseJSON(source, parserOpts);
const {
result
} = parseResultElement;
if (isNotUndefined(result)) {
const mainElement = MainElement.refract(result, refractorOpts);
mainElement.classes.push('result');
parseResultElement.replaceResult(mainElement);
}
return parseResultElement;
};
export const namespace = createNamespace(apiDesignSystemsNamespace);