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