Open
Description
Hello and thank you for this library!
I get false validation errors for schemas with a type
constraint for boolean
, number
and integer
when using the yaml-cpp adapter. See code below to reproduce the issue.
I believe this is because the isBool
, isDouble
, isInteger
, isNumber
and isString
methods in yaml_cpp_adapter.hpp
return literal true
s and false
s.
Code to reproduce the issue:
#include <valijson/adapters/yaml_cpp_adapter.hpp>
#include <valijson/schema_parser.hpp>
#include <valijson/validator.hpp>
void validate(const std::string& schema_string, const std::string& document_string) {
std::istringstream schema_iss(schema_string);
YAML::Node schema_node = YAML::Load(schema_iss);
valijson::SchemaParser schema_parser;
valijson::adapters::YamlCppAdapter schema_adapter(schema_node);
valijson::Schema schema;
schema_parser.populateSchema(schema_adapter, schema);
std::istringstream document_iss(document_string);
YAML::Node document_node = YAML::Load(document_iss);
valijson::adapters::YamlCppAdapter document_adapter(document_node);
valijson::Validator validator;
valijson::ValidationResults results;
if (validator.validate(schema, document_adapter, &results)) {
std::cout << "OK";
} else {
std::cout << "VALIDATION ERROR:";
valijson::ValidationResults::Error error;
while (results.popError(error)) {
std::cout << "\n -";
for (const std::string &contextElement : error.context) {
std::cout << " " << contextElement;
}
std::cout << ": " << error.description;
}
}
std::cout << std::endl;
}
int main() {
// OK
validate("type: string", "\"bonjour\"");
validate("type: array", "[]");
validate("type: object", "{}");
// <root>: Value type not permitted by 'type' constraint.
validate("type: boolean", "true");
validate("type: integer", "42");
validate("type: number", "49.3");
}
Thank you!
Metadata
Metadata
Assignees
Labels
No labels