import{isPrimitive}from"@redocly/theme";export function convertOperationToReplayValue(e,n,i,t){var a,r;const o=(null==t?void 0:t.activeMimeName)||"application/json";return{name:e.name,method:e.httpVerb,parameters:convertParameters(e.parameters,null==i?void 0:i.requestValues),body:convertRequestBody(e.requestBody,n,(null===(a=null==i?void 0:i.requestValues)||void 0===a?void 0:a.body)?{[o]:null===(r=null==i?void 0:i.requestValues)||void 0===r?void 0:r.body}:void 0),path:e.path,servers:e.servers,security:convertRequestSecurity(e.security)}}function convertParameters(e,n){const i=new Set,t=e.map((e=>{var t;return i.add(e.in+":"+e.name),{name:e.name,in:e.in,required:e.required,description:e.description,example:(null===(t=null==n?void 0:n[String(e.in)])||void 0===t?void 0:t[e.name])||e.example,schema:e.schema}}));for(const[e,a]of Object.entries(n||{}))for(const[n,r]of Object.entries(a||{}))i.has(e+":"+n)||t.push({name:n,in:e,required:!1,description:"",example:String(r),schema:void 0});return t}function getInputType({type:e,format:n,enum:i}){return"string"!==e||"binary"!==n&&"base64"!==n?"object"===e?"multiline":i.length>0?"select":"text":"file"}function getFieldExamples(e,n){var i,t,a,r,o;const l=(null===(i=e[0])||void 0===i?void 0:i.example)||(null===(t=e[0])||void 0===t?void 0:t.examples);if(l)return l;if(null===(a=e.schema)||void 0===a?void 0:a.example)return e.schema.example;const m=(null===(r=null==n?void 0:n.default)||void 0===r?void 0:r.value)||(null===(o=null==n?void 0:n.default)||void 0===o?void 0:o.rawValue);return(null==m?void 0:m[e.name])?isPrimitive(null==m?void 0:m[e.name])?String(null==m?void 0:m[e.name]):JSON.stringify(null==m?void 0:m[e.name]):""}function convertRequestBody(e,n,i){var t;if(!e||!(null===(t=e.content)||void 0===t?void 0:t.mediaTypes)){if(!i)return;return{mediaTypes:Object.fromEntries(Object.entries(i).map((([e,n])=>[e,{name:e,examples:{default:{value:n}},schema:{},parameters:[]}])))}}return{required:e.required,mediaTypes:e.content.mediaTypes.reduce(((e,t)=>{var a,r;const o=t.schema,l=(null==i?void 0:i[t.name])?{default:{value:null==i?void 0:i[t.name],rawValue:null==i?void 0:i[t.name],mime:t.name}}:t.examples||t.formExamples;return e[t.name]={name:t.name,examples:l,schema:getBodySchema(null===(a=t.schema)||void 0===a?void 0:a.rawSchema,n),parameters:null===(r=null==o?void 0:o.fields)||void 0===r?void 0:r.map((e=>({inputType:getInputType(e.schema),name:e.name,example:getFieldExamples(e,l)})))},e}),{})}}function getBodySchema(e,n){if(e&&n)return Object.assign(Object.assign({},e),{components:(null==n?void 0:n.components)||{}})}export function convertRequestSecurity(e){if(e)return e.map((({schemes:e})=>e.map((e=>({id:e.id,type:e.type,in:e.in,openIdConnectUrl:e.openIdConnectUrl,scopes:e.scopes,scheme:e.scheme,name:e.name,flows:e.flows})))))}
//# sourceMappingURL=utils.js.map