Closed kelaicai closed 4 years ago
Could you share a test-case (schema + instance) which shows the problem?
Here is an example which works for me:
Instance:
{
"url": "http://www.google.com?source=abc"
}
Schema:
{
"$id": "http://xxx.local/schemas/mySchema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
"url": {
"type": "string",
"pattern": "^(http|https)://.*"
}
}
}
schema like this
{
"properties":{
"imgurl":{
"items":{
"maxItems":1,
"minItems":1,
"properties":{
"#text":{
"pattern":"http.*",
"type":"string"
}
},
"type":"object"
},
"type":"array"
}
},
"required":[
"imgurl"
],
"type":"object"
}
data like this
{
"imgurl":[
{
"#text":"http://www.google.com"
}
]
}
has any problem? i passed it by [https://json-schema-validator.herokuapp.com/]() it pased.., and i don't know where is error?
Your schema and data works with the current master-branch of this project. Do you have regular expression activated? What is the C++-version you are using?
Here's a simplified example:
Schema:
{
"pattern":"http.*",
"type":"string"
}
data:
"http://www.google.com"
gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-39) and C++11 nlohmann::json 3.0.0
it work well when I check it in code , ` json js=json::object(); js["imgurl"]=json::array(); json o=json::object(); o["#text"]="http:://www.google.com"; js["imgurl"].push_back(o);
std::string schemastr="{\"properties\":{\"imgurl\":{\"items\":{\"maxItems\":1,\"minItems\":1,\"properties\":{\"#text\":{\"type\":\"string\",\"pattern\":\"http.*\"}},\"type\":\"object\"},\"type\":\"array\"}},\"required\":[\"imgurl\"],\"type\":\"object\"}";
json_schema::json_validator validator;
bool flag=false;
try {
validator.set_root_schema(schemastr); // insert root-schema
flag=true;
} catch (const std::exception &e) {
std::cerr << "Validation of schema failed, here is why: " << e.what() << "\n";
return EXIT_FAILURE;
}
` it work well in this code and no exception happened ;it seems check logic is right ,let me try to update the schema lib tomorrow to see the result! thanks a lot!
Ah OK, I see: To make regex work with GCC 4.8 you need to install boost-regex on your system.
hi ,it work well now; It may be occured by low version gcc use C++11’s std::regex_search ,it can't match regular pattern "http.*" with url and return 0 for me when i use g++4.8. boost::regex_search can match url links ,after I update my g++ to 4.9 or higher complier and compile it ,there is no error happend, so it's occured by std::regex ,and higher compile with boost can solve this problem. thank you!
I want check the url is valid but regex is right and occurs some exceptions,why?