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