test-openapi
Version:
Automated client requests
67 lines (40 loc) • 1.39 kB
JavaScript
Object.defineProperty(exports,"__esModule",{value:true});exports.checkSchema=void 0;var _lodash=require("lodash");
var _error=require("../errors/error.js");
var _crawl=require("../utils/crawl.js");
var _types=require("../utils/types.js");
var _validate=require("./validate.js");
const checkSchema=function({bug=false,value,...opts}){
const valueA=removeUndefined({value});
const error=(0,_validate.validateFromSchema)({...opts,value:valueA});
if(error===undefined){
return;
}
const ErrorType=bug?_error.BugError:_error.TestOpenApiError;
const{message}=error;
const errorProps=getErrorProps({opts,error});
throw new ErrorType(message,errorProps);
};exports.checkSchema=checkSchema;
const removeUndefined=function({value}){
return(0,_crawl.crawl)(value,removeUndefinedProp);
};
const removeUndefinedProp=function(value){
if(!(0,_types.isObject)(value)){
return value;
}
return(0,_lodash.omitBy)(value,valueA=>valueA===undefined);
};
const getErrorProps=function({
opts:{schemaProp,props},
error:{value,schema,valuePath,schemaPath}})
{
const property=getProperty({schemaProp,valuePath,schemaPath});
return{value,schema,...property,...props};
};
const getProperty=function({schemaProp,valuePath,schemaPath}){
const property=schemaProp===undefined?valuePath:schemaPath;
if(property===""){
return;
}
return{property};
};
//# sourceMappingURL=check.js.map
;