import w from"path";import{lintConfig as T,loadConfig as R,createConfigTypes as x}from"@redocly/openapi-core";import{safeParsePartial as E}from"../../safe-parse.js";import{formatConfigProblem as M}from"../../format-error.js";import{logger as m,readEnvVariable as j}from"../../../../utils/index.js";import{deepMerge as $}from"../../../../../shared/jsUtils.js";import{ExternalResolver as k}from"../../../../fs/utils/external-ref-resolver.js";import{resolveMutuallyExclusiveProps as A}from"../../resolve-mutual-exclusion.js";async function z(e,t,o,i){const v=(await t.getFileInfo(e))?.realRelativePath||e;async function C(){const s=new k(t);let n,u,a={};const b=w.join(t.cwd,v),h=await R({configPath:b,externalRefResolver:s,processRawConfig:l=>{a=l.parsed,n=l.document,u=l.resolvedRefMap}}),g=await i(a);if(g===void 0)return a;const y=[...n?.source?await T({config:h,document:{parsed:a,source:n.source},resolvedRefMap:u,externalConfigTypes:x(g,h)}):[],...n?.source?A(a,n?.source):[]];if(y.length>0)for(const l of y)o(new Error(M(l,t.cwd)));return a}const c=await t.exists(e)?await C():{},P=D(c),d=await i(c);let p=d?E(d,c):c;const{env:f}=p;if(f){const s=j("REDOCLY_ENV")||"development",n=f[s]||{};p=$(p,n)}const r=I(p,P);if(r.imports&&r.imports.length>0){m.warn("The 'imports' property is deprecated. Please use 'plugins' property instead.");const s=new Set([...r.plugins||[],...r.imports.map(n=>w.posix.join(n,"plugin.js"))]);r.plugins=Array.from(s),delete r.imports}return r.catalog&&(m.warn("The 'catalog' property is deprecated. Please use 'catalogClassic' property instead."),r.catalogClassic={...r.catalog},delete r.catalog),r}function D(e){if(!e.theme)return[];m.warn("The 'theme' property in redocly.yaml is deprecated. Please move all of the properties from 'theme' to the root of the config.");const t=[];for(const o of Object.keys(e.theme))e[o]==null?t.push(o):m.warn(`Detected both '${o}' and 'theme.${o}' properties in redocly.yaml. The 'theme.${o}' property will be ignored and needs to be removed or merged into the '${o}'.`);return t}function I(e,t){if(!e.theme||t.length===0)return e;const o={...e};for(const i of t)o[i]=e.theme[i];return delete o.theme,o}export{z as readAndValidateConfig};
