import*as g from"@redocly/openapi-docs";import{REDOCLY_TEAMS_RBAC as o}from"@redocly/config";import{combineUrls as u}from"@redocly/theme/core/utils";import{removeMarkdownLinks as p,stripFormatting as i}from"./utils.js";const h=g.default||g;class P{parser;options;basePath;resultArray=[];constructor(e,t,n){this.parser=e,this.options=t,this.basePath=n}addItem(e){switch(e.type){case"tag":return this.addTag(e);case"operation":const t=h.getOperation(this.parser,e.operationDefinition,e.parent,{...this.options,internal_skipSamples:!0},e.href);return this.addOperation(t,e[o]);case"section":return this.addSection(e)}}addInfo(e,t){const n=this.basePath,a={id:n,url:n,text:i(p(e.description||"")),title:i(`${e.title} (${e.version})`),metadata:t};return this.resultArray.push(a),a}getResult(){return this.resultArray}getParameterId(e){return e.name.toString()+e.description+e.place}addOperation(e,t){if(e.type!=="operation")return;let n={};for(let r of e.parameters){if(r[o])continue;const s=r.schema?.example||r.example,c={name:r.name,description:i(p(r.description)),place:r.in+" parameters",mediaType:void 0,type:r.schema?.type.toString()||"unknown",deepLink:h.generateDeepLink(r),[o]:r[o],required:r.required,example:s?JSON.stringify(s):void 0,enum:r.schema?.enum?.length?r.schema.enum:void 0};n[this.getParameterId(c)]=c}this.addSchema(n,e.requestBody?.content?.mediaTypes[0]?.schema,e.requestBody?.content?.mediaTypes[0]?.name,"request fields",!1);for(let r of e.responses)this.addSchema(n,r.content?.mediaTypes[0]?.schema,r.content?.mediaTypes[0]?.name,`response ${r.code} fields`,!0);let a=u(this.basePath,e.href);const d={id:a,url:a,title:i(e.name),text:i(p(e.description||"")),httpMethod:e.httpVerb,httpPath:e.path,deprecated:e.deprecated,security:e.security.map(r=>r.schemes.map(s=>s.id)).flat().filter(Boolean),parameters:Object.values(n),badges:e.badges.length?e.badges:void 0,[o]:t};return this.resultArray.push(d),d}addSchema(e,t,n,a,d,r=[]){if(!(!t||t.isCircular)){if(t?.fields)for(let s of t.fields){if(t[o])continue;const c=r.concat([s.name]);if(s.kind==="additionalProperties"||s.schema?.readOnly&&!d||s.schema?.writeOnly&&d)continue;const m=s.schema?.example||s.example,l=s.schema?.enum,f={name:s.name,description:i(s.description),place:a,mediaType:n,path:c.slice(0,-1),deepLink:h.generateDeepLink(s),type:s.schema?.type.toString()||"unknown",required:s.required||t.schema.required?.includes(s.name)||!1,example:m?JSON.stringify(m):void 0,enum:l?.length?l:void 0},y=this.getParameterId(f);e[y]==null&&(e[y]=f,this.addSchema(e,s.schema,n,a,d,c))}t?.items&&this.addSchema(e,t.items,n,a,d,r)}}addTag(e){const t=u(this.basePath,e.href),n={id:t,url:t,text:i(p(e.description||"")),title:i(e.name)};return this.resultArray.push(n),n}addSection(e){const t=u(this.basePath,e.href),n={id:t,url:t,text:i(p(e.description||"")),title:i(e.name)};return this.resultArray.push(n),n}}export{P as SearchIndexer};
