import{isObject as k}from"@redocly/theme/core/openapi";function p(e,r){Object.keys(r).length!==0&&(h(r)?(b(e,r),y(e,r.security),d(e,r.envVariables),v(e,r.serverVariables)):j(e,r))}function O(e,r){if(!r)return;const{in:s,name:t}=e;if(h(r)){const a=r,c={header:a.headers,query:a.query,path:a.path,cookie:a.cookie};s&&c[s]?.[t]&&(e.example=c[s][t])}else Object.entries(r).forEach(([a,c])=>{const f=c;if(!f)return;const n={header:f.headers,query:f.query,path:f.path,cookie:f.cookie};s&&n[s]?.[t]&&(e.serverValues||(e.serverValues={}),e.serverValues[a]={example:n[s][t]})})}function b(e,r,s){if(!e.requestBody||!r?.body)return;const t=e.requestBody.content;if(!t?.mediaTypes)return;const a=(c,f)=>{c[f]&&Object.keys(c[f]).forEach(n=>{const o=c[f]?.[n]?.value;let l;if(k(o)?l=u(o,r.body):l=r.body,!!l)if(s){const i=c[f][n];i.serverValues||(i.serverValues={}),i.serverValues[s]={value:l,rawValue:l},c[f][n]={...i,mime:c.name}}else c[f][n]={value:l,rawValue:l,mime:c.name}})};for(const c of t.mediaTypes)a(c,"examples"),a(c,"formExamples");return e}function y(e,r,s){!r||!e.security.length||e.security.forEach(t=>{s?t.schemes.forEach(a=>{a.serverValues||(a.serverValues={});const c=V(a,r);a.serverValues[s]=c}):t.schemes.forEach(a=>{const c=V(a,r);Object.assign(a,c)})})}function j(e,r){e.servers.forEach(s=>{if(r[s.url]){const t=r[s.url];t&&(b(e,t,s.url),y(e,t.security,s.url),d(e,t.envVariables,s.url),v(e,t.serverVariables,s.url))}})}function d(e,r,s){!r||Object.keys(r).length===0||(e.envVariables||(e.envVariables={}),s?(e.envVariables.serverValues||(e.envVariables.serverValues={}),e.envVariables.serverValues[s]={...e.envVariables.serverValues[s],...r}):e.envVariables.values={...e.envVariables.values,...r})}function v(e,r,s){if(!(!r||Object.keys(r).length===0))if(s){const t=e.servers.find(a=>a.url===s);if(t){t.variables||(t.variables={});for(const[a,c]of Object.entries(r))t.variables[a]&&(t.variables[a].default=c)}}else e.servers.forEach(t=>{t.variables||(t.variables={});for(const[a,c]of Object.entries(r))t.variables[a]&&(t.variables[a].default=c)})}function h(e){return!e||typeof e!="object"?!1:"headers"in e||"body"in e||"query"in e||"path"in e||"cookie"in e||"security"in e||"envVariables"in e||"serverVariables"in e}function u(e,r){if(!e||typeof e!="object")return r;if(Array.isArray(e)&&Array.isArray(r)){if(e.length>0&&typeof e[0]=="object"&&e[0]!==null){const t=Object.keys(e[0]),a=r.filter(c=>typeof c!="object"||c===null?!1:t.some(f=>f in c)&&Object.keys(c).every(f=>t.includes(f)));return a.length>0?a:e}return r}const s=Array.isArray(e)?[...e]:{...e};for(const[t,a]of Object.entries(r))t in e&&(Array.isArray(e[t])||typeof a=="object"&&a!==null&&typeof e[t]=="object"?s[t]=u(e[t],a):s[t]=a);return s}function V(e,r){const s=r?.[e.id]||r?.default||{},t={"x-defaultAccessToken":s.token?.access_token,"x-defaultTokenType":s.token?.token_type||"Bearer","x-defaultClientId":s.client_id,"x-defaultClientSecret":s.client_secret,scopes:s.scopes||e.scopes};return e.type==="http"&&e.scheme==="basic"?(t["x-defaultUsername"]=s.username,t["x-defaultPassword"]=s.password,delete t["x-defaultAccessToken"],delete t["x-defaultTokenType"]):e.type==="oauth2"&&!s.token?.access_token&&(delete t["x-defaultAccessToken"],delete t["x-defaultTokenType"]),t}export{V as createSecurityUpdates,h as isDirectRequestValues,d as updateEnvVariablesWithUserValues,u as updateObjectProperties,p as updateOperationWithRequestValues,j as updateOperationWithServerUserValues,O as updateParametersWithUserValues,b as updateRequestBodyWithUserValues,y as updateSecurityWithUserValues,v as updateServerVariablesWithUserValues};
