"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.convertRequestSecurity=exports.convertOperationToReplayValue=void 0;const theme_1=require("@redocly/theme");function convertOperationToReplayValue(e,n,t,r){var i,o;const a=(null==r?void 0:r.activeMimeName)||"application/json";return{name:e.name,method:e.httpVerb,parameters:convertParameters(e.parameters,null==t?void 0:t.requestValues),body:convertRequestBody(e.requestBody,n,(null===(i=null==t?void 0:t.requestValues)||void 0===i?void 0:i.body)?{[a]:null===(o=null==t?void 0:t.requestValues)||void 0===o?void 0:o.body}:void 0),path:e.path,servers:e.servers,security:convertRequestSecurity(e.security)}}function convertParameters(e,n){const t=new Set,r=e.map((e=>{var r;return t.add(e.in+":"+e.name),{name:e.name,in:e.in,required:e.required,description:e.description,example:(null===(r=null==n?void 0:n[String(e.in)])||void 0===r?void 0:r[e.name])||e.example,schema:e.schema}}));for(const[e,i]of Object.entries(n||{}))for(const[n,o]of Object.entries(i||{}))t.has(e+":"+n)||r.push({name:n,in:e,required:!1,description:"",example:String(o),schema:void 0});return r}function getInputType({type:e,format:n,enum:t}){return"string"!==e||"binary"!==n&&"base64"!==n?"object"===e?"multiline":t.length>0?"select":"text":"file"}function getFieldExamples(e,n){var t,r,i,o,a;const l=(null===(t=e[0])||void 0===t?void 0:t.example)||(null===(r=e[0])||void 0===r?void 0:r.examples);if(l)return l;if(null===(i=e.schema)||void 0===i?void 0:i.example)return e.schema.example;const u=(null===(o=null==n?void 0:n.default)||void 0===o?void 0:o.value)||(null===(a=null==n?void 0:n.default)||void 0===a?void 0:a.rawValue);return(null==u?void 0:u[e.name])?(0,theme_1.isPrimitive)(null==u?void 0:u[e.name])?String(null==u?void 0:u[e.name]):JSON.stringify(null==u?void 0:u[e.name]):""}function convertRequestBody(e,n,t){var r;if(!e||!(null===(r=e.content)||void 0===r?void 0:r.mediaTypes)){if(!t)return;return{mediaTypes:Object.fromEntries(Object.entries(t).map((([e,n])=>[e,{name:e,examples:{default:{value:n}},schema:{},parameters:[]}])))}}return{required:e.required,mediaTypes:e.content.mediaTypes.reduce(((e,r)=>{var i,o;const a=r.schema,l=(null==t?void 0:t[r.name])?{default:{value:null==t?void 0:t[r.name],rawValue:null==t?void 0:t[r.name],mime:r.name}}:r.examples||r.formExamples;return e[r.name]={name:r.name,examples:l,schema:getBodySchema(null===(i=r.schema)||void 0===i?void 0:i.rawSchema,n),parameters:null===(o=null==a?void 0:a.fields)||void 0===o?void 0:o.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)||{}})}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})))))}exports.convertOperationToReplayValue=convertOperationToReplayValue,exports.convertRequestSecurity=convertRequestSecurity;
//# sourceMappingURL=utils.js.map