context.swagger.readAsJSON(function (error, schema) {
if (error) {
console.error("error reading swagger: " + error);
} else {
console.log(Number.isInteger(1));
schema.paths[context.get("api.operation.path")].parameters.forEach((x) => {
console.log(x);
switch (x.type) {
//maybe add try catch to fill body as wanted
case "float":
case "double":
if (
isNumeric(context.get(`request.parameters.${x.name}.values`)[0])
) {
context.set("message.body", "true");
}else{
throw new RangeError("Parameter" + x.name + " is not of the type " + x.type);
}
case "integer":
if (
isInteger(context.get(`request.parameters.${x.name}.values`)[0])
) {
context.set("message.body", "true");
}else{
throw new RangeError("Parameter" + x.name + " is not of the type " + x.type);
}
//set error
//break apic assembly
break;
case "boolean":
if (
isInteger(context.get(`request.parameters.${x.name}.values`)[0])
) {
context.set("message.body", "true");
}else{
throw new RangeError("Parameter" + x.name + " is not of the type " + x.type);
}
//set error
//break apic assembly
break;
}
});
}
});
function isNumeric(str) {
if (typeof str != "string") return false; // we only process strings!
return (
!isNaN(str) && // use type coercion to parse the _entirety_ of the string (`parseFloat` alone does not do this)...
!isNaN(parseFloat(str))
); // ...and ensure strings of whitespace fail
}
function isInteger(str) {
var n = Math.floor(Number(str));
return n !== Infinity && String(n) === str && n >= 0;
}
function isBoolean (str){
return str === "true"
}