test-openapi
Version:
Automated client requests
53 lines (33 loc) • 1.61 kB
JavaScript
;Object.defineProperty(exports,"__esModule",{value:true});exports.STATUS_REGEXP=exports.serializeStatus=exports.parseStatus=void 0;var _lodash=require("lodash");
var _error=require("../../../../errors/error.js");
var _sort=require("../../../../utils/sort.js");
var _range=require("./range.js");
var _valid=require("./valid.js");
var _normalize=require("./normalize.js");
const parseStatus=function({status,property}){
const statusA=String(status);
const statuses=statusA.split(/[\t-\r \xA0\u1680\u2000-\u200A\u2028\u2029\u202F\u205F\u3000\uFEFF]+/u);
const statusesA=(0,_lodash.uniq)(statuses);
const statusesB=(0,_range.parseRanges)({statuses:statusesA});
checkValidStatuses({statuses:statusesB,property});
return statusesB;
};exports.parseStatus=parseStatus;
const checkValidStatuses=function({statuses,property}){
const invalidStatuses=(0,_lodash.difference)(statuses,_valid.VALID_STATUSES);
if(invalidStatuses.length===0){
return;
}
const{value,statusesStr}=(0,_normalize.normalizeStatuses)(invalidStatuses);
const expected=_valid.VALID_STATUSES.map(Number);
throw new _error.TestOpenApiError(
`The task definition is invalid: those are not valid HTTP status codes: ${statusesStr}`,
{value,expected,property});
};
const serializeStatus=function({statuses}){
const statusesA=(0,_range.replaceByRanges)({statuses});
const statusesB=(0,_sort.sortArray)(statusesA);
const statusKey=statusesB.join(" ");
return statusKey;
};exports.serializeStatus=serializeStatus;
const STATUS_REGEXP=/^[1-5][0-9x]{2}/iu;exports.STATUS_REGEXP=STATUS_REGEXP;
//# sourceMappingURL=parse.js.map