import*as Sampler from"openapi-sampler";import{getSchema}from"./schema";import{isFormUrlEncoded,isJsonLike,isMultipartFormData,JsonPointer,mapValues}from"../utils";import{getExamples}from"./example";function generateExamples({parser:e,info:{encoding:a,schema:r},schema:i,mime:s,isRequestType:n,onlyRequiredInSamples:o,generatedSamplesMaxDepth:m}){const t={skipReadOnly:n,skipWriteOnly:!n,skipNonRequired:n&&o,maxSampleDepth:m};let p={};if(i&&i.oneOf)for(const r of i.oneOf){const n=Sampler.sample(r.rawSchema,t,e.definition);i.discriminatorProp&&"object"==typeof n&&n&&n[i.discriminatorProp]&&(n[i.discriminatorProp]=r.title),p[r.title]=getExamples({parser:e,infoOrRef:{value:n},mime:s,encoding:a})}else p=i?{default:getExamples({parser:e,infoOrRef:{value:Sampler.sample(r,t,e.definition)},mime:s,encoding:a})}:{default:{value:null,rawValue:"null"}};return p}export function getMediaType(e,a,r,i,s,{operation:n,type:o,response:m,absolutePointer:t=""}){let p,l;const d=i.schema&&getSchema({parser:e,schemaOrRef:i.schema,pointer:"",absolutePointer:JsonPointer.join(t,["content",a,"schema"]),options:s,deps:{operation:n,type:o,response:m}}),{onlyRequiredInSamples:c,generatedSamplesMaxDepth:f}=s,{encoding:u,examples:g,example:x}=i;return void 0!==g?p=mapValues(g,(r=>getExamples({parser:e,infoOrRef:r,mime:a,encoding:u}))):void 0!==x?p={default:getExamples({parser:e,infoOrRef:{value:e.deref(x).resolved},mime:a,encoding:u})}:isJsonLike(a)?p=generateExamples({parser:e,info:i,schema:d,mime:a,isRequestType:r,onlyRequiredInSamples:c,generatedSamplesMaxDepth:f}):(isFormUrlEncoded(a)||isMultipartFormData(a))&&(l=generateExamples({parser:e,info:i,schema:d,mime:a,isRequestType:r,onlyRequiredInSamples:c,generatedSamplesMaxDepth:f})),{examples:p,schema:d,name:a,isRequestType:r,formExamples:l,onlyRequiredInSamples:c,operation:n}}
//# sourceMappingURL=mediaType.js.map