import{REDOCLY_TEAMS_RBAC as h}from"@redocly/config";import{removeLeadingSlash as R}from"@redocly/theme/core/openapi";import{configure as k}from"@redocly/theme/ext/configure";import{extractExtensions as B,getOperationId as P,getOperationName as E,getStatusCodeType as C,getValueFromMdParsedExtension as O,isStatusCode as V,JsonPointer as I,mergeParams as T,normalizeServers as b,sortByDeprecated as i,sortByRequired as A,updateOperationWithRequestValues as N,updateParametersWithUserValues as W}from"../utils/index.js";import{getCallback as w}from"./callback.js";import{getField as F}from"./field.js";import{getRequestBody as M}from"./request.js";import{getSecurity as S}from"./security.js";import{getResponse as j}from"./response.js";import{getHref as L}from"../services/menu/operation.js";function ee(r){return r.lang==="Payload"&&"requestBodyContent"in r}function se(r,e,d,u,l,c,n,g){const m=e.isWebhook,s={operationDefinition:e,parent:d,pointer:e.pointer,description:O(e,"description"),externalDocs:e.externalDocs,deprecated:!!e.deprecated,httpVerb:e.httpVerb,operationId:e.operationId,path:e.pathName,isWebhook:m,isAdditionalOperation:e.isAdditionalOperation,isCallback:!!c?.isCallback,isEvent:c?.isCallback||m,name:E(e),defaultExampleName:e.defaultSampleName,[h]:e[h]||d?.[h],type:"operation",callbackId:c?.id,href:l,get callbacks(){return Object.keys(e.callbacks||[]).map(a=>w(r,a,e.callbacks?.[a],s.pointer,u,l,d,n))},get responses(){let a=!1;return Object.keys(e.responses||[]).filter(t=>t==="default"?!0:(C(t)==="success"&&(a=!0),V(t))).map(t=>j({parser:r,code:t,defaultAsError:a,infoOrRef:e.responses[t],options:u,isEvent:s.isEvent,operation:s}))},get parameters(){return U(r,e,s,u,f)}};if(c?.isCallback)s.security=S(e.security,r),s.servers=b("",e.servers||e.pathServers||[]),s.id=R(l);else{s.id=P(e,d),s.href=s.href||L(s),s.security=S(e.security||r.definition.security,r);const a=e.servers||(e.pathServers?.length?e.pathServers:null)||r.definition.servers||[];s.servers=b(r.definitionUrl,_(a,u.mockServer))}u.showExtensions&&(s.extensions=B(e,u.showExtensions)),s.requestBody=e.requestBody?M({parser:r,infoOrRef:e.requestBody,options:u,operation:s,isEvent:s.isEvent}):void 0;const o=s.requestBody?.content;s.payload={lang:"Payload",source:"",requestBodyContent:o?.hasSample?o:void 0},s.definitionSamples=e["x-codeSamples"]||[];const x=(r.definition.tags||[]).filter(a=>a.kind==="badge"||a.kind==="audience"),y=e["x-badges"]?.map(({name:a,color:t,position:p})=>({name:a,color:t||"blue",position:p||"after"}))??[];if(e.tags)for(const a of e.tags){const t=x.find(p=>p.name===a);t&&y.push({name:t.summary??t.name,color:t.kind==="audience"?"grey":"blue",icon:t.kind==="audience"?"user-group":void 0,position:"after",description:t.description})}s.badges=y,s.hasSamples=o?.hasSample||s.definitionSamples.length>0,s.hideReplay=e["x-hideReplay"]===!0;const q={userClaims:n,info:r.definition.info||{},operation:{operationId:s.operationId,name:s.name,path:s.path,href:s.href,method:s.httpVerb},servers:s.servers},v=k(q)||{},f=g||v.requestValues||{};return N(s,f),s}function U(r,e,d,u,l){let c=T(r,e.pathParameters,e.parameters,{pathPointer:I.dirName(d.pointer),operationPointer:d.pointer}).map(({paramOrRef:n,pointer:g})=>{const m=F(r,n,g,u,{operation:d,type:"request"});return W(m,l),m});return u.sortRequiredPropsFirst&&(c=A(c)),i(c)}function _(r,e){if(!e)return r;const d={url:e.url,description:e.description};switch(e.position){case"first":return[d,...r];case"last":return[...r,d];case"replace":return[d];default:return r}}export{se as getOperation,ee as isPayloadSample,_ as mergeInMockServer};
