function $(e,o,s){if(!o)return;const n=o.toLowerCase();if(s)return e[`${n}@${s}`];const t=Object.values(e).filter(({name:r})=>r.toLowerCase()===n);if(t.length){if(t.length>1){const r=t.map(({version:c})=>c||"(no version)").join(", ");throw new Error(`Multiple versions of "${o}" found: ${r}. Specify a version to disambiguate.`)}return t[0]}}function v(e,o){return Object.values(e).filter(({name:s})=>s.toLowerCase().includes(o.toLowerCase()))}function d(e,o){if(!o||!e?.startsWith("#/"))return;const s=e.slice(2).split("/");let n=o;for(const t of s)if(typeof n=="object"&&n!==null&&t in n)n=n[t];else return;return n}function l({schema:e,definition:o,visitedRefs:s=new Set,maxDepth:n=50,currentDepth:t=0}){if(!e)return;if(t>=n)return{type:"object",description:`Maximum resolution depth exceeded (${n})`};if("$ref"in e&&e.$ref){if(s.has(e.$ref))return{type:"object",description:`Circular reference detected: ${e.$ref}`,"x-circular-ref":e.$ref};const f=new Set(s);f.add(e.$ref);const u=d(e.$ref,o);return u?l({schema:u,definition:o,visitedRefs:f,maxDepth:n,currentDepth:t+1}):{type:"object",description:`Could not resolve reference: ${e.$ref}`,"x-unresolved-ref":e.$ref}}const r={...e};if(r.properties){const f={};for(const[u,i]of Object.entries(r.properties)){const p=l({schema:i,definition:o,visitedRefs:new Set(s),maxDepth:n,currentDepth:t+1});f[u]=p||i}r.properties=f}if(r.items&&typeof r.items=="object")if(Array.isArray(r.items))r.items=r.items.map(f=>l({schema:f,definition:o,visitedRefs:new Set(s),maxDepth:n,currentDepth:t+1})||f);else{const f=l({schema:r.items,definition:o,visitedRefs:new Set(s),maxDepth:n,currentDepth:t+1});f&&(r.items=f)}return["allOf","anyOf","oneOf"].forEach(f=>{const u=r[f];Array.isArray(u)&&(r[f]=u.reduce((i,p)=>{const m=l({schema:p,definition:o,visitedRefs:new Set(s),maxDepth:n,currentDepth:t+1});return m&&i.push(m),i},[]))}),r}function h({pathParams:e,opParams:o,definition:s}){return[...e,...o].reduce((n,t)=>{if(!t)return n;if("$ref"in t&&t.$ref){const r=d(t.$ref,s);return r&&n.push({...r,schema:"schema"in r&&r.schema?l({schema:r.schema,definition:s}):void 0}),n}return n.push({...t,schema:"schema"in t&&t.schema?l({schema:t.schema,definition:s}):void 0}),n},[])}function a(e,o){const s={...e};if(e.example!==void 0&&(s.example=e.example),!e.examples)return s;const n={};for(const[t,r]of Object.entries(e.examples))if("$ref"in r){const c=d(r.$ref,o);c&&(n[t]=c)}else n[t]=r;return s.examples=n,s}function w(e,o){if(!e)return;const s="$ref"in e&&e.$ref?d(e.$ref,o):e;if(!s)return;const n={...s};if("content"in s&&s.content){const t={};for(const[r,c]of Object.entries(s.content))t[r]={...a(c,o),schema:c.schema?l({schema:c.schema,definition:o}):void 0};n.content=t}return n}function x(e,o){return Object.entries(e).reduce((s,[n,t])=>{const r="$ref"in t&&t.$ref?d(t.$ref,o):t;if(!r)return s;const c={...r};if("content"in r&&r.content){const f={};for(const[u,i]of Object.entries(r.content))f[u]={...a(i,o),schema:i.schema?l({schema:i.schema,definition:o}):void 0};c.content=f}return s[n]=c,s},{})}export{v as filterApiDescriptionsByName,$ as findApiDescriptionByNameAndVersion,h as resolveParameters,d as resolveRef,w as resolveRequestBody,x as resolveResponses,l as resolveSchemaRefs};
