import f from"node:path";import{OPENAPI_SHARED_DATA_PREFIX as p}from"../../../constants/plugins/openapi-docs.js";import{getNodeAttribute as A}from"../../../../markdoc/helpers/get-node-attribute.js";import{setNodeAttributeValue as w}from"../../../../markdoc/helpers/set-node-attribute-value.js";import{isOpenapiDoc as d}from"../../openapi-docs/is-openapi-doc.js";import{MdResolveError as a}from"./md-resolve-error.js";import{getLinkOriginalAttrName as g}from"./utils.js";async function O(r,t,e,{context:n}){const s=g(t);let o=r[s]||A(r,t);if(o||await d(e,n)&&(o=f.basename(e)),r[s]=o,!o)return;const i=f.posix.join(f.posix.dirname(e),o),m=p+i;if(w(r,t,m),!n.fs.exists(i))throw new a(`Definition file ${i} does not exist`,{rawLink:i});if(await n.isPathIgnored(i))throw new a(`Definition file ${i} is ignored in config`,{rawLink:i});return{sharedDataId:m}}export{O as resolveOpenApiRef};
