import{REDOCLY_TEAMS_RBAC as m}from"@redocly/config";import{OpenApiSearchBuilder as h}from"./openapi-search-builder.js";import{getOneOfSchema as O}from"./utils.js";class y extends h{constructor(t,e,n){super(t,e,n)}addItem(t){try{return this.buildSearchDocument(t)}catch(e){console.error("Cannot add item to AI search indexer",e.message);return}}buildOperationDocument(t){const e=this.createOperationDocumentBase(t),n=e?.parameters?.find(i=>i.place==="request fields"&&i.name==="body"&&"oneOf"in i&&i.oneOf!==void 0);return n&&(n.required=t.requestBody?.required??!1),e}addSchema(t,e,n,i,s,u=[],o=new Set,d=0,c){if(!(!e||e.isCircular||d>this.options.generatedSamplesMaxDepth)){if(e.pointer){if(o.has(e.pointer))return;o.add(e.pointer)}for(const r of e.fields??[]){if(c?.has(r.name)||this.#t(e,r,s))continue;const a=this.createSchemaFieldParameter(r,e,i,n,u),f=this.getParameterId(a);if(t[f]!=null)continue;t[f]=a,this.addSchema(t,r.schema,n,i,s,[...u,r.name],o,d+1);const l=O(r.schema);l&&(a.oneOf=this.#e(l,{mediaType:n,place:i,isResponse:s,visited:o,level:d+1}))}if(e.items&&this.addSchema(t,e.items,n,i,s,u,o,d+1),d===0&&u.length===0&&e.oneOf){const r=this.#e(e,{mediaType:n,place:i,isResponse:s,visited:o,level:d+1});if(r){const a={name:"body",description:"",place:i,mediaType:n,path:[],type:e.displayType||"object",required:!1,example:void 0,enum:void 0,oneOf:r};t[this.getParameterId(a)]=a}}}}#t(t,e,n){return!!t[m]||e.kind==="additionalProperties"||!!e.schema?.readOnly&&!n||!!e.schema?.writeOnly&&n}#e(t,e){const{mediaType:n,place:i,isResponse:s,visited:u,level:o}=e,d=new Set((t.fields??[]).map(r=>r.name)),c=(t.oneOf??[]).map((r,a)=>{const f={};return this.addSchema(f,r,n,i,s,[],new Set(u),o,d),{title:r.title||`variant ${a+1}`,parameters:Object.values(f)}}).filter(r=>r.parameters.length>0);if(c.length!==0)return{discriminator:t.discriminatorProp,variants:c}}}export{y as AiSearchIndexer};
