import{normalizeOptions as y}from"@redocly/openapi-docs";import{buildCodeSamples as f}from"@redocly/openapi-docs/lib/services/code-samples/build-code-samples.js";import{getOperation as v}from"../../../../markdoc/helpers/get-operation/index.js";import{setNodeAttributeValue as O}from"../../../../markdoc/helpers/set-node-attribute-value.js";import{getMediaContentSamples as S}from"./helpers/get-media-content-samples.js";import{loadOpenapiBundle as b}from"./helpers/load-openapi-bundle.js";import{getOptionalAttribute as a}from"./utils.js";const h={curl:"shell",JavaScript:"javascript","Node.js":"javascript",Python:"python",Java:"java","Java8+Apache":"java","C#":"csharp","C#+Newtonsoft":"csharp",PHP:"php",Go:"go",Ruby:"ruby",R:"r"},C=(e,n)=>typeof n=="string"?n:String(e??"");async function K(e,n,w,{context:u}){const o=await b(e,u);if(!o)return;const m=a(e,"language"),r={exampleKey:a(e,"exampleKey"),mimeType:a(e,"mimeType"),parameters:a(e,"parameters"),requestBody:a(e,"requestBody"),environments:a(e,"environments"),environment:a(e,"environment")},c=m?{...o.rawOptions,codeSamples:{...o.rawOptions.codeSamples,languages:[{lang:m}]}}:o.rawOptions,i=y(c),s=v({definition:o.definition,options:c},{operationId:a(e,"operationId"),pointer:a(e,"pointer")},i,r);if(!s)return;const p=f(s,i,o.definition,r,C).map(t=>({lang:h[t.lang]??t.lang.toLowerCase(),title:t.label??t.lang,source:t.source})),g=i.codeSamples.languages??[],l=g.find(({lang:t})=>t==="Payload");if(l){const t=S(s.payload?.requestBodyContent,r.exampleKey,l.label??"Payload"),d=g.indexOf(l);p.splice(d,0,...t)}p.length&&O(e,n,p)}export{K as resolveOpenapiCodeSamples};
