import{removeLeadingSlash}from"@redocly/theme";import{extractExtensions,getOperationId,getOperationName,getStatusCodeType,getValueFromMdParsedExtension,isStatusCode,JsonPointer,mergeParams,normalizeServers,sortByDeprecated,sortByRequired}from"../utils";import{getCallback}from"./callback";import{getField}from"./field";import{getRequestBody}from"./request";import{getSecurityRequirement}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,i,s){var a,n;const p=r.isWebhook,l={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:p,isCallback:Boolean(null==s?void 0:s.isCallback),isEvent:(null==s?void 0:s.isCallback)||p,name:getOperationName(r),defaultExampleName:r.defaultSampleName,type:"operation",callbackId:null==s?void 0:s.id,href:i,get callbacks(){return Object.keys(r.callbacks||[]).map((s=>{var a;return getCallback(e,s,null===(a=r.callbacks)||void 0===a?void 0:a[s],l.pointer,o,i,t)}))},get responses(){let t=!1;return Object.keys(r.responses||[]).filter((e=>"default"===e||("success"===getStatusCodeType(e)&&(t=!0),isStatusCode(e)))).map((i=>getResponse({parser:e,code:i,defaultAsError:t,infoOrRef:r.responses[i],options:o,isEvent:l.isEvent,operation:l})))},get parameters(){let t=mergeParams(e,r.pathParameters,r.parameters,{pathPointer:JsonPointer.dirName(l.pointer),operationPointer:l.pointer}).map((({paramOrRef:r,pointer:t})=>getField(e,r,t,o,{operation:l,type:"request"})));return o.sortRequiredPropsFirst&&(t=sortByRequired(t)),sortByDeprecated(t)}};(null==s?void 0:s.isCallback)?(l.security=(r.security||[]).map((r=>getSecurityRequirement({requirement:r,parser:e}))),l.servers=normalizeServers("",r.servers||r.pathServers||[]),l.id=removeLeadingSlash(i)):(l.id=getOperationId(r,t),l.href=l.href||getHref(l),l.security=(r.security||e.definition.security||[]).map((r=>getSecurityRequirement({requirement:r,parser:e}))),l.servers=normalizeServers(e.definitionUrl,mergeInMockServer(r.servers||r.pathServers||e.definition.servers||[],o.mockServer))),o.showExtensions&&(l.extensions=extractExtensions(r,o.showExtensions)),l.requestBody=r.requestBody&&getRequestBody({parser:e,infoOrRef:r.requestBody,options:o,operation:l,isEvent:l.isEvent});const d=null===(a=l.requestBody)||void 0===a?void 0:a.content;return l.payload={lang:"Payload",source:"",requestBodyContent:(null==d?void 0:d.hasSample)?d:void 0},l.definitionSamples=r["x-codeSamples"]||[],l.badges=(null===(n=r["x-badges"])||void 0===n?void 0:n.map((({name:e,color:r,position:t})=>({name:e,color:r||"var(--color-info-base)",position:t||"after"}))))||[],l.hasSamples=(null==d?void 0:d.hasSample)||l.definitionSamples.length>0,l.hideReplay=!0===r["x-hideReplay"],l}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