import a from"node:path";import{bundle as b,createConfig as R}from"@redocly/openapi-core";import{getNodeAttribute as v}from"../markdoc/helpers/get-node-attribute.js";import{setNodeAttributeValue as c}from"../markdoc/helpers/set-node-attribute-value.js";import{ExternalResolver as w}from"../../../fs/utils/external-ref-resolver.js";import{formatBundleFromMarkdocError as g}from"../errors.js";import{MdResolveError as h}from"./md-resolve-error.js";async function k(o,e,t,{context:p,actions:f}){const r=v(o,e),s=f.contentDir;if(typeof r!="object"||!r)return;const n=a.resolve(s,t),l={config:await R({}),base:a.dirname(n),doc:{source:{absoluteRef:n},parsed:JSON.parse(JSON.stringify({openapi:"3.1.0",components:{schemas:{__root:r}}}))},externalRefResolver:new w(p.fs)},{bundle:{parsed:d},problems:u}=await b(l);c(o,e+"Resolved",d);const i=u[0];if(!i)return{};const m=g(i,t,s);throw c(o,e+"ResolvedErrors",[m]),new h(m,{rawLink:""})}export{k as resolveJsonSchemaRef};
