"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.mergeInMockServer=exports.getOperation=exports.isPayloadSample=void 0;const theme_1=require("@redocly/theme"),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){var a,n;const l=r.isWebhook,p={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:l,isCallback:Boolean(null==o?void 0:o.isCallback),isEvent:(null==o?void 0:o.isCallback)||l,name:(0,utils_1.getOperationName)(r),defaultExampleName:r.defaultSampleName,type:"operation",callbackId:null==o?void 0:o.id,href:i,get callbacks(){return Object.keys(r.callbacks||[]).map((o=>{var a;return(0,callback_1.getCallback)(e,o,null===(a=r.callbacks)||void 0===a?void 0:a[o],p.pointer,s,i,t)}))},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:p.isEvent,operation:p})))},get parameters(){let t=(0,utils_1.mergeParams)(e,r.pathParameters,r.parameters,{pathPointer:utils_1.JsonPointer.dirName(p.pointer),operationPointer:p.pointer}).map((({paramOrRef:r,pointer:t})=>(0,field_1.getField)(e,r,t,s,{operation:p,type:"request"})));return s.sortRequiredPropsFirst&&(t=(0,utils_1.sortByRequired)(t)),(0,utils_1.sortByDeprecated)(t)}};(null==o?void 0:o.isCallback)?(p.security=(r.security||[]).map((r=>(0,security_1.getSecurityRequirement)({requirement:r,parser:e}))),p.servers=(0,utils_1.normalizeServers)("",r.servers||r.pathServers||[]),p.id=(0,theme_1.removeLeadingSlash)(i)):(p.id=(0,utils_1.getOperationId)(r,t),p.href=p.href||(0,operation_1.getHref)(p),p.security=(r.security||e.definition.security||[]).map((r=>(0,security_1.getSecurityRequirement)({requirement:r,parser:e}))),p.servers=(0,utils_1.normalizeServers)(e.definitionUrl,mergeInMockServer(r.servers||r.pathServers||e.definition.servers||[],s.mockServer))),s.showExtensions&&(p.extensions=(0,utils_1.extractExtensions)(r,s.showExtensions)),p.requestBody=r.requestBody&&(0,request_1.getRequestBody)({parser:e,infoOrRef:r.requestBody,options:s,operation:p,isEvent:p.isEvent});const u=null===(a=p.requestBody)||void 0===a?void 0:a.content;return p.payload={lang:"Payload",source:"",requestBodyContent:(null==u?void 0:u.hasSample)?u:void 0},p.definitionSamples=r["x-codeSamples"]||[],p.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"}))))||[],p.hasSamples=(null==u?void 0:u.hasSample)||p.definitionSamples.length>0,p.hideReplay=!0===r["x-hideReplay"],p}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}}exports.isPayloadSample=isPayloadSample,exports.getOperation=getOperation,exports.mergeInMockServer=mergeInMockServer;
//# sourceMappingURL=operation.js.map