package.cjs.adapter.cjs 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.
"use strict";
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault").default;
var _interopRequireWildcard = require("@babel/runtime-corejs3/helpers/interopRequireWildcard").default;
exports.__esModule = true;
exports.parse = exports.namespace = exports.mediaTypes = exports.detectionRegExp = exports.detect = void 0;
var _ramda = require("ramda");
var _ramdaAdjunct = require("ramda-adjunct");
var _apidomCore = require("@swagger-api/apidom-core");
var _apidomParserAdapterJson = require("@swagger-api/apidom-parser-adapter-json");
var _apidomNsApiDesignSystems = _interopRequireWildcard(require("@swagger-api/apidom-ns-api-design-systems"));
var _mediaTypes = _interopRequireDefault(require("./media-types.cjs"));
exports.mediaTypes = _mediaTypes.default;
const detectionRegExp = exports.detectionRegExp = /"version"\s*:\s*"(?2021-05-07)"/;
const detect = async source => detectionRegExp.test(source) && (await (0, _apidomParserAdapterJson.detect)(source));
exports.detect = detect;
const parse = async (source, options = {}) => {
const refractorOpts = (0, _ramda.propOr)({}, 'refractorOpts', options);
const parserOpts = (0, _ramda.omit)(['refractorOpts'], options);
const parseResultElement = await (0, _apidomParserAdapterJson.parse)(source, parserOpts);
const {
result
} = parseResultElement;
if ((0, _ramdaAdjunct.isNotUndefined)(result)) {
const mainElement = _apidomNsApiDesignSystems.MainElement.refract(result, refractorOpts);
mainElement.classes.push('result');
parseResultElement.replaceResult(mainElement);
}
return parseResultElement;
};
exports.parse = parse;
const namespace = exports.namespace = (0, _apidomCore.createNamespace)(_apidomNsApiDesignSystems.default);