fix: False positives in some cases when calling `JSONSchema.apply` on a schema with `additionalProperties`, `patternProperties`, and `properties` combined.

This commit is contained in:
Dmitry Dygalo 2021-12-08 11:14:46 +01:00 committed by Dmitry Dygalo
parent 6444e7c724
commit eb3c601025
2 changed files with 15 additions and 3 deletions

View File

@ -6,6 +6,10 @@
- Make `BasicOutput.is_valid` public.
### Fixed
- False positives in some cases when calling `JSONSchema.apply` on a schema with `additionalProperties`, `patternProperties`, and `properties` combined.
### Performance
- Remove unused private field in `JSONSchema`, that lead to improvement in the compilation performance.

View File

@ -976,9 +976,7 @@ impl<M: PropertiesValidatorsMap> Validate for AdditionalPropertiesWithPatternsNo
self.patterns
.iter()
.filter(|(re, _)| re.is_match(property).unwrap_or(false))
.flat_map(|(_, validators)| {
validate!(validators, value, instance_path, name)
}),
.flat_map(|(_, node)| validate!(node, value, instance_path, name)),
);
} else {
let mut has_match = false;
@ -1014,6 +1012,11 @@ impl<M: PropertiesValidatorsMap> Validate for AdditionalPropertiesWithPatternsNo
let path = instance_path.push(property.clone());
if let Some((_name, node)) = self.properties.get_key_validator(property) {
output += node.apply_rooted(value, &path);
for (pattern, node) in &self.patterns {
if pattern.is_match(property).unwrap_or(false) {
output += node.apply_rooted(value, &path);
}
}
} else {
let mut has_match = false;
for (pattern, node) in &self.patterns {
@ -1201,6 +1204,11 @@ impl<M: PropertiesValidatorsMap> Validate
let path = instance_path.push(property.clone());
if let Some((_name, node)) = self.properties.get_key_validator(property) {
output += node.apply_rooted(value, &path);
for (pattern, node) in &self.patterns {
if pattern.is_match(property).unwrap_or(false) {
output += node.apply_rooted(value, &path);
}
}
} else {
let mut has_match = false;
for (pattern, node) in &self.patterns {