Skip to content

Commit

Permalink
Updated schema validator to loop through params in request
Browse files Browse the repository at this point in the history
  • Loading branch information
parag-pv committed Sep 19, 2024
1 parent 86d5300 commit 1e17527
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions languages/cpp/src/shared/include/json_engine.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,26 @@ class JsonEngine
}
else {
std::cout << "Params is NOT empty" << std::endl;
const json currentSchema = method["params"][0]["schema"];
std::cout << "schema JSON before $ref: " << currentSchema.dump() << std::endl;

json dereferenced_schema = process_schema(currentSchema, _data);
std::cout << "schema JSON after $ref: " << dereferenced_schema.dump() << std::endl;

json_validator validator;
try{
validator.set_root_schema(dereferenced_schema);
validator.validate(requestParams);
std::cout << "Schema validation succeeded" << std::endl;
}
catch (const std::exception &e){
FAIL() << "Schema validation error: " << e.what() << std::endl;
const json openRPCParams = method["params"];
for (auto& item : openRPCParams.items()) {
std::string key = item.key();
json currentSchema = item.value();
std::string paramName = currentSchema["name"];
std::cout << "paramName: " << paramName << std::endl;
if (requestParams.contains(paramName)) {
std::cout << "RequestParams contain paramName in rpc" << std::endl;
json dereferenced_schema = process_schema(currentSchema, _data);
std::cout << "schema JSON after $ref: " << dereferenced_schema.dump() << std::endl;
try{
validator.set_root_schema(dereferenced_schema["schema"]);
validator.validate(requestParams[paramName]);
std::cout << "Schema validation succeeded" << std::endl;
}
catch (const std::exception &e){
FAIL() << "Schema validation error: " << e.what() << std::endl;
}
}
}
}
}
Expand Down

0 comments on commit 1e17527

Please sign in to comment.