"use strict";var __createBinding=this&&this.__createBinding||(Object.create?function(e,t,a,r){void 0===r&&(r=a);var i=Object.getOwnPropertyDescriptor(t,a);i&&!("get"in i?!t.__esModule:i.writable||i.configurable)||(i={enumerable:!0,get:function(){return t[a]}}),Object.defineProperty(e,r,i)}:function(e,t,a,r){void 0===r&&(r=a),e[r]=t[a]}),__setModuleDefault=this&&this.__setModuleDefault||(Object.create?function(e,t){Object.defineProperty(e,"default",{enumerable:!0,value:t})}:function(e,t){e.default=t}),__importStar=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(null!=e)for(var a in e)"default"!==a&&Object.prototype.hasOwnProperty.call(e,a)&&__createBinding(t,e,a);return __setModuleDefault(t,e),t};Object.defineProperty(exports,"__esModule",{value:!0}),exports.getMediaType=void 0;const Sampler=__importStar(require("openapi-sampler")),schema_1=require("./schema"),utils_1=require("../utils"),example_1=require("./example");function generateExamples({parser:e,info:{encoding:t,schema:a},schema:r,mime:i,isRequestType:n,onlyRequiredInSamples:s,generatedSamplesMaxDepth:o}){const l={skipReadOnly:n,skipWriteOnly:!n,skipNonRequired:n&&s,maxSampleDepth:o};let p={};if(r&&r.oneOf)for(const a of r.oneOf){const n=Sampler.sample(a.rawSchema,l,e.definition);r.discriminatorProp&&"object"==typeof n&&n&&n[r.discriminatorProp]&&(n[r.discriminatorProp]=a.title),p[a.title]=(0,example_1.getExamples)({parser:e,infoOrRef:{value:n},mime:i,encoding:t})}else p=r?{default:(0,example_1.getExamples)({parser:e,infoOrRef:{value:Sampler.sample(a,l,e.definition)},mime:i,encoding:t})}:{default:{value:null,rawValue:"null"}};return p}function getMediaType(e,t,a,r,i,{operation:n,type:s,response:o,absolutePointer:l=""}){let p,m;const u=r.schema&&(0,schema_1.getSchema)({parser:e,schemaOrRef:r.schema,pointer:"",absolutePointer:utils_1.JsonPointer.join(l,["content",t,"schema"]),options:i,deps:{operation:n,type:s,response:o}}),{onlyRequiredInSamples:c,generatedSamplesMaxDepth:d}=i,{encoding:f,examples:_,example:g}=r;return void 0!==_?p=(0,utils_1.mapValues)(_,(a=>(0,example_1.getExamples)({parser:e,infoOrRef:a,mime:t,encoding:f}))):void 0!==g?p={default:(0,example_1.getExamples)({parser:e,infoOrRef:{value:e.deref(g).resolved},mime:t,encoding:f})}:(0,utils_1.isJsonLike)(t)?p=generateExamples({parser:e,info:r,schema:u,mime:t,isRequestType:a,onlyRequiredInSamples:c,generatedSamplesMaxDepth:d}):((0,utils_1.isFormUrlEncoded)(t)||(0,utils_1.isMultipartFormData)(t))&&(m=generateExamples({parser:e,info:r,schema:u,mime:t,isRequestType:a,onlyRequiredInSamples:c,generatedSamplesMaxDepth:d})),{examples:p,schema:u,name:t,isRequestType:a,formExamples:m,onlyRequiredInSamples:c,operation:n}}exports.getMediaType=getMediaType;
//# sourceMappingURL=mediaType.js.map