import S from"node:path";import{getNodeAttribute as f}from"../../../../markdoc/helpers/get-node-attribute.js";import{setNodeAttributeValue as i}from"../../../../markdoc/helpers/set-node-attribute-value.js";import{MdResolveError as a}from"./md-resolve-error.js";import{generateSampleFromSchema as g}from"./helpers/generate-sample-from-schema.js";import{formatBundleFromMarkdocError as k}from"../errors.js";import{dereferenceJsonSchemaRefs as E}from"./helpers/dereference-json-schema-refs.js";async function y(o,e,r,{context:p,actions:l}){const h=f(o,e),t=l.contentDir,d=S.resolve(t,r),s=await E({schemaOrRef:h,filePath:d,fs:p.fs});if(!s)return;const{schema:u,problems:w,oas:b}=s,m=w[0];if(m){const c=k(m,r,t);throw i(o,e+"ResolvedErrors",[c]),new a(c,{rawLink:""})}const R=f(o,"mode"),{value:v,error:n}=g(u,{mode:R,spec:b});if(i(o,e+"Resolved",v),n)throw new a(n,{rawLink:""})}export{y as resolveSampleFromJsonSchema};
