|
18 | 18 |
|
19 | 19 | import java.util.ArrayList; |
20 | 20 | import java.util.Collections; |
| 21 | +import java.util.HashSet; |
21 | 22 | import java.util.Iterator; |
22 | 23 | import java.util.LinkedHashSet; |
23 | 24 | import java.util.List; |
|
33 | 34 | public class AdditionalPropertiesValidator extends BaseJsonValidator implements JsonValidator { |
34 | 35 | private static final Logger logger = LoggerFactory.getLogger(AdditionalPropertiesValidator.class); |
35 | 36 |
|
36 | | - private boolean allowAdditionalProperties; |
37 | | - private JsonSchema additionalPropertiesSchema; |
38 | | - private List<String> allowedProperties; |
39 | | - private List<Pattern> patternProperties = new ArrayList<Pattern>(); |
| 37 | + private final boolean allowAdditionalProperties; |
| 38 | + private final JsonSchema additionalPropertiesSchema; |
| 39 | + private final Set<String> allowedProperties; |
| 40 | + private final List<Pattern> patternProperties = new ArrayList<Pattern>(); |
40 | 41 |
|
41 | 42 | public AdditionalPropertiesValidator(String schemaPath, JsonNode schemaNode, JsonSchema parentSchema, |
42 | 43 | ValidationContext validationContext) { |
43 | 44 | super(schemaPath, schemaNode, parentSchema, ValidatorTypeCode.ADDITIONAL_PROPERTIES, validationContext); |
44 | | - allowAdditionalProperties = false; |
45 | 45 | if (schemaNode.isBoolean()) { |
46 | 46 | allowAdditionalProperties = schemaNode.booleanValue(); |
47 | | - } |
48 | | - if (schemaNode.isObject()) { |
| 47 | + additionalPropertiesSchema = null; |
| 48 | + } else if (schemaNode.isObject()) { |
49 | 49 | allowAdditionalProperties = true; |
50 | 50 | additionalPropertiesSchema = new JsonSchema(validationContext, getValidatorType().getValue(), schemaNode, parentSchema); |
| 51 | + } else { |
| 52 | + allowAdditionalProperties = false; |
| 53 | + additionalPropertiesSchema = null; |
51 | 54 | } |
52 | 55 |
|
53 | | - allowedProperties = new ArrayList<String>(); |
| 56 | + allowedProperties = new HashSet<String>(); |
54 | 57 | JsonNode propertiesNode = parentSchema.getSchemaNode().get(PropertiesValidator.PROPERTY); |
55 | 58 | if (propertiesNode != null) { |
56 | 59 | for (Iterator<String> it = propertiesNode.fieldNames(); it.hasNext(); ) { |
|
0 commit comments