import{isDefinitionHidden as $}from"../utils/xmcp-utils";function h(t,o,r="docs"){return t.find(({info:e})=>e?.title?.toLowerCase().includes(o.toLowerCase())&&!$(e,r))}function x(t,o,r="docs"){return t.filter(({info:e})=>e?.title?.toLowerCase().includes(o.toLowerCase())&&!$(e,r))}function d(t,o){if(!o||!t?.startsWith("#/"))return;const r=t.slice(2).split("/");let e=o;for(const s of r)if(typeof e=="object"&&e!==null&&s in e)e=e[s];else return;return e}function l({schema:t,definition:o,visitedRefs:r=new Set,maxDepth:e=50,currentDepth:s=0}){if(!t)return;if(s>=e)return{type:"object",description:`Maximum resolution depth exceeded (${e})`};if("$ref"in t&&t.$ref){if(r.has(t.$ref))return{type:"object",description:`Circular reference detected: ${t.$ref}`,"x-circular-ref":t.$ref};const f=new Set(r);f.add(t.$ref);const u=d(t.$ref,o);return u?l({schema:u,definition:o,visitedRefs:f,maxDepth:e,currentDepth:s+1}):{type:"object",description:`Could not resolve reference: ${t.$ref}`,"x-unresolved-ref":t.$ref}}const n={...t};if(n.properties){const f={};for(const[u,i]of Object.entries(n.properties)){const m=l({schema:i,definition:o,visitedRefs:new Set(r),maxDepth:e,currentDepth:s+1});f[u]=m||i}n.properties=f}if(n.items&&typeof n.items=="object")if(Array.isArray(n.items))n.items=n.items.map(f=>l({schema:f,definition:o,visitedRefs:new Set(r),maxDepth:e,currentDepth:s+1})||f);else{const f=l({schema:n.items,definition:o,visitedRefs:new Set(r),maxDepth:e,currentDepth:s+1});f&&(n.items=f)}return["allOf","anyOf","oneOf"].forEach(f=>{const u=n[f];Array.isArray(u)&&(n[f]=u.reduce((i,m)=>{const p=l({schema:m,definition:o,visitedRefs:new Set(r),maxDepth:e,currentDepth:s+1});return p&&i.push(p),i},[]))}),n}function w({pathParams:t,opParams:o,definition:r}){return[...t,...o].reduce((e,s)=>{if(!s)return e;if("$ref"in s&&s.$ref){const n=d(s.$ref,r);return n&&e.push({...n,schema:"schema"in n&&n.schema?l({schema:n.schema,definition:r}):void 0}),e}return e.push({...s,schema:"schema"in s&&s.schema?l({schema:s.schema,definition:r}):void 0}),e},[])}function a(t,o){const r={...t};if(t.example!==void 0&&(r.example=t.example),!t.examples)return r;const e={};for(const[s,n]of Object.entries(t.examples))if("$ref"in n){const c=d(n.$ref,o);c&&(e[s]=c)}else e[s]=n;return r.examples=e,r}function y(t,o){if(!t)return;const r="$ref"in t&&t.$ref?d(t.$ref,o):t;if(!r)return;const e={...r};if("content"in r&&r.content){const s={};for(const[n,c]of Object.entries(r.content))s[n]={...a(c,o),schema:c.schema?l({schema:c.schema,definition:o}):void 0};e.content=s}return e}function b(t,o){return Object.entries(t).reduce((r,[e,s])=>{const n="$ref"in s&&s.$ref?d(s.$ref,o):s;if(!n)return r;const c={...n};if("content"in n&&n.content){const f={};for(const[u,i]of Object.entries(n.content))f[u]={...a(i,o),schema:i.schema?l({schema:i.schema,definition:o}):void 0};c.content=f}return r[e]=c,r},{})}export{x as findAllDefinitionsByName,h as findDefinitionByName,w as resolveParameters,d as resolveRef,y as resolveRequestBody,b as resolveResponses,l as resolveSchemaRefs};
