import{isObject}from"#shared/guards.js";import matter from"#compiled/gray-matter/index.js";import{isArray}from"#runtime/connections/openapi-schema.js";function parseSpecDocument(e){try{return JSON.parse(e)}catch{}let n=e.replace(/^\uFEFF/,``);return matter(n.trimStart().startsWith(`---`)?n:`---\n${n}\n---`).data??{}}function extractServerUrl(t,r){let i=t.servers;if(isArray(i))for(let t of i){if(!isObject(t)||typeof t.url!=`string`||t.url.length===0)continue;let n=isObject(t.variables)?substituteServerVariables(t.url,t.variables):t.url;if(n.startsWith(`http://`)||n.startsWith(`https://`))return n;if(typeof r==`string`&&URL.canParse(r))try{return new URL(n,r).toString()}catch{}}}function substituteServerVariables(t,n){return t.replace(/\{([^}]+)\}/g,(t,r)=>{let i=n[r];return isObject(i)&&typeof i.default==`string`?i.default:t})}export{extractServerUrl,parseSpecDocument};