test-openapi
Version:
Automated client requests
53 lines (40 loc) • 1.48 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:true});exports.normalizeResponses=void 0;var _lodash=require("lodash");
var _json_schema=require("./json_schema.js");
var _content_negotiation=require("./content_negotiation.js");
const normalizeResponses=function({
spec,
operation,
operation:{responses}})
{
return(0,_lodash.mapValues)(responses,(response)=>
normalizeResponse({response,spec,operation}));
};exports.normalizeResponses=normalizeResponses;
const normalizeResponse=function({response,spec,operation}){
const body=getResponseBody({response});
const headers=getResponseHeaders({response,spec,operation});
return{body,...headers};
};
const getResponseBody=function({response:{schema={}}}){
return(0,_json_schema.normalizeSchema)({schema});
};
const getResponseHeaders=function({
response:{headers={}},
spec,
operation})
{
const headersA=(0,_lodash.mapValues)(headers,getResponseHeader);
const contentNegotiations=(0,_content_negotiation.getNegotiationsResponse)({spec,operation});
const headersB={...contentNegotiations,...headersA};
const headersC=(0,_lodash.mapKeys)(headersB,normalizeHeaderKey);
return headersC;
};
const getResponseHeader=function(value){
const schema=(0,_lodash.omit)(value,"collectionFormat");
const schemaA=(0,_json_schema.normalizeSchema)({schema});
return schemaA;
};
const normalizeHeaderKey=function(value,name){
const nameA=name.toLowerCase();
return`headers.${nameA}`;
};
//# sourceMappingURL=response.js.map
;