import{configure,removeLeadingSlash}from"@redocly/theme";import{REDOCLY_TEAMS_RBAC}from"@redocly/config";import{extractExtensions,getOperationId,getOperationName,getStatusCodeType,getValueFromMdParsedExtension,isStatusCode,JsonPointer,mergeParams,normalizeServers,sortByDeprecated,sortByRequired,updateOperationWithRequestValues,updateParametersWithUserValues}from"../utils";import{getCallback}from"./callback";import{getField}from"./field";import{getRequestBody}from"./request";import{getSecurity}from"./security";import{getResponse}from"./response";import{getHref}from"../services/menu/operation";export function isPayloadSample(e){return"Payload"===e.lang&&"requestBodyContent"in e}export function getOperation(e,r,t,o,s,a,i){var n,l,p;const d=r.isWebhook,u={operationDefinition:r,parent:t,pointer:r.pointer,description:getValueFromMdParsedExtension(r,"description"),externalDocs:r.externalDocs,deprecated:!!r.deprecated,httpVerb:r.httpVerb,operationId:r.operationId,path:r.pathName,isWebhook:d,isCallback:Boolean(null==a?void 0:a.isCallback),isEvent:(null==a?void 0:a.isCallback)||d,name:getOperationName(r),defaultExampleName:r.defaultSampleName,[REDOCLY_TEAMS_RBAC]:r[REDOCLY_TEAMS_RBAC]||(null==t?void 0:t[REDOCLY_TEAMS_RBAC]),type:"operation",callbackId:null==a?void 0:a.id,href:s,get callbacks(){return Object.keys(r.callbacks||[]).map((a=>{var n;return getCallback(e,a,null===(n=r.callbacks)||void 0===n?void 0:n[a],u.pointer,o,s,t,i)}))},get responses(){let t=!1;return Object.keys(r.responses||[]).filter((e=>"default"===e||("success"===getStatusCodeType(e)&&(t=!0),isStatusCode(e)))).map((s=>getResponse({parser:e,code:s,defaultAsError:t,infoOrRef:r.responses[s],options:o,isEvent:u.isEvent,operation:u})))},get parameters(){return processParameters(e,r,u,o,f)}};if(null==a?void 0:a.isCallback)u.security=getSecurity(r.security,e),u.servers=normalizeServers("",r.servers||r.pathServers||[]),u.id=removeLeadingSlash(s);else{u.id=getOperationId(r,t),u.href=u.href||getHref(u),u.security=getSecurity(r.security||e.definition.security,e);const s=r.servers||((null===(n=r.pathServers)||void 0===n?void 0:n.length)?r.pathServers:null)||e.definition.servers||[];u.servers=normalizeServers(e.definitionUrl,mergeInMockServer(s,o.mockServer))}o.showExtensions&&(u.extensions=extractExtensions(r,o.showExtensions)),u.requestBody=r.requestBody?getRequestBody({parser:e,infoOrRef:r.requestBody,options:o,operation:u,isEvent:u.isEvent}):void 0;const c=null===(l=u.requestBody)||void 0===l?void 0:l.content;u.payload={lang:"Payload",source:"",requestBodyContent:(null==c?void 0:c.hasSample)?c:void 0},u.definitionSamples=r["x-codeSamples"]||[],u.badges=(null===(p=r["x-badges"])||void 0===p?void 0:p.map((({name:e,color:r,position:t})=>({name:e,color:r||"var(--color-info-base)",position:t||"after"}))))||[],u.hasSamples=(null==c?void 0:c.hasSample)||u.definitionSamples.length>0,u.hideReplay=!0===r["x-hideReplay"];const m={userClaims:i,operation:{operationId:u.operationId,name:u.name,path:u.path,href:u.href,method:u.httpVerb},servers:u.servers},f=(configure(m)||{}).requestValues||{};return updateOperationWithRequestValues(u,f),u}function processParameters(e,r,t,o,s){let a=mergeParams(e,r.pathParameters,r.parameters,{pathPointer:JsonPointer.dirName(t.pointer),operationPointer:t.pointer}).map((({paramOrRef:r,pointer:a})=>{const i=getField(e,r,a,o,{operation:t,type:"request"});return updateParametersWithUserValues(i,s),i}));return o.sortRequiredPropsFirst&&(a=sortByRequired(a)),sortByDeprecated(a)}export function mergeInMockServer(e,r){if(!r)return e;const t={url:r.url,description:r.description};switch(r.position){case"first":return[t,...e];case"last":return[...e,t];case"replace":return[t];default:return e}}
//# sourceMappingURL=operation.js.map