tristanpenman / valijson

Header-only C++ library for JSON Schema validation, with support for many popular parsers
BSD 2-Clause "Simplified" License
351 stars 105 forks source link

type name doesn't match in parser and validator #165

Closed silentmissile closed 2 years ago

silentmissile commented 2 years ago

the test environment is: Debian-11.5 with gcc-10.2.1. You can try it in WSL2, too. In my test the physical machine and WSL2 virtual machine can both reproduct the issue.

in Readme.md, there is an example. And I make a simple modification from RapidJSON to jsoncpp.

and I import a Json::Value object of jsoncpp as schema object.

the variable schema is constructed by valijson::Schema class

in SchemaParser class, the member function populateSchema needs 4 parameters

void populateSchema(
        const AdapterType &node,
        Schema &schema,
        typename FunctionPtrs<AdapterType>::FetchDoc fetchDoc = nullptr ,
        typename FunctionPtrs<AdapterType>::FreeDoc freeDoc = nullptr )

and the last 2 parameters have default value, so at least 2 parameters are needed, and the 2nd parameter is a Schema object. I success in this step.

in Validator class, the member function validate needs 3 parameters

bool validate(const Subschema &schema, const AdapterType &target,
            ValidationResults *results)

and the 1st parameter is a Subschema object, it's NOT a Schema object.

so when I compile an example with jsoncpp, the compiler would have an error

no matching function for call to ‘valijson::Validator::validate(valijson::Schema&, valijson::adapters::JsonCppAdapter&, valijson::ValidationResults&)’

though Schema is a chile class of Subschema, the compiler would not cast it automaticly.

silentmissile commented 2 years ago

sorry my mistake, the 3rd parameter of Validator::validate function should be a pointer not value.