class f{static#e=new Map;static resolveSchemaRefs(o,t,a=new Set){if(!o||typeof o!="object")return o;const e=o;if(e.$ref&&typeof e.$ref=="string"){const r=e.$ref;if(this.#e.has(r))return this.#e.get(r)??{};if(a.has(r))return{$ref:r};const c=this.#r(r);if(c){const h=t.definition.components?.schemas?.[c];if(h){const p=new Set(a);p.add(r);const m=this.resolveSchemaRefs(h,t,p);return this.#e.set(r,m),m}}return{$ref:r}}const s={...e};if(e.allOf&&Array.isArray(e.allOf)&&(s.allOf=e.allOf.map(r=>this.resolveSchemaRefs(r,t,a))),e.anyOf&&Array.isArray(e.anyOf)&&(s.anyOf=e.anyOf.map(r=>this.resolveSchemaRefs(r,t,a))),e.oneOf&&Array.isArray(e.oneOf)&&(s.oneOf=e.oneOf.map(r=>this.resolveSchemaRefs(r,t,a))),e.not&&(s.not=this.resolveSchemaRefs(e.not,t,a)),Array.isArray(e.items)?s.items=e.items.map(r=>this.resolveSchemaRefs(r,t,a)):typeof e.items=="object"&&(s.items=this.resolveSchemaRefs(e.items,t,a)),e.additionalProperties&&typeof e.additionalProperties=="object"&&(s.additionalProperties=this.resolveSchemaRefs(e.additionalProperties,t,a)),e.properties&&typeof e.properties=="object"){s.properties={};for(const[r,c]of Object.entries(e.properties))s.properties[r]=this.resolveSchemaRefs(c,t,a)}if(e.patternProperties&&typeof e.patternProperties=="object"){s.patternProperties={};for(const[r,c]of Object.entries(e.patternProperties))s.patternProperties[r]=this.resolveSchemaRefs(c,t,a)}return e.if&&(s.if=this.resolveSchemaRefs(e.if,t,a)),e.then&&(s.then=this.resolveSchemaRefs(e.then,t,a)),e.else&&(s.else=this.resolveSchemaRefs(e.else,t,a)),e.additionalItems&&typeof e.additionalItems=="object"&&(s.additionalItems=this.resolveSchemaRefs(e.additionalItems,t,a)),e.prefixItems&&Array.isArray(e.prefixItems)&&(s.prefixItems=e.prefixItems.map(r=>this.resolveSchemaRefs(r,t,a))),s}static clearSchemaCache(){this.#e.clear()}static#r=o=>{const t=o.match(/^#\/components\/schemas\/(.+)$/);return t?t[1]:null}}export{f as OpenapiSchemaResolver};
