Closed ntregillus closed 4 years ago
@ntregillus You should specify the regular expression as a string — the schema object should be compatible with a JSON Schema document parsed with JSON.parse
.
Maybe as a future extension this should support a RegExp instance—or at the very least, it should error out if the value is an unexpected type.
I tried both as a regular expression, and a string wrapper (like below):
{
"type": "object",
"properties": {
"singleField": {
"type": "string",
"pattern": "^$"
}
}
}
however it still does not work. I did notice though if my type was in an array definition, it was correctly validating my regex statement. It just appears the verification on an object property does not work.
@ntregillus Can you provide a minimal test case? I cannot reproduce this.
var schema = {
"type": "object",
"properties": {
"singleField": {
"type": "string",
"pattern": "^$"
}
}
};
// returns: instance.singleField does not match pattern "^$"
console.log(jsonschema.validate({singleField:"x"}, schema).errors.toString());
I'm going to close this since this appears to have the correct behavior. Please try the latest release, 1.2.7
, and open a new issue if you encounter any further problems.
https://github.com/tdegrunt/jsonschema/blob/b49eefa200ce0b8146f00ee8dc6153580573de19/examples/all.js#L59
I have been attempting to test a json schema's string property, but the Validator.Validate seems to ignore my type definitions "pattern" value entirely: https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.3.3
when I run this through validate
I am expecting an error, but the errors array of the result is empty. below is the code i would run: