"use strict";var __awaiter=this&&this.__awaiter||function(e,n,t,o){return new(t||(t=Promise))((function(r,i){function c(e){try{u(o.next(e))}catch(e){i(e)}}function a(e){try{u(o.throw(e))}catch(e){i(e)}}function u(e){var n;e.done?r(e.value):(n=e.value,n instanceof t?n:new t((function(e){e(n)}))).then(c,a)}u((o=o.apply(e,n||[])).next())}))};Object.defineProperty(exports,"__esModule",{value:!0}),exports.convertSwagger2OpenAPI=exports.loadAndBundleDefinition=void 0;const bundle_1=require("@redocly/openapi-core/lib/bundle"),config_1=require("@redocly/openapi-core/lib/config/config"),swagger2openapi_1=require("swagger2openapi"),theme_1=require("@redocly/theme"),createParsedDocument_1=require("./createParsedDocument");function loadAndBundleDefinition(e){return __awaiter(this,void 0,void 0,(function*(){const n=new config_1.Config({}),t={config:n,base:theme_1.IS_BROWSER?window.location.href:process.cwd()};theme_1.IS_BROWSER&&(n.resolve.http.customFetch=global.fetch),"object"==typeof e&&null!==e?t.doc=(0,createParsedDocument_1.createParsedDocument)(e):t.ref=e;const{bundle:{parsed:o}}=yield(0,bundle_1.bundle)(t);return void 0!==o.swagger?convertSwagger2OpenAPI(o):o}))}function convertSwagger2OpenAPI(e){return e.paths||(e.paths={}),new Promise(((n,t)=>(0,swagger2openapi_1.convertObj)(e,{patch:!0,warnOnly:!0,text:"{}",anchors:!0},((e,o)=>{if(e)return t(e);n(null==o?void 0:o.openapi)}))))}exports.loadAndBundleDefinition=loadAndBundleDefinition,exports.convertSwagger2OpenAPI=convertSwagger2OpenAPI;
//# sourceMappingURL=loadAndBundleSpec.js.map